lib/madowu/directorymapper.rb in madowu-0.0.7 vs lib/madowu/directorymapper.rb in madowu-0.0.8

- old
+ new

@@ -6,13 +6,15 @@ # class Madowu::DirectoryMapper # #def initialize() #end - def self.dirmap(dir, with_kakasi = false) + # if index: is given as true, generate link to foo/index.html + # even when the file did not exist. + def self.dirmap(path: dir, kakasi: false, index: false) results = [] - md_dir = Pathname.new(dir) + md_dir = Pathname.new(path) results << "Parent directory:" results << "" if File.exist?(md_dir.parent + 'index.html') results << "* [../](../index.html)" @@ -21,11 +23,11 @@ end results << "" results << "Current directory:" results << "" - current_entries = [] + #current_entries = [] cur_dir_entries = Dir.entries(md_dir).sort.delete_if{|i| i =~ /^\./} links = [] cur_dir_entries.each do |i| path = md_dir + i @@ -35,10 +37,13 @@ link_path = (path + "index.html") title = self.get_title((path + "index.md").to_s) elsif FileTest.exist?(path + "index.html") link_path = path + "index.html" title = self.get_title((path + "index.html").to_s) + elsif index + link_path = path + "index.html" + title = "#{path.basename}/" else link_path = path title = nil end filename += "/" @@ -60,18 +65,19 @@ title = " (#{filename})" if title.to_s.empty? #line = "* [#{title}](#{link_path})" links << [link_path, title] end - links = links.sort_by do |path, title| - if with_kakasi + links = links.sort_by do |file, title| + if kakasi + title = title.escape_zsh `echo #{title} | nkf -e | kakasi -JH |nkf -w` else title end end - links.each do |path, title| - results << "* [#{title}](#{path})" + links.each do |file, title| + results << "* [#{title}](#{file})" end #results << "</ul>" results end