Object
generate html index pages of a directory
# File lib/heel/directory_indexer.rb, line 35 35: def highlighting? 36: @options[:highlighting] 37: end
generate the directory index html page of a directory
# File lib/heel/directory_indexer.rb, line 57 57: def index_page_for(req) 58: reload_template if reload_on_template_change? 59: dir = req.request_path 60: base_uri = req.path_info 61: entries = [] 62: Dir.entries(dir).each do |entry| 63: next if should_ignore?(entry) 64: next if dir == @options[:document_root] and entry == ".." 65: 66: stat = File.stat(File.join(dir,entry)) 67: entry_data = OpenStruct.new 68: 69: entry_data.name = entry == ".." ? "Parent Directory" : entry 70: entry_data.link = entry 71: entry_data.size = num_to_bytes(stat.size) 72: entry_data.last_modified = stat.mtime.strftime("%Y-%m-%d %H:%M:%S") 73: 74: if stat.directory? then 75: entry_data.content_type = "Directory" 76: entry_data.size = "-" 77: entry_data.name += "/" 78: if using_icons? then 79: entry_data.icon_url = File.join(options[:icon_url], MimeMap.icons_by_mime_type[:directory]) 80: end 81: else 82: entry_data.mime_type = mime_map.mime_type_of(entry) 83: entry_data.content_type = entry_data.mime_type.content_type 84: if using_icons? then 85: entry_data.icon_url = File.join(options[:icon_url], mime_map.icon_for(entry_data.mime_type)) 86: end 87: end 88: entries << entry_data 89: end 90: 91: entries = entries.sort_by { |e| e.link } 92: return template.result(binding) 93: end
# File lib/heel/directory_indexer.rb, line 31 31: def mime_map 32: @mime_map ||= Heel::MimeMap.new 33: end
essentially this is strfbytes from facets
# File lib/heel/directory_indexer.rb, line 97 97: def num_to_bytes(num,fmt="%.2f") 98: case 99: when num < 1024 100: "#{num} bytes" 101: when num < 1024**2 102: "#{fmt % (num.to_f / 1024)} KB" 103: when num < 1024**3 104: "#{fmt % (num.to_f / 1024**2)} MB" 105: when num < 1024**4 106: "#{fmt % (num.to_f / 1024**3)} GB" 107: when num < 1024**5 108: "#{fmt % (num.to_f / 1024**4)} TB" 109: else 110: "#{num} bytes" 111: end 112: end
# File lib/heel/directory_indexer.rb, line 39 39: def reload_on_template_change? 40: @options[:reload_template_on_change] 41: end
# File lib/heel/directory_indexer.rb, line 47 47: def reload_template 48: fstat = File.stat(@template_file) 49: @template_mtime ||= fstat.mtime 50: if @template.nil? or fstat.mtime > @template_mtime then 51: @template = ::ERB.new(File.read(@template_file)) 52: end 53: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.