review 2.0.0.beta1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +66 -1
- data/.rubocop_todo.yml +617 -0
- data/.travis.yml +16 -1
- data/ChangeLog +48 -0
- data/Dockerfile +22 -0
- data/Gemfile +0 -1
- data/README.md +97 -0
- data/Rakefile +10 -11
- data/appveyor.yml +9 -0
- data/bin/review +46 -0
- data/bin/review-check +8 -21
- data/bin/review-compile +26 -43
- data/bin/review-index +9 -22
- data/bin/review-init +21 -25
- data/bin/review-preproc +9 -13
- data/bin/review-validate +1 -1
- data/bin/review-vol +3 -17
- data/bin/review-webmaker +15 -0
- data/doc/NEWS.ja.md +534 -0
- data/doc/NEWS.md +538 -0
- data/doc/catalog.ja.md +10 -18
- data/doc/catalog.md +5 -9
- data/doc/config.yml.sample +319 -0
- data/doc/customize_epub.ja.md +42 -0
- data/doc/format.ja.md +320 -288
- data/doc/format.md +277 -170
- data/doc/format_idg.ja.md +82 -175
- data/doc/pdfmaker.ja.md +61 -0
- data/doc/pdfmaker.md +65 -0
- data/doc/quickstart.ja.md +88 -98
- data/doc/quickstart.md +72 -110
- data/doc/sample.css +41 -0
- data/doc/writing_vertical.ja.md +55 -0
- data/doc/writing_vertical.md +5 -0
- data/lib/epubmaker/content.rb +3 -3
- data/lib/epubmaker/epubcommon.rb +173 -145
- data/lib/epubmaker/epubv2.rb +24 -77
- data/lib/epubmaker/epubv3.rb +72 -73
- data/lib/epubmaker/producer.rb +54 -30
- data/lib/lineinput.rb +48 -0
- data/lib/review/book.rb +0 -1
- data/lib/review/book/base.rb +47 -27
- data/lib/review/book/chapter.rb +48 -19
- data/lib/review/book/compilable.rb +10 -14
- data/lib/review/book/index.rb +10 -19
- data/lib/review/book/page_metric.rb +0 -10
- data/lib/review/book/part.rb +17 -3
- data/lib/review/builder.rb +84 -68
- data/lib/review/catalog.rb +5 -1
- data/lib/review/compiler.rb +327 -4657
- data/lib/review/configure.rb +84 -10
- data/lib/review/converter.rb +28 -0
- data/lib/review/epubbuilder.rb +1 -1
- data/lib/review/epubmaker.rb +142 -158
- data/lib/review/ewbbuilder.rb +5 -5
- data/lib/review/exception.rb +1 -1
- data/lib/review/extentions.rb +1 -1
- data/lib/review/extentions/hash.rb +15 -0
- data/lib/review/extentions/string.rb +2 -1
- data/lib/review/htmlbuilder.rb +364 -348
- data/lib/review/htmltoc.rb +44 -0
- data/lib/review/htmlutils.rb +12 -6
- data/lib/review/i18n.rb +78 -6
- data/lib/review/i18n.yml +7 -4
- data/lib/review/idgxmlbuilder.rb +226 -267
- data/lib/review/latexbuilder.rb +281 -274
- data/lib/review/latexutils.rb +56 -49
- data/lib/review/makerhelper.rb +8 -4
- data/lib/review/markdownbuilder.rb +80 -124
- data/lib/review/pdfmaker.rb +197 -138
- data/lib/review/preprocessor.rb +16 -67
- data/lib/review/template.rb +24 -0
- data/lib/review/textbuilder.rb +1 -1
- data/lib/review/textutils.rb +18 -24
- data/lib/review/tocparser.rb +51 -106
- data/lib/review/tocprinter.rb +61 -117
- data/lib/review/topbuilder.rb +119 -126
- data/lib/review/unfold.rb +2 -2
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +302 -0
- data/lib/review/webtocprinter.rb +48 -0
- data/lib/review/yamlloader.rb +47 -0
- data/review.gemspec +3 -3
- data/templates/html/layout-html5.html.erb +17 -0
- data/templates/html/layout-xhtml1.html.erb +20 -0
- data/{lib/review → templates/latex}/layout.tex.erb +107 -115
- data/templates/ncx/epubv2.ncx.erb +11 -0
- data/templates/opf/epubv2.opf.erb +21 -0
- data/templates/opf/epubv3.opf.erb +18 -0
- data/templates/web/html/layout-html5.html.erb +56 -0
- data/templates/web/html/layout-xhtml1.html.erb +20 -0
- data/templates/xml/container.xml.erb +6 -0
- data/test/assets/test.xml.erb +3 -0
- data/test/assets/test_template.tex +28 -71
- data/test/assets/test_template_backmatter.tex +1 -9
- data/test/sample-book/src/Rakefile +12 -3
- data/{doc/sample.yml → test/sample-book/src/config-epub2.yml} +92 -147
- data/test/sample-book/src/config.yml +40 -154
- data/test/sample-book/src/style-web.css +45 -0
- data/test/sample-book/src/style.css +23 -1
- data/test/test.re +1 -1
- data/test/test_book.rb +15 -17
- data/test/test_book_chapter.rb +2 -80
- data/test/test_book_part.rb +1 -1
- data/test/test_builder.rb +28 -6
- data/test/test_catalog.rb +17 -0
- data/test/test_compiler.rb +14 -59
- data/test/test_configure.rb +94 -0
- data/test/test_converter.rb +21 -0
- data/test/test_epub3maker.rb +155 -3
- data/test/test_epubmaker.rb +245 -30
- data/test/test_epubmaker_cmd.rb +2 -2
- data/test/test_extentions_hash.rb +60 -0
- data/test/test_helper.rb +4 -47
- data/test/test_htmlbuilder.rb +282 -175
- data/test/test_htmltoc.rb +33 -0
- data/test/test_i18n.rb +134 -70
- data/test/test_idgxmlbuilder.rb +58 -39
- data/test/test_latexbuilder.rb +132 -14
- data/test/test_lineinput.rb +5 -26
- data/test/test_makerhelper.rb +6 -4
- data/test/test_markdownbuilder.rb +23 -5
- data/test/test_pdfmaker.rb +86 -20
- data/test/test_pdfmaker_cmd.rb +1 -3
- data/test/test_review_ext.rb +1 -1
- data/test/test_template.rb +27 -0
- data/test/test_textutils.rb +36 -0
- data/test/test_tocparser.rb +25 -0
- data/test/test_topbuilder.rb +34 -2
- data/test/test_yamlloader.rb +188 -0
- metadata +71 -29
- data/README.rdoc +0 -81
- data/bin/review-epubmaker-legacy +0 -1024
- data/doc/ruby-uuid/README +0 -11
- data/doc/ruby-uuid/README.ja +0 -34
- data/lib/review/compiler/literals_1_8.kpeg +0 -19
- data/lib/review/compiler/literals_1_8.rb +0 -432
- data/lib/review/compiler/literals_1_9.kpeg +0 -22
- data/lib/review/compiler/literals_1_9.rb +0 -435
- data/lib/review/extentions/array.rb +0 -25
- data/lib/review/htmllayout.rb +0 -41
- data/lib/review/inaobuilder.rb +0 -357
- data/lib/review/location.rb +0 -24
- data/lib/review/node.rb +0 -267
- data/lib/review/review.kpeg +0 -724
- data/lib/uuid.rb +0 -312
- data/rubocop-todo.yml +0 -456
- data/test/test_inaobuilder.rb +0 -247
- data/test/test_uuid.rb +0 -157
data/lib/review/unfold.rb
CHANGED
@@ -47,7 +47,7 @@ module ReVIEW
|
|
47
47
|
|
48
48
|
private
|
49
49
|
|
50
|
-
ZSPACE = "\241\241"
|
50
|
+
ZSPACE = "\241\241" # EUC-JP zen-kaku space
|
51
51
|
|
52
52
|
def do_unfold(input)
|
53
53
|
@blank_needed = false
|
@@ -135,4 +135,4 @@ module ReVIEW
|
|
135
135
|
|
136
136
|
end
|
137
137
|
|
138
|
-
end
|
138
|
+
end # module ReVIEW
|
data/lib/review/version.rb
CHANGED
@@ -0,0 +1,302 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This program is free software.
|
4
|
+
# You can distribute or modify this program under the terms of
|
5
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
6
|
+
# For details of the GNU LGPL, see the file "COPYING".
|
7
|
+
#
|
8
|
+
require 'optparse'
|
9
|
+
require 'yaml'
|
10
|
+
require 'fileutils'
|
11
|
+
require 'erb'
|
12
|
+
|
13
|
+
require 'review/i18n'
|
14
|
+
require 'review/converter'
|
15
|
+
require 'review/configure'
|
16
|
+
require 'review/book'
|
17
|
+
require 'review/htmlbuilder'
|
18
|
+
require 'review/template'
|
19
|
+
require 'review/tocprinter'
|
20
|
+
require 'review/version'
|
21
|
+
require 'erb'
|
22
|
+
|
23
|
+
module ReVIEW
|
24
|
+
class WEBMaker
|
25
|
+
include ERB::Util
|
26
|
+
|
27
|
+
attr_accessor :config, :basedir
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
@basedir = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.execute(*args)
|
34
|
+
self.new.execute(*args)
|
35
|
+
end
|
36
|
+
|
37
|
+
def parse_opts(args)
|
38
|
+
cmd_config = Hash.new
|
39
|
+
opts = OptionParser.new
|
40
|
+
|
41
|
+
opts.banner = "Usage: review-webmaker configfile"
|
42
|
+
opts.version = ReVIEW::VERSION
|
43
|
+
opts.on('--help', 'Prints this message and quit.') do
|
44
|
+
puts opts.help
|
45
|
+
exit 0
|
46
|
+
end
|
47
|
+
opts.on('--ignore-errors', 'Ignore review-compile errors.') do
|
48
|
+
cmd_config["ignore-errors"] = true
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.parse!(args)
|
52
|
+
if args.size != 1
|
53
|
+
puts opts.help
|
54
|
+
exit 0
|
55
|
+
end
|
56
|
+
|
57
|
+
return cmd_config, args[0]
|
58
|
+
end
|
59
|
+
|
60
|
+
def build_path
|
61
|
+
@config["docroot"] || "webroot"
|
62
|
+
end
|
63
|
+
|
64
|
+
def remove_old_files(path)
|
65
|
+
FileUtils.rm_rf(path)
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def execute(*args)
|
70
|
+
@config = ReVIEW::Configure.values
|
71
|
+
@config.maker = "webmaker"
|
72
|
+
cmd_config, yamlfile = parse_opts(args)
|
73
|
+
|
74
|
+
@config.merge!(YAML.load_file(yamlfile))
|
75
|
+
# YAML configs will be overridden by command line options.
|
76
|
+
@config.merge!(cmd_config)
|
77
|
+
@config["htmlext"] = "html"
|
78
|
+
I18n.setup(@config["language"])
|
79
|
+
generate_html_files(yamlfile)
|
80
|
+
end
|
81
|
+
|
82
|
+
def generate_html_files(yamlfile)
|
83
|
+
@basedir = File.dirname(yamlfile)
|
84
|
+
@path = build_path()
|
85
|
+
remove_old_files(@path)
|
86
|
+
Dir.mkdir(@path)
|
87
|
+
|
88
|
+
@book = ReVIEW::Book.load(@basedir)
|
89
|
+
@book.config = @config
|
90
|
+
|
91
|
+
copy_stylesheet(@path)
|
92
|
+
copy_frontmatter(@path)
|
93
|
+
build_body(@path, yamlfile)
|
94
|
+
copy_backmatter(@path)
|
95
|
+
|
96
|
+
copy_images(@config["imagedir"], "#{@path}/images")
|
97
|
+
|
98
|
+
copy_resources("covers", "#{@path}/images")
|
99
|
+
copy_resources("adv", "#{@path}/images")
|
100
|
+
copy_resources(@config["fontdir"], "#{@path}/fonts", @config["font_ext"])
|
101
|
+
end
|
102
|
+
|
103
|
+
def build_body(basetmpdir, yamlfile)
|
104
|
+
base_path = Pathname.new(@basedir)
|
105
|
+
builder = ReVIEW::HTMLBuilder.new
|
106
|
+
@converter = ReVIEW::Converter.new(@book, builder)
|
107
|
+
@book.parts.each do |part|
|
108
|
+
htmlfile = nil
|
109
|
+
if part.name.present?
|
110
|
+
if part.file?
|
111
|
+
build_chap(part, base_path, basetmpdir, true)
|
112
|
+
else
|
113
|
+
htmlfile = "part_#{part.number}.#{@config["htmlext"]}"
|
114
|
+
build_part(part, basetmpdir, htmlfile)
|
115
|
+
title = ReVIEW::I18n.t("part", part.number)
|
116
|
+
title += ReVIEW::I18n.t("chapter_postfix") + part.name.strip if part.name.strip.present?
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
part.chapters.each do |chap|
|
121
|
+
build_chap(chap, base_path, basetmpdir, false)
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def build_part(part, basetmpdir, htmlfile)
|
128
|
+
File.open("#{basetmpdir}/#{htmlfile}", "w") do |f|
|
129
|
+
@body = ""
|
130
|
+
@body << "<div class=\"part\">\n"
|
131
|
+
@body << "<h1 class=\"part-number\">#{ReVIEW::I18n.t("part", part.number)}</h1>\n"
|
132
|
+
if part.name.strip.present?
|
133
|
+
@body << "<h2 class=\"part-title\">#{part.name.strip}</h2>\n"
|
134
|
+
end
|
135
|
+
@body << "</div>\n"
|
136
|
+
|
137
|
+
@language = @config['language']
|
138
|
+
@stylesheets = @config["stylesheet"]
|
139
|
+
tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
|
140
|
+
tmpl = ReVIEW::Template.load(tmplfile)
|
141
|
+
f.write tmpl.result(binding)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def template_name
|
146
|
+
if @config["htmlversion"].to_i == 5
|
147
|
+
'web/html/layout-html5.html.erb'
|
148
|
+
else
|
149
|
+
'web/html/layout-xhtml1.html.erb'
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def build_chap(chap, base_path, basetmpdir, ispart)
|
154
|
+
filename = ""
|
155
|
+
|
156
|
+
if ispart.present?
|
157
|
+
filename = chap.path
|
158
|
+
else
|
159
|
+
filename = Pathname.new(chap.path).relative_path_from(base_path).to_s
|
160
|
+
end
|
161
|
+
id = filename.sub(/\.re\Z/, "")
|
162
|
+
|
163
|
+
htmlfile = "#{id}.#{@config["htmlext"]}"
|
164
|
+
|
165
|
+
if @config["params"].present?
|
166
|
+
warn "'params:' in config.yml is obsoleted."
|
167
|
+
end
|
168
|
+
|
169
|
+
begin
|
170
|
+
@converter.convert(filename, File.join(basetmpdir, htmlfile))
|
171
|
+
rescue => e
|
172
|
+
warn "compile error in #{filename} (#{e.class})"
|
173
|
+
warn e.message
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def copy_images(resdir, destdir)
|
178
|
+
return nil unless File.exist?(resdir)
|
179
|
+
allow_exts = @config["image_ext"]
|
180
|
+
FileUtils.mkdir_p(destdir)
|
181
|
+
recursive_copy_files(resdir, destdir, allow_exts)
|
182
|
+
end
|
183
|
+
|
184
|
+
def copy_resources(resdir, destdir, allow_exts=nil)
|
185
|
+
if !resdir || !File.exist?(resdir)
|
186
|
+
return nil
|
187
|
+
end
|
188
|
+
allow_exts = @config["image_ext"] if allow_exts.nil?
|
189
|
+
FileUtils.mkdir_p(destdir)
|
190
|
+
recursive_copy_files(resdir, destdir, allow_exts)
|
191
|
+
end
|
192
|
+
|
193
|
+
def recursive_copy_files(resdir, destdir, allow_exts)
|
194
|
+
Dir.open(resdir) do |dir|
|
195
|
+
dir.each do |fname|
|
196
|
+
next if fname.start_with?('.')
|
197
|
+
if FileTest.directory?("#{resdir}/#{fname}")
|
198
|
+
recursive_copy_files("#{resdir}/#{fname}", "#{destdir}/#{fname}", allow_exts)
|
199
|
+
else
|
200
|
+
if fname =~ /\.(#{allow_exts.join("|")})\Z/i
|
201
|
+
FileUtils.mkdir_p(destdir)
|
202
|
+
FileUtils.cp("#{resdir}/#{fname}", destdir)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def copy_stylesheet(basetmpdir)
|
210
|
+
if @config["stylesheet"].size > 0
|
211
|
+
@config["stylesheet"].each do |sfile|
|
212
|
+
FileUtils.cp(sfile, basetmpdir)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def copy_frontmatter(basetmpdir)
|
218
|
+
build_indexpage(basetmpdir)
|
219
|
+
|
220
|
+
if @config["titlepage"]
|
221
|
+
if @config["titlefile"]
|
222
|
+
FileUtils.cp(@config["titlefile"], "#{basetmpdir}/titlepage.#{@config["htmlext"]}")
|
223
|
+
else
|
224
|
+
build_titlepage(basetmpdir, "titlepage.#{@config["htmlext"]}")
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
copy_file_with_param("creditfile")
|
229
|
+
copy_file_with_param("originaltitlefile")
|
230
|
+
end
|
231
|
+
|
232
|
+
def build_indexpage(basetmpdir)
|
233
|
+
File.open("#{basetmpdir}/index.html", "w") do |f|
|
234
|
+
if @config["coverimage"]
|
235
|
+
file = File.join("images", @config["coverimage"])
|
236
|
+
@body = <<-EOT
|
237
|
+
<div id="cover-image" class="cover-image">
|
238
|
+
<img src="#{file}" class="max"/>
|
239
|
+
</div>
|
240
|
+
EOT
|
241
|
+
else
|
242
|
+
@body = ""
|
243
|
+
end
|
244
|
+
@language = @config['language']
|
245
|
+
@stylesheets = @config["stylesheet"]
|
246
|
+
@toc = ReVIEW::WEBTOCPrinter.book_to_string(@book)
|
247
|
+
@next = @book.chapters[0]
|
248
|
+
@next_title = @next ? @next.title : ""
|
249
|
+
tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
|
250
|
+
tmpl = ReVIEW::Template.load(tmplfile)
|
251
|
+
f.write tmpl.result(binding)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def build_titlepage(basetmpdir, htmlfile)
|
256
|
+
File.open("#{basetmpdir}/#{htmlfile}", "w") do |f|
|
257
|
+
@body = ""
|
258
|
+
@body << "<div class=\"titlepage\">"
|
259
|
+
@body << "<h1 class=\"tp-title\">#{CGI.escapeHTML(@config["booktitle"])}</h1>"
|
260
|
+
if @config["aut"]
|
261
|
+
@body << "<h2 class=\"tp-author\">#{join_with_separator(@config["aut"], ReVIEW::I18n.t("names_splitter"))}</h2>"
|
262
|
+
end
|
263
|
+
if @config["prt"]
|
264
|
+
@body << "<h3 class=\"tp-publisher\">#{join_with_separator(@config["prt"], ReVIEW::I18n.t("names_splitter"))}</h3>"
|
265
|
+
end
|
266
|
+
@body << "</div>"
|
267
|
+
|
268
|
+
@language = @config['language']
|
269
|
+
@stylesheets = @config["stylesheet"]
|
270
|
+
tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
|
271
|
+
tmpl = ReVIEW::Template.load(tmplfile)
|
272
|
+
f.write tmpl.result(binding)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
def copy_backmatter(basetmpdir)
|
277
|
+
copy_file_with_param("profile")
|
278
|
+
copy_file_with_param("advfile")
|
279
|
+
if @config["colophon"] && @config["colophon"].kind_of?(String)
|
280
|
+
copy_file_with_param("colophon", "colophon.#{@config["htmlext"]}")
|
281
|
+
end
|
282
|
+
copy_file_with_param("backcover")
|
283
|
+
end
|
284
|
+
|
285
|
+
def copy_file_with_param(name, target_file = nil)
|
286
|
+
if @config[name] && File.exist?(@config[name])
|
287
|
+
target_file ||= File.basename(@config[name])
|
288
|
+
FileUtils.cp(@config[name], File.join(basetmpdir, target_file))
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
def join_with_separator(value, sep)
|
293
|
+
if value.kind_of? Array
|
294
|
+
value.join(sep)
|
295
|
+
else
|
296
|
+
value
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'review/tocprinter'
|
2
|
+
|
3
|
+
module ReVIEW
|
4
|
+
class WEBTOCPrinter < TOCPrinter
|
5
|
+
include HTMLUtils
|
6
|
+
|
7
|
+
def self.book_to_string(book)
|
8
|
+
io = StringIO.new
|
9
|
+
ReVIEW::WEBTOCPrinter.new(1, {}, io).print_book(book)
|
10
|
+
io.seek(0)
|
11
|
+
io.read
|
12
|
+
end
|
13
|
+
|
14
|
+
def print_book(book)
|
15
|
+
@out.puts '<ul class="book-toc">'
|
16
|
+
@out.puts "<li><a href=\"index.html\">TOP</a></li>\n"
|
17
|
+
book.each_part do |part|
|
18
|
+
print_part(part)
|
19
|
+
end
|
20
|
+
@out.puts '</ul>'
|
21
|
+
end
|
22
|
+
|
23
|
+
def print_part(part)
|
24
|
+
if part.number
|
25
|
+
@out.puts "<li>#{h(part.title)}\n<ul>\n"
|
26
|
+
end
|
27
|
+
part.each_chapter do |chap|
|
28
|
+
print_chapter(chap)
|
29
|
+
end
|
30
|
+
if part.number
|
31
|
+
@out.puts "</ul>\n</li>\n"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def print_chapter(chap)
|
36
|
+
chap_node = TOCParser.chapter_node(chap)
|
37
|
+
ext = chap.book.config["htmlext"] || "html"
|
38
|
+
path = chap.path.sub(/\.re/, "."+ext)
|
39
|
+
if chap_node.number && chap.on_CHAPS?
|
40
|
+
label = "#{chap.number} #{chap.title}"
|
41
|
+
else
|
42
|
+
label = chap.title
|
43
|
+
end
|
44
|
+
@out.puts "<li><a href=\"#{path}\">#{h(label)}</a></li>\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module ReVIEW
|
4
|
+
class YAMLLoader
|
5
|
+
def initialize
|
6
|
+
end
|
7
|
+
|
8
|
+
# load YAML files
|
9
|
+
#
|
10
|
+
# `inherit: [3.yml, 6.yml]` in 7.yml; `inherit: [1.yml, 2.yml]` in 3.yml; `inherit: [4.yml, 5.yml]` in 6.yml
|
11
|
+
# => 7.yml > 6.yml > 5.yml > 4.yml > 3.yml > 2.yml > 1.yml
|
12
|
+
#
|
13
|
+
def load_file(yamlfile)
|
14
|
+
file_queue = [File.expand_path(yamlfile)]
|
15
|
+
loaded_files = {}
|
16
|
+
yaml = {}
|
17
|
+
|
18
|
+
loop do
|
19
|
+
# Check exit condition
|
20
|
+
if file_queue.empty?
|
21
|
+
return yaml
|
22
|
+
end
|
23
|
+
|
24
|
+
current_file = file_queue.shift
|
25
|
+
current_yaml = YAML.load_file(current_file)
|
26
|
+
yaml = current_yaml.deep_merge(yaml)
|
27
|
+
|
28
|
+
if yaml.key?('inherit')
|
29
|
+
buf = []
|
30
|
+
yaml['inherit'].reverse_each do |item|
|
31
|
+
inherit_file = File.expand_path(item, File.dirname(yamlfile))
|
32
|
+
|
33
|
+
# Check loop
|
34
|
+
if loaded_files[inherit_file]
|
35
|
+
raise "Found circular YAML inheritance '#{inherit_file}' in #{yamlfile}."
|
36
|
+
end
|
37
|
+
|
38
|
+
loaded_files[inherit_file] = true
|
39
|
+
buf << inherit_file
|
40
|
+
end
|
41
|
+
yaml.delete('inherit')
|
42
|
+
file_queue = buf + file_queue
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/review.gemspec
CHANGED
@@ -13,20 +13,20 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.summary = "Re:VIEW: a easy-to-use digital publishing system"
|
14
14
|
gem.description = "Re:VIEW is a digital publishing system for books and ebooks. It supports InDesign, EPUB and LaTeX."
|
15
15
|
gem.required_rubygems_version = Gem::Requirement.new(">= 0") if gem.respond_to? :required_rubygems_version=
|
16
|
-
gem.date = "
|
16
|
+
gem.date = "2016-04-29"
|
17
17
|
|
18
18
|
gem.files = `git ls-files`.split("\n")
|
19
19
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
20
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
21
|
gem.extra_rdoc_files = [
|
22
22
|
"ChangeLog",
|
23
|
-
"README.rdoc"
|
24
23
|
]
|
25
24
|
gem.require_paths = ["lib"]
|
26
25
|
|
26
|
+
gem.add_dependency("rubyzip")
|
27
27
|
gem.add_development_dependency("rake")
|
28
28
|
gem.add_development_dependency("test-unit")
|
29
|
-
gem.add_development_dependency("kpeg")
|
30
29
|
gem.add_development_dependency("pygments.rb")
|
30
|
+
gem.add_development_dependency("rubocop")
|
31
31
|
end
|
32
32
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html>
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="<%= @language %>">
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8" />
|
6
|
+
<% if @stylesheets.present? %>
|
7
|
+
<% @stylesheets.each do |style| %>
|
8
|
+
<link rel="stylesheet" type="text/css" href="<%= style %>" />
|
9
|
+
<% end %>
|
10
|
+
<% end%>
|
11
|
+
<meta name="generator" content="Re:VIEW" />
|
12
|
+
<title><%= @title %></title>
|
13
|
+
</head>
|
14
|
+
<body<%= @body_ext %>>
|
15
|
+
<%= @body %>
|
16
|
+
</body>
|
17
|
+
</html>
|