Hola,
My boss asked me to make a nice map of the directories on our web
server for an upcoming meeting. I’m aware of several ways to approach
this, like find and tree, etc, but I’m a Ruby addict, so that’s what
I’m using. This gets good, don’t bail yet!
What I want to see looks like this:
Thus, my nested folders appear nested on the page.
I start by doing a “ls -R > filemap.txt” on the directory I’m
interested in, and then I can process the output file:
map_file.rb
final_document = File.open(‘newmap.html’, ‘w’) do |f|
f << “\n”
f << “<!-- \n.folder { \n”
f << " background-color: #99CCCC; \nborder: 1px solid #333333;
\ndisplay: block; \nmargin-top: 3px; \nmargin-right: 3px; \nmargin-
left: 6px; \nmargin-bottom: 6px; \n}\n "
f << “.title {\n”
f << " background-color: #D5EAEA;\n width: 99%;\n padding-left: 1%;
\nborder-bottom-width: 1px; \nborder-bottom-style: dotted;\n border-
bottom-color: #333333; \n}\n"
f << “.file {\n”
f << “padding-right: 12px; \n padding-left: 12px;”
f << “\n}\n”
f << “”
f << “Version 19:
\n”
f << “
File.open(‘filemap.txt’).each do |x|
case x
when /.*:$/
f << “\n
f << x
f << “\n\t
when /^\n/
f << “
else
f << “\n\n\t”
f << x
f << “\n\t”
end
end
f << “
f << “\n”
end
If you run this, everything goes fine – except for the nesting part.
I don’t think I can solve this one in a case statement - I think I’m
going to need an array like:
arrayname[folder, folder[child]]
and iterate over that, putting my at the end of each nested
array.
I’m just not that good! This one is killing me. Can anyone help?
Mahalo,
John