placeholder.rb 713 Bytes
Newer Older
Nico Schottelius's avatar
init  
Nico Schottelius committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#!/usr/bin/env ruby

def createPlaceholder(dir, level = 0)
    dir = dir + '/' if(!dir.empty? && dir[-1].chr != '/')

    entries = Array.new
    entries = File.new("#{dir}menu.def").readlines if(FileTest.exists?("#{dir}menu.def"))

    rel = ''
    level.times {
        rel += '../'
    }

    entries.each { |x|
        entry = x.split(/\s*\|\s*/, 2)
        if(!FileTest.exists?(dir + entry[0] + '.html'))
            File.symlink("#{rel}placeholder.html", dir + entry[0] + '.html')
        end
        
        if(FileTest.directory?(dir + entry[0]))
            createPlaceholder(dir + entry[0], level + 1)
        end
    }
end

if(!ARGV[0])
    puts 'Need a directory'
end

createPlaceholder(ARGV[0], 0)