J
John
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:
<div class='folder'>
<div class='title'> Foldername </div>
<span class='file'> file1</span><span class='file'> file2</span>
<div class='folder'>
<div class='title'> Nested Foldername </div>
<span class='file'> file3</span><span class='file'> file4</span>
</div>
</div>
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 << "<html><head>\n<style type='text/css'>"
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 << "</style></head><body>"
f << "Version 19: <br />\n"
f << "<div class='folder'>\n\t"
File.open('filemap.txt').each do |x|
case x
when /.*:$/
f << "\n<div class='folder'><div class='title'>\n\t"
f << x
f << "\n\t</div>"
when /^\n/
f << "<!-- double-newline: end of folder //--></div>"
else
f << "\n<span class='file'>\n\t"
f << x
f << "\n\t</span>"
end
end
f << "</div>"
f << "\n</body></html>"
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 </div> at the end of each nested
array.
I'm just not that good! This one is killing me. Can anyone help?
Mahalo,
John
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:
<div class='folder'>
<div class='title'> Foldername </div>
<span class='file'> file1</span><span class='file'> file2</span>
<div class='folder'>
<div class='title'> Nested Foldername </div>
<span class='file'> file3</span><span class='file'> file4</span>
</div>
</div>
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 << "<html><head>\n<style type='text/css'>"
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 << "</style></head><body>"
f << "Version 19: <br />\n"
f << "<div class='folder'>\n\t"
File.open('filemap.txt').each do |x|
case x
when /.*:$/
f << "\n<div class='folder'><div class='title'>\n\t"
f << x
f << "\n\t</div>"
when /^\n/
f << "<!-- double-newline: end of folder //--></div>"
else
f << "\n<span class='file'>\n\t"
f << x
f << "\n\t</span>"
end
end
f << "</div>"
f << "\n</body></html>"
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 </div> at the end of each nested
array.
I'm just not that good! This one is killing me. Can anyone help?
Mahalo,
John