28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/guard/toc.rb', line 28
def run_on_change(paths)
paths.uniq.each do |path|
input, output, outfile, template = path.split("|")
info = "Created '#{output}/#{outfile}' from the directory '#{input}'"
info = "#{info} via '#{template}'" unless template.nil?
UI.info info
unless @options[:dry_run]
reg = /(.+\/).+\.\w+/i
target_path = output.gsub(reg,"\\1")
FileUtils.mkpath target_path unless target_path.empty?
full_file_list = Dir.entries(input)
file_list = full_file_list[2,full_file_list.length-2]
if input==output
file_list = file_list - ["#{outfile}"]
end
source = "<ul class='toc_links'>\n"
if file_list.length > 0
file_list.each do |file|
file_name = file.gsub(/.html/ix,'').gsub(/_/ix,' ').capitalize
source += " <li><a href='#{output}/#{file}'>#{file_name}</a></li>\n"
end
end
source += " </ul>"
kram_ops = { :input => "kramdown", :output => "html" }
kram_ops.update({ :template => template }) unless template.nil?
doc = Kramdown::Document.new(source, kram_ops).to_html
File.open("#{output}/#{outfile}", "w") do |f|
f.write(doc)
end
end
end
true
end
|