9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/mayuki.rb', line 9
def self.mayuki(input_dir = ".")
conf_global = {
"_output" => File.join(input_dir, "_output"),
"_render" => ["liquid"],
"_export" => [],
"_pygments" => false
}
Dir[File.join(input_dir, "_conf*/*"),
File.join(input_dir, "_conf*.yaml"),
File.join(input_dir, "_conf*.yml")
].each do |f|
begin
conf_global.merge!(YAML.load_file(f))
rescue
end
end
Dir.mkdir(conf_global["_output"]) unless Dir.exist?(conf_global["_output"])
Dir[File.join(input_dir, "/"), File.join(input_dir, "**/*/")].each do |d|
rel = d.split(File.join(input_dir, "/"))[1]
rel = "." unless rel
next if not d.split("/").reduce(true) { |result, elem| result and elem[0] != "_" }
conf = Hash[conf_global]
Dir[File.join(d, "_conf*/*"),
File.join(d, "_conf*.yaml"),
File.join(d, "_conf*.yml")
].each do |f|
begin
conf.merge!(YAML.load_file(f))
rescue
end
end
Dir.mkdir(conf["_output"]) unless Dir.exist?(conf["_output"])
Dir.mkdir(File.join(conf["_output"], rel)) unless Dir.exist?(File.join(conf["_output"], rel))
Dir[File.join(d, "*")].each do |f|
next if not File.file?(f)
next if File.basename(f).start_with?("_")
conf_infile = Hash[conf]
if [".markdown", ".md"
].index(File.extname(f))
part1, sep, part2 = IO.read(f).partition("\n---")
if sep == ""
text = part1
else
yaml, text = [part1, part2]
begin
conf_infile.merge!(YAML.load(yaml))
rescue
end
end
$dir_i = d
$dir_o = File.join(conf_infile["_output"], rel)
["liquid", "markdown"].each do |r|
if conf_infile["_render"].index(r)
text = method("render_" + r).call(text)
end
end
if conf_infile["_export"].index("html")
text = export_html(text, conf_infile)
IO.write(File.join(conf_infile["_output"], rel, File.basename(f, File.extname(f)) + ".html"), text)
elsif conf_infile["_export"].index("html_article")
text = export_html_article(text, conf_infile)
IO.write(File.join(conf_infile["_output"], rel, File.basename(f, File.extname(f)) + ".html"), text)
elsif conf_infile["_export"].index("html_full")
text = export_html_full(text, conf_infile)
IO.write(File.join(conf_infile["_output"], rel, File.basename(f, File.extname(f)) + ".html"), text)
else
text = yaml + "\n---\n" + text if sep != ""
IO.write(File.join(conf_infile["_output"], rel, File.basename(f)), text)
end
if conf_infile["_pygments"]
IO.write(File.join(conf_infile["_output"], rel, "_pygments.css"),
".pygments td.linenos { background-color: #f0f0f0; padding-right: 10px; }\n"\
".pygments span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }\n"\
".pygments pre { line-height: 125%; }\n")
system("pygmentize -f html -S default -a .pygments "\
">> #{File.join(conf_infile["_output"], rel, "_pygments.css")}")
end
else
text = IO.read(f)
IO.write(File.join(conf_infile["_output"], rel, File.basename(f)), text)
end
end
end
conf_global["_output"]
end
|