review 2.3.0 → 2.4.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 +90 -66
- data/.travis.yml +1 -1
- data/Gemfile +0 -1
- data/NEWS.ja.md +82 -0
- data/NEWS.md +83 -0
- data/README.md +5 -3
- data/Rakefile +8 -8
- data/bin/review +1 -5
- data/bin/review-catalog-converter +22 -27
- data/bin/review-check +36 -43
- data/bin/review-checkdep +10 -15
- data/bin/review-compile +37 -55
- data/bin/review-epubmaker +4 -5
- data/bin/review-index +21 -29
- data/bin/review-init +26 -37
- data/bin/review-pdfmaker +0 -2
- data/bin/review-preproc +25 -45
- data/bin/review-validate +19 -18
- data/bin/review-vol +15 -27
- data/doc/config.yml.sample +5 -2
- data/doc/format.ja.md +20 -1
- data/doc/format.md +21 -5
- data/doc/images/review-generate.png +0 -0
- data/lib/epubmaker.rb +1 -3
- data/lib/epubmaker/content.rb +24 -27
- data/lib/epubmaker/epubcommon.rb +135 -148
- data/lib/epubmaker/epubv2.rb +39 -46
- data/lib/epubmaker/epubv3.rb +93 -103
- data/lib/epubmaker/producer.rb +138 -151
- data/lib/epubmaker/zip_exporter.rb +21 -26
- data/lib/review/book.rb +3 -6
- data/lib/review/book/base.rb +78 -103
- data/lib/review/book/chapter.rb +36 -40
- data/lib/review/book/compilable.rb +28 -31
- data/lib/review/book/image_finder.rb +6 -13
- data/lib/review/book/index.rb +100 -121
- data/lib/review/book/page_metric.rb +2 -7
- data/lib/review/book/part.rb +18 -20
- data/lib/review/book/volume.rb +9 -13
- data/lib/review/builder.rb +81 -116
- data/lib/review/catalog.rb +15 -19
- data/lib/review/compiler.rb +64 -83
- data/lib/review/configure.rb +87 -97
- data/lib/review/converter.rb +2 -7
- data/lib/review/epubbuilder.rb +1 -3
- data/lib/review/epubmaker.rb +213 -205
- data/lib/review/exception.rb +2 -4
- data/lib/review/extentions.rb +0 -1
- data/lib/review/extentions/hash.rb +2 -2
- data/lib/review/extentions/string.rb +5 -30
- data/lib/review/htmlbuilder.rb +320 -375
- data/lib/review/htmltoc.rb +4 -7
- data/lib/review/htmlutils.rb +29 -32
- data/lib/review/i18n.rb +33 -44
- data/lib/review/i18n.yml +3 -3
- data/lib/review/idgxmlbuilder.rb +309 -345
- data/lib/review/latexbuilder.rb +175 -212
- data/lib/review/latexindex.rb +2 -8
- data/lib/review/latexutils.rb +33 -43
- data/lib/review/lineinput.rb +1 -1
- data/lib/review/logger.rb +21 -0
- data/lib/review/makerhelper.rb +1 -4
- data/lib/review/markdownbuilder.rb +44 -53
- data/lib/review/md2inaobuilder.rb +6 -12
- data/lib/review/pdfmaker.rb +143 -173
- data/lib/review/preprocessor.rb +64 -101
- data/lib/review/rstbuilder.rb +126 -158
- data/lib/review/sec_counter.rb +18 -34
- data/lib/review/template.rb +4 -5
- data/lib/review/textbuilder.rb +2 -3
- data/lib/review/textutils.rb +7 -13
- data/lib/review/tocparser.rb +31 -56
- data/lib/review/tocprinter.rb +26 -52
- data/lib/review/topbuilder.rb +219 -247
- data/lib/review/unfold.rb +15 -24
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +75 -99
- data/lib/review/webtocprinter.rb +15 -20
- data/lib/review/yamlloader.rb +13 -15
- data/review.gemspec +20 -22
- data/templates/latex/layout.tex.erb +2 -2
- data/templates/opf/epubv2.opf.erb +7 -7
- data/templates/opf/epubv3.opf.erb +7 -7
- data/templates/web/html/layout-html5.html.erb +2 -2
- data/test/assets/black.eps +280 -0
- data/test/assets/fit.png +0 -0
- data/test/assets/large.gif +0 -0
- data/test/assets/large.jpg +0 -0
- data/test/assets/large.png +0 -0
- data/test/assets/large.svg +65 -0
- data/test/assets/test_template.tex +1 -1
- data/test/book_test_helper.rb +2 -2
- data/test/run_test.rb +4 -4
- data/test/sample-book/src/Rakefile +21 -22
- data/test/syntax-book/Gemfile +4 -0
- data/test/syntax-book/Rakefile +72 -0
- data/test/syntax-book/appA.re +22 -0
- data/test/syntax-book/bib.re +6 -0
- data/test/syntax-book/catalog.yml +15 -0
- data/test/syntax-book/ch01.re +136 -0
- data/test/syntax-book/ch02.re +351 -0
- data/test/syntax-book/ch03.re +82 -0
- data/test/syntax-book/config.yml +35 -0
- data/test/syntax-book/images/ball.png +0 -0
- data/test/syntax-book/images/cover.jpg +0 -0
- data/test/syntax-book/images/fractal.png +0 -0
- data/test/syntax-book/images/img3-1.png +0 -0
- data/test/syntax-book/images/inlineicon.jpg +0 -0
- data/test/syntax-book/images/logic.png +0 -0
- data/test/syntax-book/images/logic2.png +0 -0
- data/test/syntax-book/images/puzzle.jpg +0 -0
- data/test/syntax-book/images/table.jpg +0 -0
- data/test/syntax-book/part2.re +6 -0
- data/test/syntax-book/pre01.re +26 -0
- data/test/syntax-book/review-ext.rb +14 -0
- data/test/syntax-book/sty/jumoline.sty +310 -0
- data/test/syntax-book/sty/reviewmacro.sty +39 -0
- data/test/syntax-book/style.css +494 -0
- data/test/syntax-book/syntax.dic +2 -0
- data/test/test_book.rb +106 -111
- data/test/test_book_chapter.rb +21 -22
- data/test/test_book_part.rb +3 -5
- data/test/test_builder.rb +11 -22
- data/test/test_catalog.rb +17 -18
- data/test/test_catalog_converter_cmd.rb +5 -5
- data/test/test_compiler.rb +18 -16
- data/test/test_configure.rb +35 -38
- data/test/test_converter.rb +3 -4
- data/test/test_epub3maker.rb +136 -117
- data/test/test_epubmaker.rb +107 -114
- data/test/test_epubmaker_cmd.rb +2 -4
- data/test/test_extentions_hash.rb +32 -33
- data/test/test_helper.rb +9 -11
- data/test/test_htmlbuilder.rb +454 -420
- data/test/test_htmltoc.rb +8 -12
- data/test/test_htmlutils.rb +0 -2
- data/test/test_i18n.rb +159 -150
- data/test/test_idgxmlbuilder.rb +190 -197
- data/test/test_image_finder.rb +21 -22
- data/test/test_index.rb +24 -29
- data/test/test_latexbuilder.rb +274 -264
- data/test/test_lineinput.rb +7 -10
- data/test/test_location.rb +7 -7
- data/test/test_makerhelper.rb +13 -25
- data/test/test_markdownbuilder.rb +23 -26
- data/test/test_md2inaobuilder.rb +8 -11
- data/test/test_pdfmaker.rb +114 -123
- data/test/test_pdfmaker_cmd.rb +1 -3
- data/test/test_review_ext.rb +3 -5
- data/test/test_rstbuilder.rb +92 -97
- data/test/test_template.rb +3 -7
- data/test/test_textutils.rb +27 -27
- data/test/test_tocparser.rb +2 -2
- data/test/test_topbuilder.rb +98 -103
- data/test/test_webtocprinter.rb +5 -6
- data/test/test_yamlloader.rb +42 -42
- data/test/test_zip_exporter.rb +12 -18
- metadata +86 -9
- data/lib/review/ewbbuilder.rb +0 -382
data/lib/review/unfold.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
# Copyright (c) 2002-2007 Minero Aoki
|
1
|
+
# Copyright (c) 2007-2017 Kenshi Muto
|
2
|
+
# 2002-2007 Minero Aoki
|
5
3
|
#
|
6
4
|
# This program is free software.
|
7
5
|
# You can distribute or modify this program under the terms of
|
@@ -13,18 +11,16 @@ require 'review/preprocessor'
|
|
13
11
|
require 'stringio'
|
14
12
|
|
15
13
|
module ReVIEW
|
16
|
-
|
17
14
|
class WrongInput < Error; end
|
18
15
|
|
19
16
|
class Unfold
|
20
|
-
|
21
17
|
# unfold paragraphs and strip preprocessor tags.
|
22
|
-
def
|
18
|
+
def self.unfold_author_source(s)
|
23
19
|
unfold(Preprocessor::Strip.new(StringIO.new(s)))
|
24
20
|
end
|
25
21
|
|
26
|
-
def
|
27
|
-
new
|
22
|
+
def self.unfold(f)
|
23
|
+
new.unfold(f)
|
28
24
|
end
|
29
25
|
|
30
26
|
def initialize(indent_paragraph = false)
|
@@ -47,14 +43,14 @@ module ReVIEW
|
|
47
43
|
|
48
44
|
private
|
49
45
|
|
50
|
-
ZSPACE = "\241\241" # EUC-JP zen-kaku space
|
46
|
+
ZSPACE = "\241\241".freeze # EUC-JP zen-kaku space
|
51
47
|
|
52
48
|
def do_unfold(input)
|
53
49
|
@blank_needed = false
|
54
50
|
first = true
|
55
51
|
indent = @indent_paragraph ? ZSPACE : ''
|
56
52
|
f = LineInput.new(input)
|
57
|
-
|
53
|
+
f.each_line do |line|
|
58
54
|
case line
|
59
55
|
when /\A\#@/
|
60
56
|
raise "must not happen: input includes preproc directive: #{line.inspect}"
|
@@ -81,27 +77,25 @@ module ReVIEW
|
|
81
77
|
println line
|
82
78
|
skip_block f, /\A:|\A\s+\S/
|
83
79
|
blank
|
84
|
-
when %r
|
80
|
+
when %r{\A//\w.*\{\s*\z}
|
85
81
|
blank
|
86
82
|
println line
|
87
|
-
f.until_terminator(%r
|
83
|
+
f.until_terminator(%r{\A//\}}) do |s|
|
88
84
|
println s
|
89
85
|
end
|
90
86
|
println '//}'
|
91
87
|
blank
|
92
|
-
when %r
|
88
|
+
when %r{\A//\w}
|
93
89
|
blank
|
94
90
|
println line
|
95
91
|
blank
|
96
92
|
when /\A\S/
|
97
|
-
if %r
|
93
|
+
if %r{\A//\[} =~ line
|
98
94
|
$stderr.puts "warning: #{f.path}:#{f.lineno}: paragraph begin with `//['; missing ReVIEW directive name?"
|
99
95
|
end
|
100
96
|
flush_blank
|
101
97
|
@output.print indent + line.rstrip
|
102
|
-
f.until_match(%r
|
103
|
-
@output.print s.rstrip
|
104
|
-
end
|
98
|
+
f.until_match(%r{\A\s*\z|\A//\w}) { |s| @output.print s.rstrip }
|
105
99
|
@output.puts
|
106
100
|
else
|
107
101
|
unless line.strip.empty?
|
@@ -127,12 +121,9 @@ module ReVIEW
|
|
127
121
|
end
|
128
122
|
|
129
123
|
def flush_blank
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
end
|
124
|
+
return unless @blank_needed
|
125
|
+
@output.puts
|
126
|
+
@blank_needed = false
|
134
127
|
end
|
135
|
-
|
136
128
|
end
|
137
|
-
|
138
129
|
end # module ReVIEW
|
data/lib/review/version.rb
CHANGED
data/lib/review/webmaker.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
# This program is free software.
|
4
2
|
# You can distribute or modify this program under the terms of
|
5
3
|
# the GNU LGPL, Lesser General Public License version 2.1.
|
@@ -28,6 +26,7 @@ module ReVIEW
|
|
28
26
|
|
29
27
|
def initialize
|
30
28
|
@basedir = nil
|
29
|
+
@logger = ReVIEW.logger
|
31
30
|
end
|
32
31
|
|
33
32
|
def self.execute(*args)
|
@@ -38,15 +37,13 @@ module ReVIEW
|
|
38
37
|
cmd_config = {}
|
39
38
|
opts = OptionParser.new
|
40
39
|
|
41
|
-
opts.banner =
|
40
|
+
opts.banner = 'Usage: review-webmaker configfile'
|
42
41
|
opts.version = ReVIEW::VERSION
|
43
42
|
opts.on('--help', 'Prints this message and quit.') do
|
44
43
|
puts opts.help
|
45
44
|
exit 0
|
46
45
|
end
|
47
|
-
opts.on('--ignore-errors', 'Ignore review-compile errors.')
|
48
|
-
cmd_config["ignore-errors"] = true
|
49
|
-
end
|
46
|
+
opts.on('--ignore-errors', 'Ignore review-compile errors.') { cmd_config['ignore-errors'] = true }
|
50
47
|
|
51
48
|
opts.parse!(args)
|
52
49
|
if args.size != 1
|
@@ -54,33 +51,35 @@ module ReVIEW
|
|
54
51
|
exit 0
|
55
52
|
end
|
56
53
|
|
57
|
-
|
54
|
+
[cmd_config, args[0]]
|
58
55
|
end
|
59
56
|
|
60
57
|
def build_path
|
61
|
-
@config[
|
58
|
+
@config['docroot'] || 'webroot'
|
62
59
|
end
|
63
60
|
|
64
61
|
def remove_old_files(path)
|
62
|
+
math_dir = "./#{@config['imagedir']}/_review_math"
|
63
|
+
FileUtils.rm_rf(math_dir) if @config['imgmath'] && Dir.exist?(math_dir)
|
65
64
|
FileUtils.rm_rf(path)
|
66
65
|
end
|
67
66
|
|
68
67
|
def execute(*args)
|
69
68
|
@config = ReVIEW::Configure.values
|
70
|
-
@config.maker =
|
69
|
+
@config.maker = 'webmaker'
|
71
70
|
cmd_config, yamlfile = parse_opts(args)
|
72
71
|
|
73
72
|
@config.merge!(YAML.load_file(yamlfile))
|
74
73
|
# YAML configs will be overridden by command line options.
|
75
74
|
@config.merge!(cmd_config)
|
76
|
-
@config[
|
77
|
-
I18n.setup(@config[
|
75
|
+
@config['htmlext'] = 'html'
|
76
|
+
I18n.setup(@config['language'])
|
78
77
|
generate_html_files(yamlfile)
|
79
78
|
end
|
80
79
|
|
81
80
|
def generate_html_files(yamlfile)
|
82
81
|
@basedir = File.dirname(yamlfile)
|
83
|
-
@path = build_path
|
82
|
+
@path = build_path
|
84
83
|
remove_old_files(@path)
|
85
84
|
Dir.mkdir(@path)
|
86
85
|
|
@@ -92,56 +91,50 @@ module ReVIEW
|
|
92
91
|
build_body(@path, yamlfile)
|
93
92
|
copy_backmatter(@path)
|
94
93
|
|
95
|
-
copy_images(@config[
|
94
|
+
copy_images(@config['imagedir'], "#{@path}/#{@config['imagedir']}")
|
96
95
|
|
97
|
-
copy_resources(
|
98
|
-
copy_resources(
|
99
|
-
copy_resources(@config[
|
96
|
+
copy_resources('covers', "#{@path}/#{@config['imagedir']}")
|
97
|
+
copy_resources('adv', "#{@path}/#{@config['imagedir']}")
|
98
|
+
copy_resources(@config['fontdir'], "#{@path}/fonts", @config['font_ext'])
|
100
99
|
end
|
101
100
|
|
102
|
-
def build_body(basetmpdir,
|
101
|
+
def build_body(basetmpdir, _yamlfile)
|
103
102
|
base_path = Pathname.new(@basedir)
|
104
103
|
builder = ReVIEW::HTMLBuilder.new
|
105
104
|
@converter = ReVIEW::Converter.new(@book, builder)
|
106
105
|
@book.parts.each do |part|
|
107
|
-
htmlfile = nil
|
108
106
|
if part.name.present?
|
109
107
|
if part.file?
|
110
108
|
build_chap(part, base_path, basetmpdir, true)
|
111
109
|
else
|
112
|
-
htmlfile = "part_#{part.number}.#{@config[
|
110
|
+
htmlfile = "part_#{part.number}.#{@config['htmlext']}"
|
113
111
|
build_part(part, basetmpdir, htmlfile)
|
114
|
-
title = ReVIEW::I18n.t(
|
115
|
-
title += ReVIEW::I18n.t(
|
112
|
+
# title = ReVIEW::I18n.t('part', part.number)
|
113
|
+
# title += ReVIEW::I18n.t('chapter_postfix') + part.name.strip unless part.name.strip.empty?
|
116
114
|
end
|
117
115
|
end
|
118
116
|
|
119
|
-
part.chapters.each
|
120
|
-
build_chap(chap, base_path, basetmpdir, false)
|
121
|
-
end
|
117
|
+
part.chapters.each { |chap| build_chap(chap, base_path, basetmpdir, false) }
|
122
118
|
end
|
123
119
|
end
|
124
120
|
|
125
121
|
def build_part(part, basetmpdir, htmlfile)
|
126
|
-
File.open("#{basetmpdir}/#{htmlfile}",
|
127
|
-
@body =
|
128
|
-
@body <<
|
129
|
-
@body <<
|
130
|
-
if part.name.strip.present?
|
131
|
-
@body << "<h2 class=\"part-title\">#{part.name.strip}</h2>\n"
|
132
|
-
end
|
122
|
+
File.open("#{basetmpdir}/#{htmlfile}", 'w') do |f|
|
123
|
+
@body = ''
|
124
|
+
@body << %Q(<div class="part">\n)
|
125
|
+
@body << %Q(<h1 class="part-number">#{ReVIEW::I18n.t('part', part.number)}</h1>\n)
|
126
|
+
@body << %Q(<h2 class="part-title">#{part.name.strip}</h2>\n) if part.name.strip.present?
|
133
127
|
@body << "</div>\n"
|
134
128
|
|
135
129
|
@language = @config['language']
|
136
|
-
@stylesheets = @config[
|
130
|
+
@stylesheets = @config['stylesheet']
|
137
131
|
tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
|
138
|
-
|
139
|
-
f.write tmpl.result(binding)
|
132
|
+
f.write ReVIEW::Template.load(tmplfile).result(binding)
|
140
133
|
end
|
141
134
|
end
|
142
135
|
|
143
136
|
def template_name
|
144
|
-
if @config[
|
137
|
+
if @config['htmlversion'].to_i == 5
|
145
138
|
'web/html/layout-html5.html.erb'
|
146
139
|
else
|
147
140
|
'web/html/layout-xhtml1.html.erb'
|
@@ -149,41 +142,39 @@ module ReVIEW
|
|
149
142
|
end
|
150
143
|
|
151
144
|
def build_chap(chap, base_path, basetmpdir, ispart)
|
152
|
-
filename =
|
145
|
+
filename = ''
|
153
146
|
|
154
147
|
if ispart.present?
|
155
148
|
filename = chap.path
|
156
149
|
else
|
157
150
|
filename = Pathname.new(chap.path).relative_path_from(base_path).to_s
|
158
151
|
end
|
159
|
-
id = filename.sub(/\.re\Z/,
|
152
|
+
id = filename.sub(/\.re\Z/, '')
|
160
153
|
|
161
|
-
htmlfile = "#{id}.#{@config[
|
154
|
+
htmlfile = "#{id}.#{@config['htmlext']}"
|
162
155
|
|
163
|
-
if @config[
|
164
|
-
warn
|
156
|
+
if @config['params'].present?
|
157
|
+
@logger.warn %Q('params:' in config.yml is obsoleted.)
|
165
158
|
end
|
166
159
|
|
167
160
|
begin
|
168
161
|
@converter.convert(filename, File.join(basetmpdir, htmlfile))
|
169
162
|
rescue => e
|
170
|
-
warn "compile error in #{filename} (#{e.class})"
|
171
|
-
warn e.message
|
163
|
+
@logger.warn "compile error in #{filename} (#{e.class})"
|
164
|
+
@logger.warn e.message
|
172
165
|
end
|
173
166
|
end
|
174
167
|
|
175
168
|
def copy_images(resdir, destdir)
|
176
169
|
return nil unless File.exist?(resdir)
|
177
|
-
allow_exts = @config[
|
170
|
+
allow_exts = @config['image_ext']
|
178
171
|
FileUtils.mkdir_p(destdir)
|
179
172
|
recursive_copy_files(resdir, destdir, allow_exts)
|
180
173
|
end
|
181
174
|
|
182
|
-
def copy_resources(resdir, destdir, allow_exts=nil)
|
183
|
-
if !resdir || !File.exist?(resdir)
|
184
|
-
|
185
|
-
end
|
186
|
-
allow_exts = @config["image_ext"] if allow_exts.nil?
|
175
|
+
def copy_resources(resdir, destdir, allow_exts = nil)
|
176
|
+
return nil if !resdir || !File.exist?(resdir)
|
177
|
+
allow_exts = @config['image_ext'] if allow_exts.nil?
|
187
178
|
FileUtils.mkdir_p(destdir)
|
188
179
|
recursive_copy_files(resdir, destdir, allow_exts)
|
189
180
|
end
|
@@ -194,107 +185,92 @@ module ReVIEW
|
|
194
185
|
next if fname.start_with?('.')
|
195
186
|
if FileTest.directory?("#{resdir}/#{fname}")
|
196
187
|
recursive_copy_files("#{resdir}/#{fname}", "#{destdir}/#{fname}", allow_exts)
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
FileUtils.cp("#{resdir}/#{fname}", destdir)
|
201
|
-
end
|
188
|
+
elsif fname =~ /\.(#{allow_exts.join('|')})\Z/i
|
189
|
+
FileUtils.mkdir_p(destdir)
|
190
|
+
FileUtils.cp("#{resdir}/#{fname}", destdir)
|
202
191
|
end
|
203
192
|
end
|
204
193
|
end
|
205
194
|
end
|
206
195
|
|
207
196
|
def copy_stylesheet(basetmpdir)
|
208
|
-
if @config[
|
209
|
-
@config["stylesheet"].each do |sfile|
|
210
|
-
FileUtils.cp(sfile, basetmpdir)
|
211
|
-
end
|
212
|
-
end
|
197
|
+
@config['stylesheet'].each { |sfile| FileUtils.cp(sfile, basetmpdir) } if @config['stylesheet'].size > 0
|
213
198
|
end
|
214
199
|
|
215
200
|
def copy_frontmatter(basetmpdir)
|
216
201
|
build_indexpage(basetmpdir)
|
217
202
|
|
218
|
-
if @config[
|
219
|
-
if @config[
|
220
|
-
FileUtils.cp(@config[
|
203
|
+
if @config['titlepage']
|
204
|
+
if @config['titlefile']
|
205
|
+
FileUtils.cp(@config['titlefile'], "#{basetmpdir}/titlepage.#{@config['htmlext']}")
|
221
206
|
else
|
222
|
-
build_titlepage(basetmpdir, "titlepage.#{@config[
|
207
|
+
build_titlepage(basetmpdir, "titlepage.#{@config['htmlext']}")
|
223
208
|
end
|
224
209
|
end
|
225
210
|
|
226
|
-
copy_file_with_param(
|
227
|
-
copy_file_with_param(
|
211
|
+
copy_file_with_param('creditfile')
|
212
|
+
copy_file_with_param('originaltitlefile')
|
228
213
|
end
|
229
214
|
|
230
215
|
def build_indexpage(basetmpdir)
|
231
|
-
File.open("#{basetmpdir}/index.html",
|
232
|
-
if @config[
|
233
|
-
file = File.join(@config[
|
216
|
+
File.open("#{basetmpdir}/index.html", 'w') do |f|
|
217
|
+
if @config['coverimage']
|
218
|
+
file = File.join(@config['imagedir'], @config['coverimage'])
|
234
219
|
@body = <<-EOT
|
235
220
|
<div id="cover-image" class="cover-image">
|
236
221
|
<img src="#{file}" class="max"/>
|
237
222
|
</div>
|
238
223
|
EOT
|
239
224
|
else
|
240
|
-
@body =
|
225
|
+
@body = ''
|
241
226
|
end
|
242
227
|
@language = @config['language']
|
243
|
-
@stylesheets = @config[
|
228
|
+
@stylesheets = @config['stylesheet']
|
244
229
|
@toc = ReVIEW::WEBTOCPrinter.book_to_string(@book)
|
245
230
|
@next = @book.chapters[0]
|
246
|
-
@next_title = @next ? @next.title :
|
231
|
+
@next_title = @next ? @next.title : ''
|
247
232
|
tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
|
248
|
-
|
249
|
-
f.write tmpl.result(binding)
|
233
|
+
f.write ReVIEW::Template.load(tmplfile).result(binding)
|
250
234
|
end
|
251
235
|
end
|
252
236
|
|
253
237
|
def build_titlepage(basetmpdir, htmlfile)
|
254
|
-
File.open("#{basetmpdir}/#{htmlfile}",
|
255
|
-
@body =
|
256
|
-
@body <<
|
257
|
-
@body <<
|
258
|
-
if @config[
|
259
|
-
|
260
|
-
|
261
|
-
if @config["prt"]
|
262
|
-
@body << "<h3 class=\"tp-publisher\">#{join_with_separator(@config["prt"], ReVIEW::I18n.t("names_splitter"))}</h3>"
|
263
|
-
end
|
264
|
-
@body << "</div>"
|
238
|
+
File.open("#{basetmpdir}/#{htmlfile}", 'w') do |f|
|
239
|
+
@body = ''
|
240
|
+
@body << %Q(<div class="titlepage">)
|
241
|
+
@body << %Q(<h1 class="tp-title">#{CGI.escapeHTML(@config.name_of('booktitle'))}</h1>)
|
242
|
+
@body << %Q(<h2 class="tp-author">#{join_with_separator(@config.names_of('aut'), ReVIEW::I18n.t('names_splitter'))}</h2>) if @config['aut']
|
243
|
+
@body << %Q(<h3 class="tp-publisher">#{join_with_separator(@config.names_of('prt'), ReVIEW::I18n.t('names_splitter'))}</h3>) if @config['prt']
|
244
|
+
@body << '</div>'
|
265
245
|
|
266
246
|
@language = @config['language']
|
267
|
-
@stylesheets = @config[
|
247
|
+
@stylesheets = @config['stylesheet']
|
268
248
|
tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)
|
269
|
-
|
270
|
-
f.write tmpl.result(binding)
|
249
|
+
f.write ReVIEW::Template.load(tmplfile).result(binding)
|
271
250
|
end
|
272
251
|
end
|
273
252
|
|
274
|
-
def copy_backmatter(
|
275
|
-
copy_file_with_param(
|
276
|
-
copy_file_with_param(
|
277
|
-
if @config[
|
278
|
-
copy_file_with_param(
|
253
|
+
def copy_backmatter(_basetmpdir)
|
254
|
+
copy_file_with_param('profile')
|
255
|
+
copy_file_with_param('advfile')
|
256
|
+
if @config['colophon'] && @config['colophon'].is_a?(String)
|
257
|
+
copy_file_with_param('colophon', "colophon.#{@config['htmlext']}")
|
279
258
|
end
|
280
|
-
copy_file_with_param(
|
259
|
+
copy_file_with_param('backcover')
|
281
260
|
end
|
282
261
|
|
283
262
|
def copy_file_with_param(name, target_file = nil)
|
284
|
-
if @config[name]
|
285
|
-
|
286
|
-
|
287
|
-
end
|
263
|
+
return if @config[name].nil? || !File.exist?(@config[name])
|
264
|
+
target_file ||= File.basename(@config[name])
|
265
|
+
FileUtils.cp(@config[name], File.join(basetmpdir, target_file))
|
288
266
|
end
|
289
267
|
|
290
268
|
def join_with_separator(value, sep)
|
291
|
-
if value.
|
269
|
+
if value.is_a?(Array)
|
292
270
|
value.join(sep)
|
293
271
|
else
|
294
272
|
value
|
295
273
|
end
|
296
274
|
end
|
297
|
-
|
298
275
|
end
|
299
276
|
end
|
300
|
-
|
data/lib/review/webtocprinter.rb
CHANGED
@@ -14,7 +14,7 @@ module ReVIEW
|
|
14
14
|
|
15
15
|
def print_book(book)
|
16
16
|
@out.puts '<ul class="book-toc">'
|
17
|
-
@out.puts
|
17
|
+
@out.puts %Q(<li><a href="index.html">TOP</a></li>\n)
|
18
18
|
book.each_part do |part|
|
19
19
|
print_part(part)
|
20
20
|
end
|
@@ -24,32 +24,27 @@ module ReVIEW
|
|
24
24
|
def print_part(part)
|
25
25
|
if part.number
|
26
26
|
if part.file?
|
27
|
-
ext = part.book.config[
|
28
|
-
path = part.path.sub(/\.re/,
|
29
|
-
@out.puts
|
27
|
+
ext = part.book.config['htmlext'] || 'html'
|
28
|
+
path = part.path.sub(/\.re/, '.' + ext)
|
29
|
+
@out.puts %Q(<li><a href="#{path}">#{h(I18n.t('part_short', part.number) + ' ' + part.title)}</a>\n<ul>\n)
|
30
30
|
else
|
31
|
-
@out.puts
|
31
|
+
@out.puts %Q(<li>#{h(I18n.t('part_short', part.number) + ' ' + part.title)}\n<ul>\n)
|
32
32
|
end
|
33
33
|
end
|
34
|
-
part.each_chapter
|
35
|
-
|
36
|
-
end
|
37
|
-
if part.number
|
38
|
-
@out.puts "</ul>\n</li>\n"
|
39
|
-
end
|
34
|
+
part.each_chapter { |chap| print_chapter(chap) }
|
35
|
+
@out.puts "</ul>\n</li>\n" if part.number
|
40
36
|
end
|
41
37
|
|
42
38
|
def print_chapter(chap)
|
43
39
|
chap_node = TOCParser.chapter_node(chap)
|
44
|
-
ext = chap.book.config[
|
45
|
-
path = chap.path.sub(/\.re/,
|
46
|
-
if chap_node.number && chap.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@out.puts
|
40
|
+
ext = chap.book.config['htmlext'] || 'html'
|
41
|
+
path = chap.path.sub(/\.re/, '.' + ext)
|
42
|
+
label = if chap_node.number && chap.on_chaps?
|
43
|
+
"#{I18n.t('chapter_short', chap.number)} #{chap.title}"
|
44
|
+
else
|
45
|
+
chap.title
|
46
|
+
end
|
47
|
+
@out.puts %Q(<li><a href="#{path}">#{h(label)}</a></li>\n)
|
52
48
|
end
|
53
|
-
|
54
49
|
end
|
55
50
|
end
|