From: "ara.t.howard" Date: 2008-04-29T16:17:03+09:00 Subject: Re: hacking arrays On Apr 28, 2008, at 8:10 PM, John wrote: > The code: > > http://pastie.caboo.se/188207 > > The question: > > Why isn't it doing them like nested folders? I'd like to get > > .----------------- > | Parent folder > | .------------------ > | | child folder > | | child files > | |____________ > __________ > > but I don't. Can anyone see whats wrong here? I'm losing my mind. > Thanks. it looks like you are making it much harder than it needs to be... this code gives you the depth you are at all the way down without the need to count: cfp:~ > find a a a/b a/b/c a/b/c/file.rb a/b/file.rb a/file.rb cfp:~ > cat a.rb def div folder = '.', depth = 0 title = folder entries = Dir[ "#{ folder }/*" ] padding = ' ' * depth files = entries.select{|entry| test ?f, entry} dirs = entries.select{|entry| test ?d, entry} dir_content = dirs.map do |dir| div dir, depth + 1 end file_content = files.map do |file| content = <<-html #{ file } html end content = <<-html
#{ title }
#{ file_content } #{ dir_content }
html indent = content[%r/^\s*/] content.strip.gsub %r/^#{ indent }/, padding end puts div( ARGV.shift ) cfp:~ > ruby a.rb a
a
a/file.rb
a/b
a/b/file.rb
a/b/c
a/b/c/file.rb
the indentation could be improved... but i suppose that doesn't matter for html anyhow. regards. a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama