review 2.5.0 → 3.0.0.preview1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +28 -10
- data/.travis.yml +11 -2
- data/NEWS.ja.md +89 -17
- data/NEWS.md +92 -0
- data/README.md +1 -1
- data/Rakefile +0 -13
- data/bin/review-catalog-converter +83 -37
- data/bin/review-check +17 -5
- data/bin/review-compile +1 -1
- data/bin/review-index +6 -0
- data/bin/review-init +3 -155
- data/bin/review-preproc +0 -5
- data/bin/review-validate +21 -7
- data/bin/review-vol +13 -5
- data/doc/config.yml.sample +12 -7
- data/doc/config.yml.sample-simple +1 -1
- data/doc/format.ja.md +39 -3
- data/doc/format.md +39 -3
- data/doc/format_idg.ja.md +0 -4
- data/doc/pdfmaker.ja.md +1 -1
- data/doc/pdfmaker.md +1 -1
- data/doc/sample.css +7 -0
- data/lib/epubmaker/content.rb +31 -12
- data/lib/epubmaker/epubcommon.rb +10 -3
- data/lib/epubmaker/epubv2.rb +11 -3
- data/lib/epubmaker/epubv3.rb +11 -3
- data/lib/epubmaker/producer.rb +55 -20
- data/lib/review/book/base.rb +63 -48
- data/lib/review/book/chapter.rb +19 -7
- data/lib/review/book/compilable.rb +5 -20
- data/lib/review/book/image_finder.rb +10 -3
- data/lib/review/book/index.rb +30 -9
- data/lib/review/book/part.rb +9 -6
- data/lib/review/book.rb +0 -14
- data/lib/review/builder.rb +110 -18
- data/lib/review/catalog.rb +24 -4
- data/lib/review/compiler.rb +3 -1
- data/lib/review/configure.rb +43 -9
- data/lib/review/epubmaker/reviewheaderlistener.rb +57 -0
- data/lib/review/epubmaker.rb +129 -85
- data/lib/review/htmlbuilder.rb +76 -58
- data/lib/review/htmlutils.rb +20 -13
- data/lib/review/i18n.rb +6 -2
- data/lib/review/idgxmlbuilder.rb +52 -41
- data/lib/review/init.rb +194 -0
- data/lib/review/latexbuilder.rb +118 -34
- data/lib/review/latexutils.rb +5 -5
- data/lib/review/logger.rb +2 -1
- data/lib/review/makerhelper.rb +1 -1
- data/lib/review/markdownbuilder.rb +66 -6
- data/lib/review/md2inaobuilder.rb +2 -2
- data/lib/review/pdfmaker.rb +74 -22
- data/lib/review/plaintextbuilder.rb +8 -4
- data/lib/review/preprocessor.rb +14 -17
- data/lib/review/sec_counter.rb +8 -2
- data/lib/review/textmaker.rb +2 -2
- data/lib/review/textutils.rb +9 -2
- data/lib/review/tocparser.rb +7 -4
- data/lib/review/tocprinter.rb +3 -1
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +19 -7
- data/lib/review/webtocprinter.rb +8 -4
- data/review.gemspec +4 -3
- data/templates/latex/config.erb +84 -0
- data/templates/latex/layout.tex.erb +76 -361
- data/templates/latex/review-jlreq/README.md +22 -0
- data/templates/latex/review-jlreq/review-base.sty +178 -0
- data/templates/latex/review-jlreq/review-custom.sty +1 -0
- data/templates/latex/review-jlreq/review-jlreq.cls +141 -0
- data/templates/latex/review-jlreq/review-style.sty +149 -0
- data/templates/latex/review-jlreq/reviewmacro.sty +8 -0
- data/templates/latex/review-jsbook/jumoline.sty +310 -0
- data/templates/latex/review-jsbook/plistings.sty +326 -0
- data/templates/latex/review-jsbook/review-base.sty +405 -0
- data/templates/latex/review-jsbook/review-custom.sty +1 -0
- data/templates/latex/review-jsbook/review-style.sty +38 -0
- data/templates/latex/review-jsbook/reviewmacro.sty +8 -0
- data/templates/latex-compat2/layout.tex.erb +387 -0
- data/test/assets/test_template.tex +105 -235
- data/test/assets/test_template_backmatter.tex +133 -14
- data/test/book_test_helper.rb +1 -1
- data/test/run_test.rb +2 -0
- data/test/sample-book/src/Rakefile +11 -6
- data/test/sample-book/src/config.yml +2 -2
- data/test/sample-book/src/sty/reviewmacro.sty +1 -39
- data/test/sample-book/src/style.css +6 -0
- data/test/syntax-book/config.yml +1 -1
- data/test/test_book.rb +13 -16
- data/test/test_book_chapter.rb +4 -10
- data/test/test_book_part.rb +4 -3
- data/test/test_catalog.rb +15 -4
- data/test/test_helper.rb +2 -2
- data/test/test_htmlbuilder.rb +78 -10
- data/test/test_htmlutils.rb +12 -5
- data/test/test_idgxmlbuilder.rb +1 -1
- data/test/test_latexbuilder.rb +94 -49
- data/test/test_latexbuilder_v2.rb +1077 -0
- data/test/test_logger.rb +20 -0
- data/test/test_markdownbuilder.rb +10 -0
- data/test/test_pdfmaker.rb +6 -7
- data/test/test_plaintextbuilder.rb +1 -1
- data/test/test_review_ext.rb +0 -1
- data/test/test_rstbuilder.rb +1 -1
- data/test/test_topbuilder.rb +19 -7
- data/test/test_webtocprinter.rb +14 -14
- data/{test/sample-book/src/vendor → vendor}/jumoline/README +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.dtx +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.ins +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/lppl.txt +0 -0
- data/vendor/plistings/.gitignore +9 -0
- data/vendor/plistings/LICENSE +21 -0
- data/vendor/plistings/README.md +18 -0
- data/vendor/plistings/plistings.sty +326 -0
- data/vendor/plistings/test1.tex +174 -0
- data/vendor/plistings/test2.tex +54 -0
- metadata +48 -19
- data/lib/review/unfold.rb +0 -129
- data/test/CHAPS +0 -2
- data/test/bib.re +0 -13
- data/test/test.re +0 -43
data/lib/epubmaker/epubv3.rb
CHANGED
@@ -18,7 +18,9 @@ module EPUBMaker
|
|
18
18
|
def initialize(producer)
|
19
19
|
super
|
20
20
|
@opf_prefix = {}
|
21
|
-
|
21
|
+
if @producer.config['opf_prefix'].present?
|
22
|
+
@producer.config['opf_prefix'].each { |k, v| @opf_prefix[k] = v }
|
23
|
+
end
|
22
24
|
end
|
23
25
|
|
24
26
|
# Return opf file content.
|
@@ -124,7 +126,11 @@ module EPUBMaker
|
|
124
126
|
end
|
125
127
|
|
126
128
|
## add custom <meta> element
|
127
|
-
|
129
|
+
if @producer.config['opf_meta'].present?
|
130
|
+
@producer.config['opf_meta'].each do |k, v|
|
131
|
+
s << %Q( <meta property="#{k}">#{CGI.escapeHTML(v)}</meta>\n)
|
132
|
+
end
|
133
|
+
end
|
128
134
|
|
129
135
|
s
|
130
136
|
end
|
@@ -178,7 +184,9 @@ EOT
|
|
178
184
|
@producer.contents.each do |item|
|
179
185
|
next if item.media !~ /xhtml\+xml/ # skip non XHTML
|
180
186
|
if toc.nil? && item.chaptype != 'pre'
|
181
|
-
|
187
|
+
if @producer.config['toc']
|
188
|
+
s << %Q( <itemref idref="#{@producer.config['bookname']}-toc.#{@producer.config['htmlext']}" />\n)
|
189
|
+
end
|
182
190
|
toc = true
|
183
191
|
end
|
184
192
|
s << %Q( <itemref idref="#{item.id}"/>\n)
|
data/lib/epubmaker/producer.rb
CHANGED
@@ -29,14 +29,18 @@ module EPUBMaker
|
|
29
29
|
|
30
30
|
# Take YAML +file+ and return parameter hash.
|
31
31
|
def self.load(file)
|
32
|
-
|
32
|
+
if file.nil? || !File.exist?(file)
|
33
|
+
raise "Can't open #{file}."
|
34
|
+
end
|
33
35
|
loader = ReVIEW::YAMLLoader.new
|
34
36
|
loader.load_file(file)
|
35
37
|
end
|
36
38
|
|
37
39
|
# Take YAML +file+ and update parameter hash.
|
38
40
|
def load(file)
|
39
|
-
|
41
|
+
if file.nil? || !File.exist?(file)
|
42
|
+
raise "Can't open #{file}."
|
43
|
+
end
|
40
44
|
loader = ReVIEW::YAMLLoader.new
|
41
45
|
merge_config(@config.deep_merge(loader.load_file(file)))
|
42
46
|
end
|
@@ -79,33 +83,43 @@ module EPUBMaker
|
|
79
83
|
raise "Invalid EPUB version (#{@config['epubversion']}.)"
|
80
84
|
end
|
81
85
|
end
|
82
|
-
|
86
|
+
if config['language']
|
87
|
+
ReVIEW::I18n.locale = config['language']
|
88
|
+
end
|
83
89
|
support_legacy_maker
|
84
90
|
end
|
85
91
|
|
86
92
|
# Write mimetype file to IO object +wobj+.
|
87
93
|
def mimetype(wobj)
|
88
94
|
s = @epub.mimetype
|
89
|
-
|
95
|
+
if !s.nil? && !wobj.nil?
|
96
|
+
wobj.print s
|
97
|
+
end
|
90
98
|
end
|
91
99
|
|
92
100
|
# Write opf file to IO object +wobj+.
|
93
101
|
def opf(wobj)
|
94
102
|
s = @epub.opf
|
95
|
-
|
103
|
+
if !s.nil? && !wobj.nil?
|
104
|
+
wobj.puts s
|
105
|
+
end
|
96
106
|
end
|
97
107
|
|
98
108
|
# Write ncx file to IO object +wobj+. +indentarray+ defines prefix
|
99
109
|
# string for each level.
|
100
110
|
def ncx(wobj, indentarray = [])
|
101
111
|
s = @epub.ncx(indentarray)
|
102
|
-
|
112
|
+
if !s.nil? && !wobj.nil?
|
113
|
+
wobj.puts s
|
114
|
+
end
|
103
115
|
end
|
104
116
|
|
105
117
|
# Write container file to IO object +wobj+.
|
106
118
|
def container(wobj)
|
107
119
|
s = @epub.container
|
108
|
-
|
120
|
+
if !s.nil? && !wobj.nil?
|
121
|
+
wobj.puts s
|
122
|
+
end
|
109
123
|
end
|
110
124
|
|
111
125
|
# Write cover file to IO object +wobj+.
|
@@ -114,32 +128,40 @@ module EPUBMaker
|
|
114
128
|
def cover(wobj)
|
115
129
|
type = @config['epubversion'] >= 3 ? 'cover' : nil
|
116
130
|
s = @epub.cover(type)
|
117
|
-
|
131
|
+
if !s.nil? && !wobj.nil?
|
132
|
+
wobj.puts s
|
133
|
+
end
|
118
134
|
end
|
119
135
|
|
120
136
|
# Write title file (copying) to IO object +wobj+.
|
121
137
|
def titlepage(wobj)
|
122
138
|
s = @epub.titlepage
|
123
|
-
|
139
|
+
if !s.nil? && !wobj.nil?
|
140
|
+
wobj.puts s
|
141
|
+
end
|
124
142
|
end
|
125
143
|
|
126
144
|
# Write colophon file to IO object +wobj+.
|
127
145
|
def colophon(wobj)
|
128
146
|
s = @epub.colophon
|
129
|
-
|
147
|
+
if !s.nil? && !wobj.nil?
|
148
|
+
wobj.puts s
|
149
|
+
end
|
130
150
|
end
|
131
151
|
|
132
152
|
# Write own toc file to IO object +wobj+.
|
133
153
|
def mytoc(wobj)
|
134
154
|
s = @epub.mytoc
|
135
|
-
|
155
|
+
if !s.nil? && !wobj.nil?
|
156
|
+
wobj.puts s
|
157
|
+
end
|
136
158
|
end
|
137
159
|
|
138
160
|
# Add informations of figure files in +path+ to contents array.
|
139
161
|
# +base+ defines a string to remove from path name.
|
140
162
|
def import_imageinfo(path, base = nil, allow_exts = nil)
|
141
163
|
return nil unless File.exist?(path)
|
142
|
-
allow_exts
|
164
|
+
allow_exts ||= @config['image_ext']
|
143
165
|
Dir.foreach(path) do |f|
|
144
166
|
next if f.start_with?('.')
|
145
167
|
if f =~ /\.(#{allow_exts.join('|')})\Z/i
|
@@ -150,7 +172,9 @@ module EPUBMaker
|
|
150
172
|
@contents.push(EPUBMaker::Content.new('file' => "#{path.sub(base + '/', '')}/#{f}"))
|
151
173
|
end
|
152
174
|
end
|
153
|
-
|
175
|
+
if FileTest.directory?("#{path}/#{f}")
|
176
|
+
import_imageinfo("#{path}/#{f}", base)
|
177
|
+
end
|
154
178
|
end
|
155
179
|
end
|
156
180
|
|
@@ -161,10 +185,12 @@ module EPUBMaker
|
|
161
185
|
# +tmpdir+ defines temporary directory.
|
162
186
|
def produce(epubfile, basedir = nil, tmpdir = nil)
|
163
187
|
current = Dir.pwd
|
164
|
-
basedir
|
188
|
+
basedir ||= current
|
165
189
|
|
166
190
|
new_tmpdir = tmpdir.nil? ? Dir.mktmpdir : tmpdir
|
167
|
-
|
191
|
+
if epubfile !~ %r{\A/}
|
192
|
+
epubfile = "#{current}/#{epubfile}"
|
193
|
+
end
|
168
194
|
|
169
195
|
# FIXME: error check
|
170
196
|
File.unlink(epubfile) if File.exist?(epubfile)
|
@@ -188,8 +214,12 @@ module EPUBMaker
|
|
188
214
|
def isbn_hyphen
|
189
215
|
str = @config['isbn'].to_s
|
190
216
|
|
191
|
-
|
192
|
-
|
217
|
+
if str =~ /\A\d{10}\Z/
|
218
|
+
return "#{str[0..0]}-#{str[1..5]}-#{str[6..8]}-#{str[9..9]}"
|
219
|
+
end
|
220
|
+
if str =~ /\A\d{13}\Z/
|
221
|
+
return "#{str[0..2]}-#{str[3..3]}-#{str[4..8]}-#{str[9..11]}-#{str[12..12]}"
|
222
|
+
end
|
193
223
|
nil
|
194
224
|
end
|
195
225
|
|
@@ -197,7 +227,7 @@ module EPUBMaker
|
|
197
227
|
|
198
228
|
# Complement parameters.
|
199
229
|
def complement
|
200
|
-
@config['htmlext']
|
230
|
+
@config['htmlext'] ||= 'html'
|
201
231
|
defaults = ReVIEW::Configure.new.merge(
|
202
232
|
'language' => 'ja',
|
203
233
|
'date' => Time.now.strftime('%Y-%m-%d'),
|
@@ -237,6 +267,7 @@ module EPUBMaker
|
|
237
267
|
'cover_linear' => nil
|
238
268
|
},
|
239
269
|
'externallink' => true,
|
270
|
+
'contentdir' => '.',
|
240
271
|
'imagedir' => 'images',
|
241
272
|
'fontdir' => 'fonts',
|
242
273
|
'image_ext' => %w[png gif jpg jpeg svg ttf woff otf],
|
@@ -274,7 +305,9 @@ module EPUBMaker
|
|
274
305
|
@config.delete(k)
|
275
306
|
end
|
276
307
|
|
277
|
-
|
308
|
+
if @config['epubversion'] >= 3
|
309
|
+
@config['htmlversion'] = 5
|
310
|
+
end
|
278
311
|
|
279
312
|
@config.maker = 'epubmaker'
|
280
313
|
@config['cover'] = "#{@config['bookname']}.#{@config['htmlext']}" unless @config['cover']
|
@@ -290,7 +323,9 @@ module EPUBMaker
|
|
290
323
|
ill lyr mdc mus nrt oth pht pbl prt red rev spn ths trc trl
|
291
324
|
stylesheet rights].each do |item|
|
292
325
|
next unless @config[item]
|
293
|
-
|
326
|
+
if @config[item].is_a?(String)
|
327
|
+
@config[item] = [@config[item]]
|
328
|
+
end
|
294
329
|
end
|
295
330
|
# optional
|
296
331
|
# type, format, identifier, source, relation, coverpage, aut
|
data/lib/review/book/base.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright (c) 2009-
|
2
|
+
# Copyright (c) 2009-2018 Minero Aoki, Kenshi Muto
|
3
3
|
# 2002-2008 Minero Aoki
|
4
4
|
#
|
5
5
|
# This program is free software.
|
@@ -13,47 +13,36 @@ require 'review/catalog'
|
|
13
13
|
module ReVIEW
|
14
14
|
module Book
|
15
15
|
class Base
|
16
|
-
|
16
|
+
attr_accessor :config
|
17
17
|
attr_writer :parts
|
18
18
|
attr_writer :catalog
|
19
19
|
attr_reader :basedir
|
20
20
|
|
21
|
-
def self.load_default
|
22
|
-
ReVIEW.logger.warn 'Book::Base.load_default() is obsoleted. Use Book::Base.load().'
|
23
|
-
load
|
24
|
-
end
|
25
|
-
|
26
21
|
def self.load(dir = '.')
|
27
|
-
update_rubyenv dir
|
28
22
|
new(dir)
|
29
23
|
end
|
30
24
|
|
31
|
-
|
32
|
-
|
33
|
-
def self.update_rubyenv(dir)
|
34
|
-
return if @basedir_seen.key?(dir)
|
35
|
-
if File.file?(File.join(dir, 'review-ext.rb'))
|
36
|
-
if ENV['REVIEW_SAFE_MODE'].to_i & 2 > 0
|
37
|
-
ReVIEW.logger.warn 'review-ext.rb is prohibited in safe mode. ignored.'
|
38
|
-
else
|
39
|
-
Kernel.load File.expand_path(File.join(dir, 'review-ext.rb'))
|
40
|
-
end
|
41
|
-
end
|
42
|
-
@basedir_seen[dir] = true
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.clear_rubyenv
|
46
|
-
@basedir_seen = {}
|
47
|
-
end
|
48
|
-
|
49
|
-
def initialize(basedir)
|
25
|
+
def initialize(basedir = '.')
|
50
26
|
@basedir = basedir
|
27
|
+
@logger = ReVIEW.logger
|
51
28
|
@parts = nil
|
52
29
|
@chapter_index = nil
|
53
30
|
@config = ReVIEW::Configure.values
|
54
31
|
@catalog = nil
|
55
32
|
@read_part = nil
|
56
33
|
@warn_old_files = {} # XXX for checking CHAPS, PREDEF, POSTDEF
|
34
|
+
@basedir_seen = {}
|
35
|
+
update_rubyenv
|
36
|
+
end
|
37
|
+
|
38
|
+
def update_rubyenv
|
39
|
+
if File.file?(File.join(@basedir, 'review-ext.rb'))
|
40
|
+
if ENV['REVIEW_SAFE_MODE'].to_i & 2 > 0
|
41
|
+
@logger.warn 'review-ext.rb is prohibited in safe mode. ignored.'
|
42
|
+
else
|
43
|
+
Kernel.load(File.expand_path(File.join(@basedir, 'review-ext.rb')))
|
44
|
+
end
|
45
|
+
end
|
57
46
|
end
|
58
47
|
|
59
48
|
def bib_file
|
@@ -68,8 +57,8 @@ module ReVIEW
|
|
68
57
|
config['ext']
|
69
58
|
end
|
70
59
|
|
71
|
-
def
|
72
|
-
config['
|
60
|
+
def imagedir
|
61
|
+
File.join(@basedir, config['imagedir'])
|
73
62
|
end
|
74
63
|
|
75
64
|
def image_types
|
@@ -80,6 +69,14 @@ module ReVIEW
|
|
80
69
|
config['image_types'] = types
|
81
70
|
end
|
82
71
|
|
72
|
+
def contentdir
|
73
|
+
if !config['contentdir'].present? || config['contentdir'] == '.'
|
74
|
+
@basedir
|
75
|
+
else
|
76
|
+
File.join(@basedir, config['contentdir'])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
83
80
|
def page_metric
|
84
81
|
if config['page_metric'].respond_to?(:downcase) && config['page_metric'].upcase =~ /\A[A-Z0-9_]+\Z/
|
85
82
|
ReVIEW::Book::PageMetric.const_get(config['page_metric'].upcase)
|
@@ -103,7 +100,10 @@ module ReVIEW
|
|
103
100
|
end
|
104
101
|
|
105
102
|
def parts_in_file
|
106
|
-
parts.find_all
|
103
|
+
# TODO: should be `parts.find_all{|part| part.present? and part.file?}` ?
|
104
|
+
parts.find_all do |part|
|
105
|
+
part if part.present? and part.file?
|
106
|
+
end
|
107
107
|
end
|
108
108
|
|
109
109
|
def part(n)
|
@@ -139,7 +139,12 @@ module ReVIEW
|
|
139
139
|
return @chapter_index if @chapter_index
|
140
140
|
|
141
141
|
contents = chapters
|
142
|
-
parts.
|
142
|
+
# TODO: contents += parts.find_all { |prt| prt.id.present? }
|
143
|
+
parts.each do |prt|
|
144
|
+
if prt.id.present?
|
145
|
+
contents << prt
|
146
|
+
end
|
147
|
+
end
|
143
148
|
@chapter_index = ChapterIndex.new(contents)
|
144
149
|
end
|
145
150
|
|
@@ -151,7 +156,9 @@ module ReVIEW
|
|
151
156
|
finded = false
|
152
157
|
each_chapter do |c|
|
153
158
|
return c if finded
|
154
|
-
|
159
|
+
if c == chapter
|
160
|
+
finded = true
|
161
|
+
end
|
155
162
|
end
|
156
163
|
nil # not found
|
157
164
|
end
|
@@ -160,7 +167,9 @@ module ReVIEW
|
|
160
167
|
finded = false
|
161
168
|
each_chapter_r do |c|
|
162
169
|
return c if finded
|
163
|
-
|
170
|
+
if c == chapter
|
171
|
+
finded = true
|
172
|
+
end
|
164
173
|
end
|
165
174
|
nil # not found
|
166
175
|
end
|
@@ -171,10 +180,6 @@ module ReVIEW
|
|
171
180
|
vol
|
172
181
|
end
|
173
182
|
|
174
|
-
def config
|
175
|
-
@config ||= Configure.values
|
176
|
-
end
|
177
|
-
|
178
183
|
def load_config(filename)
|
179
184
|
new_conf = YAML.load_file(filename)
|
180
185
|
@config.merge!(new_conf)
|
@@ -184,9 +189,11 @@ module ReVIEW
|
|
184
189
|
return @catalog if @catalog.present?
|
185
190
|
|
186
191
|
catalogfile_path = filename_join(@basedir, config['catalogfile'])
|
187
|
-
|
192
|
+
if File.file? catalogfile_path
|
193
|
+
@catalog = File.open(catalogfile_path, 'r:BOM|utf-8') { |f| Catalog.new(f) }
|
194
|
+
end
|
188
195
|
if @catalog
|
189
|
-
@catalog.validate!(basedir)
|
196
|
+
@catalog.validate!(@config, basedir)
|
190
197
|
end
|
191
198
|
@catalog
|
192
199
|
end
|
@@ -256,7 +263,9 @@ module ReVIEW
|
|
256
263
|
|
257
264
|
begin
|
258
265
|
predef_file = filename_join(@basedir, config['predef_file'])
|
259
|
-
|
266
|
+
if File.file?(predef_file)
|
267
|
+
mkpart_from_namelistfile(predef_file)
|
268
|
+
end
|
260
269
|
rescue FileNotFound => err
|
261
270
|
raise FileNotFound, "preface #{err.message}"
|
262
271
|
end
|
@@ -271,14 +280,18 @@ module ReVIEW
|
|
271
280
|
|
272
281
|
begin
|
273
282
|
postdef_file = filename_join(@basedir, config['postdef_file'])
|
274
|
-
|
283
|
+
if File.file?(postdef_file)
|
284
|
+
mkpart_from_namelistfile(postdef_file)
|
285
|
+
end
|
275
286
|
rescue FileNotFound => err
|
276
287
|
raise FileNotFound, "postscript #{err.message}"
|
277
288
|
end
|
278
289
|
end
|
279
290
|
|
280
291
|
def postscripts
|
281
|
-
|
292
|
+
if catalog
|
293
|
+
mkpart_from_namelist(catalog.postdef.split("\n"))
|
294
|
+
end
|
282
295
|
end
|
283
296
|
|
284
297
|
private
|
@@ -308,12 +321,12 @@ module ReVIEW
|
|
308
321
|
return catalog.parts_with_chaps.map do |entry|
|
309
322
|
if entry.is_a?(Hash)
|
310
323
|
chaps = entry.values.first.map do |chap|
|
311
|
-
chap = Chapter.new(self, num += 1, chap, File.join(
|
324
|
+
chap = Chapter.new(self, num += 1, chap, File.join(contentdir, chap))
|
312
325
|
chap
|
313
326
|
end
|
314
327
|
Part.new(self, part += 1, chaps, read_part.split("\n")[part - 1])
|
315
328
|
else
|
316
|
-
chap = Chapter.new(self, num += 1, entry, File.join(
|
329
|
+
chap = Chapter.new(self, num += 1, entry, File.join(contentdir, entry))
|
317
330
|
if chap.number
|
318
331
|
num = chap.number
|
319
332
|
else
|
@@ -327,7 +340,7 @@ module ReVIEW
|
|
327
340
|
chap = read_chaps.
|
328
341
|
strip.lines.map(&:strip).join("\n").split(/\n{2,}/).
|
329
342
|
map do |part_chunk|
|
330
|
-
chaps = part_chunk.split.map { |chapid| Chapter.new(self, num += 1, chapid, File.join(
|
343
|
+
chaps = part_chunk.split.map { |chapid| Chapter.new(self, num += 1, chapid, File.join(contentdir, chapid)) }
|
331
344
|
if part_exist? && read_part.split("\n").size > part
|
332
345
|
Part.new(self, part += 1, chaps, read_part.split("\n")[part - 1])
|
333
346
|
else
|
@@ -359,14 +372,14 @@ module ReVIEW
|
|
359
372
|
|
360
373
|
def mkchap(name, number = nil)
|
361
374
|
name += ext if File.extname(name).empty?
|
362
|
-
path = File.join(
|
375
|
+
path = File.join(contentdir, name)
|
363
376
|
raise FileNotFound, "file not exist: #{path}" unless File.file?(path)
|
364
377
|
Chapter.new(self, number, name, path)
|
365
378
|
end
|
366
379
|
|
367
380
|
def mkchap_ifexist(name, idx = nil)
|
368
381
|
name += ext if File.extname(name).empty?
|
369
|
-
path = File.join(
|
382
|
+
path = File.join(contentdir, name)
|
370
383
|
if File.file?(path)
|
371
384
|
idx += 1 if idx
|
372
385
|
Chapter.new(self, idx, name, path)
|
@@ -376,7 +389,9 @@ module ReVIEW
|
|
376
389
|
def read_file(filename)
|
377
390
|
unless @warn_old_files[filename]
|
378
391
|
@warn_old_files[filename] = true
|
379
|
-
|
392
|
+
if caller.none? { |item| item =~ %r{/review/test/test_} }
|
393
|
+
@logger.warn "!!! #{filename} is obsoleted. please use catalog.yml."
|
394
|
+
end
|
380
395
|
end
|
381
396
|
res = ''
|
382
397
|
File.open(filename_join(@basedir, filename), 'r:BOM|utf-8') do |f|
|
data/lib/review/book/chapter.rb
CHANGED
@@ -51,7 +51,7 @@ module ReVIEW
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def find_first_header_option
|
54
|
-
f = LineInput.new(
|
54
|
+
f = LineInput.new(StringIO.new(@content))
|
55
55
|
while f.next?
|
56
56
|
case f.peek
|
57
57
|
when /\A=+[\[\s\{]/
|
@@ -59,7 +59,9 @@ module ReVIEW
|
|
59
59
|
return m[2] # tag
|
60
60
|
when %r{/\A//[a-z]+/}
|
61
61
|
line = f.gets
|
62
|
-
|
62
|
+
if line.rstrip[-1, 1] == '{'
|
63
|
+
f.until_match(%r{\A//\}})
|
64
|
+
end
|
63
65
|
end
|
64
66
|
f.gets
|
65
67
|
end
|
@@ -72,18 +74,28 @@ module ReVIEW
|
|
72
74
|
|
73
75
|
def format_number(heading = true)
|
74
76
|
return '' unless @number
|
75
|
-
|
77
|
+
if on_predef?
|
78
|
+
return @number.to_s
|
79
|
+
end
|
76
80
|
|
77
81
|
if on_appendix?
|
78
|
-
|
79
|
-
|
82
|
+
# XXX: should be extracted with magic number
|
83
|
+
if @number < 1 || @number > 27
|
84
|
+
return @number.to_s
|
85
|
+
end
|
86
|
+
if @book.config['appendix_format']
|
87
|
+
raise ReVIEW::ConfigError, %Q('appendix_format:' in config.yml is obsoleted.)
|
88
|
+
end
|
80
89
|
|
81
90
|
i18n_appendix = I18n.get('appendix')
|
82
91
|
fmt = i18n_appendix.scan(/%\w{1,3}/).first || '%s'
|
83
92
|
I18n.update('appendix_without_heading' => fmt)
|
84
93
|
|
85
|
-
|
86
|
-
|
94
|
+
if heading
|
95
|
+
return I18n.t('appendix', @number)
|
96
|
+
else
|
97
|
+
return I18n.t('appendix_without_heading', @number)
|
98
|
+
end
|
87
99
|
end
|
88
100
|
|
89
101
|
if heading
|
@@ -14,10 +14,7 @@ module ReVIEW
|
|
14
14
|
include TextUtils
|
15
15
|
attr_reader :book
|
16
16
|
attr_reader :path
|
17
|
-
|
18
|
-
def env
|
19
|
-
@book
|
20
|
-
end
|
17
|
+
attr_accessor :content
|
21
18
|
|
22
19
|
def dirname
|
23
20
|
return nil unless @path
|
@@ -62,18 +59,6 @@ module ReVIEW
|
|
62
59
|
@volume
|
63
60
|
end
|
64
61
|
|
65
|
-
# deprecated; use content()
|
66
|
-
def open(&_block)
|
67
|
-
return (block_given? ? yield(@io) : @io) if @io
|
68
|
-
StringIO.new(content)
|
69
|
-
end
|
70
|
-
|
71
|
-
attr_writer :content
|
72
|
-
|
73
|
-
def content
|
74
|
-
@content
|
75
|
-
end
|
76
|
-
|
77
62
|
def lines
|
78
63
|
# FIXME: we cannot duplicate Enumerator on ruby 1.9 HEAD
|
79
64
|
(@lines ||= content.lines.to_a).dup
|
@@ -116,20 +101,20 @@ module ReVIEW
|
|
116
101
|
def numberless_image_index
|
117
102
|
@numberless_image_index ||=
|
118
103
|
NumberlessImageIndex.parse(lines, id,
|
119
|
-
|
104
|
+
@book.imagedir,
|
120
105
|
@book.image_types, @book.config['builder'])
|
121
106
|
end
|
122
107
|
|
123
108
|
def image_index
|
124
109
|
@image_index ||= ImageIndex.parse(lines, id,
|
125
|
-
|
110
|
+
@book.imagedir,
|
126
111
|
@book.image_types, @book.config['builder'])
|
127
112
|
@image_index
|
128
113
|
end
|
129
114
|
|
130
115
|
def icon_index
|
131
116
|
@icon_index ||= IconIndex.parse(lines, id,
|
132
|
-
|
117
|
+
@book.imagedir,
|
133
118
|
@book.image_types, @book.config['builder'])
|
134
119
|
@icon_index
|
135
120
|
end
|
@@ -137,7 +122,7 @@ module ReVIEW
|
|
137
122
|
def indepimage_index
|
138
123
|
@indepimage_index ||=
|
139
124
|
IndepImageIndex.parse(lines, id,
|
140
|
-
|
125
|
+
@book.imagedir,
|
141
126
|
@book.image_types, @book.config['builder'])
|
142
127
|
end
|
143
128
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright (c) 2014-
|
2
|
+
# Copyright (c) 2014-2018 Minero Aoki, Kenshi Muto, Masayoshi Takahashi
|
3
3
|
#
|
4
4
|
# This program is free software.
|
5
5
|
# You can distribute or modify this program under the terms of
|
@@ -22,7 +22,7 @@ module ReVIEW
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def dir_entries
|
25
|
-
Dir.glob(File.join(@basedir, '**{,/*/**}/*.*')).uniq
|
25
|
+
Dir.glob(File.join(@basedir, '**{,/*/**}/*.*')).uniq.sort
|
26
26
|
end
|
27
27
|
|
28
28
|
def add_entry(path)
|
@@ -33,7 +33,14 @@ module ReVIEW
|
|
33
33
|
def find_path(id)
|
34
34
|
targets = target_list(id)
|
35
35
|
targets.each do |target|
|
36
|
-
@exts.each
|
36
|
+
@exts.each do |ext|
|
37
|
+
@entries.find do |entry|
|
38
|
+
downname = entry.sub(/\.[^.]+$/, File.extname(entry).downcase)
|
39
|
+
if downname == "#{target}#{ext}"
|
40
|
+
return entry
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
37
44
|
end
|
38
45
|
nil
|
39
46
|
end
|