review 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/.rubocop.yml +4 -1
- data/NEWS.ja.md +29 -0
- data/NEWS.md +29 -0
- data/bin/review-index +2 -89
- data/bin/review-vol +4 -78
- data/doc/config.yml.sample +18 -5
- data/doc/config.yml.sample-simple +1 -1
- data/doc/pdfmaker.ja.md +42 -0
- data/doc/pdfmaker.md +41 -0
- data/doc/quickstart.ja.md +8 -5
- data/doc/quickstart.md +7 -4
- data/lib/review/book/base.rb +2 -4
- data/lib/review/book/compilable.rb +1 -5
- data/lib/review/book/page_metric.rb +7 -7
- data/lib/review/book/part.rb +6 -3
- data/lib/review/book/volume.rb +3 -4
- data/lib/review/builder.rb +23 -10
- data/lib/review/compiler.rb +9 -9
- data/lib/review/configure.rb +6 -0
- data/lib/review/epubmaker.rb +1 -1
- data/lib/review/htmlbuilder.rb +56 -16
- data/lib/review/idgxmlbuilder.rb +63 -22
- data/lib/review/latexbuilder.rb +70 -19
- data/lib/review/makerhelper.rb +18 -1
- data/lib/review/pdfmaker.rb +8 -1
- data/lib/review/plaintextbuilder.rb +41 -11
- data/lib/review/textmaker.rb +1 -1
- data/lib/review/textutils.rb +2 -3
- data/lib/review/tocprinter.rb +231 -102
- data/lib/review/topbuilder.rb +47 -13
- data/lib/review/version.rb +1 -1
- data/lib/review/volumeprinter.rb +99 -0
- data/lib/review/webmaker.rb +1 -1
- data/lib/review/webtocprinter.rb +38 -35
- data/review.gemspec +1 -1
- data/samples/sample-book/src/config.yml +1 -1
- data/templates/web/html/layout-html5.html.erb +2 -2
- data/test/test_book.rb +1 -1
- data/test/test_book_part.rb +3 -3
- data/test/test_helper.rb +4 -1
- data/test/test_htmlbuilder.rb +179 -0
- data/test/test_idgxmlbuilder.rb +143 -0
- data/test/test_latexbuilder.rb +223 -0
- data/test/test_pdfmaker.rb +17 -0
- data/test/test_plaintextbuilder.rb +99 -0
- data/test/test_topbuilder.rb +116 -2
- data/test/test_webtocprinter.rb +66 -34
- metadata +3 -5
- data/lib/review/tocparser.rb +0 -275
- data/test/test_tocparser.rb +0 -25
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: review
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kmuto
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-06-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: image_size
|
@@ -305,11 +305,11 @@ files:
|
|
305
305
|
- lib/review/textbuilder.rb
|
306
306
|
- lib/review/textmaker.rb
|
307
307
|
- lib/review/textutils.rb
|
308
|
-
- lib/review/tocparser.rb
|
309
308
|
- lib/review/tocprinter.rb
|
310
309
|
- lib/review/topbuilder.rb
|
311
310
|
- lib/review/update.rb
|
312
311
|
- lib/review/version.rb
|
312
|
+
- lib/review/volumeprinter.rb
|
313
313
|
- lib/review/webmaker.rb
|
314
314
|
- lib/review/webtocprinter.rb
|
315
315
|
- lib/review/yamlloader.rb
|
@@ -445,7 +445,6 @@ files:
|
|
445
445
|
- test/test_template.rb
|
446
446
|
- test/test_textmaker_cmd.rb
|
447
447
|
- test/test_textutils.rb
|
448
|
-
- test/test_tocparser.rb
|
449
448
|
- test/test_topbuilder.rb
|
450
449
|
- test/test_update.rb
|
451
450
|
- test/test_webtocprinter.rb
|
@@ -620,7 +619,6 @@ test_files:
|
|
620
619
|
- test/test_template.rb
|
621
620
|
- test/test_textmaker_cmd.rb
|
622
621
|
- test/test_textutils.rb
|
623
|
-
- test/test_tocparser.rb
|
624
622
|
- test/test_topbuilder.rb
|
625
623
|
- test/test_update.rb
|
626
624
|
- test/test_webtocprinter.rb
|
data/lib/review/tocparser.rb
DELETED
@@ -1,275 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2008-2019 Minero Aoki, Kenshi Muto
|
3
|
-
# 2002-2007 Minero Aoki
|
4
|
-
#
|
5
|
-
# This program is free software.
|
6
|
-
# You can distribute or modify this program under the terms of
|
7
|
-
# the GNU LGPL, Lesser General Public License version 2.1.
|
8
|
-
# For details of the GNU LGPL, see the file "COPYING".
|
9
|
-
#
|
10
|
-
|
11
|
-
require 'review/preprocessor'
|
12
|
-
require 'review/book'
|
13
|
-
require 'review/textbuilder'
|
14
|
-
|
15
|
-
module ReVIEW
|
16
|
-
class TOCParser
|
17
|
-
def self.parse(chap)
|
18
|
-
stream = StringIO.new(chap.content, 'rt:BOM|utf-8')
|
19
|
-
new.parse(stream, chap).map do |root|
|
20
|
-
root.number = chap.number
|
21
|
-
root
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.chapter_node(chap)
|
26
|
-
toc = self.parse(chap)
|
27
|
-
$stderr.puts "warning: chapter #{toc.join} contains more than 1 chapter" unless toc.size == 1
|
28
|
-
toc.first
|
29
|
-
end
|
30
|
-
|
31
|
-
def parse(f, chap)
|
32
|
-
roots = [] # list of chapters
|
33
|
-
node_stack = []
|
34
|
-
@chap = chap
|
35
|
-
filename = chap.path
|
36
|
-
while line = f.gets
|
37
|
-
case line
|
38
|
-
when /\A\#@/
|
39
|
-
# do nothing
|
40
|
-
next
|
41
|
-
when /\A\s*\z/
|
42
|
-
# do nothing
|
43
|
-
next
|
44
|
-
when /\A(={2,})[\[\s\{]/
|
45
|
-
lev = $1.size
|
46
|
-
if lev > 5
|
47
|
-
error!(filename, f.lineno, "section level too deep: #{lev}")
|
48
|
-
end
|
49
|
-
label = get_label(line)
|
50
|
-
if node_stack.empty?
|
51
|
-
# missing chapter label
|
52
|
-
dummy_chapter = Chapter.new(label, chap)
|
53
|
-
node_stack.push(dummy_chapter)
|
54
|
-
roots.push(dummy_chapter)
|
55
|
-
end
|
56
|
-
next if label.start_with?('[/') # ex) "[/column]"
|
57
|
-
sec = Section.new(lev, label.gsub(/\A\{.*?\}\s?/, ''))
|
58
|
-
node_stack.pop until node_stack.last.level < sec.level
|
59
|
-
node_stack.last.add_child(sec)
|
60
|
-
node_stack.push(sec)
|
61
|
-
|
62
|
-
when /\A=[^=]/
|
63
|
-
label = get_label(line)
|
64
|
-
node_stack.clear
|
65
|
-
new_chapter = Chapter.new(label, chap)
|
66
|
-
node_stack.push(new_chapter)
|
67
|
-
roots.push(new_chapter)
|
68
|
-
|
69
|
-
when %r{\A//\w+(?:\[.*?\])*\{\s*\z}
|
70
|
-
if node_stack.empty?
|
71
|
-
error!(filename, f.lineno, 'list found before section label')
|
72
|
-
end
|
73
|
-
node_stack.last.add_child(list = List.new)
|
74
|
-
beg = f.lineno
|
75
|
-
list.add(line)
|
76
|
-
while line = f.gets
|
77
|
-
break if line.start_with?('//}')
|
78
|
-
list.add(line)
|
79
|
-
end
|
80
|
-
error!(filename, beg, 'unterminated list') unless line
|
81
|
-
|
82
|
-
when %r{\A//\w}
|
83
|
-
# do nothing
|
84
|
-
next
|
85
|
-
else
|
86
|
-
# if node_stack.empty?
|
87
|
-
# error! filename, f.lineno, 'text found before section label'
|
88
|
-
# end
|
89
|
-
next if node_stack.empty?
|
90
|
-
node_stack.last.add_child(par = Paragraph.new(chap))
|
91
|
-
par.add(line)
|
92
|
-
while line = f.gets
|
93
|
-
break if /\A\s*\z/ =~ line
|
94
|
-
par.add(line)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
roots
|
100
|
-
end
|
101
|
-
|
102
|
-
def get_label(line)
|
103
|
-
line = line.strip.sub(/\A=+\s*/, '')
|
104
|
-
compile_label(line)
|
105
|
-
end
|
106
|
-
|
107
|
-
def compile_label(line)
|
108
|
-
b = ReVIEW::TEXTBuilder.new
|
109
|
-
dummy_book = ReVIEW::Book::Base.load
|
110
|
-
dummy_chapter = ReVIEW::Book::Chapter.new(dummy_book, 1, '-', nil, StringIO.new)
|
111
|
-
if @chap
|
112
|
-
dummy_chapter = @chap
|
113
|
-
end
|
114
|
-
dummy_loc = Location.new('', StringIO.new)
|
115
|
-
b.bind(ReVIEW::Compiler.new(b), dummy_chapter, dummy_loc)
|
116
|
-
b.compile_inline(line)
|
117
|
-
end
|
118
|
-
|
119
|
-
def error!(filename, lineno, msg)
|
120
|
-
raise "#{filename}:#{lineno}: #{msg}"
|
121
|
-
end
|
122
|
-
|
123
|
-
class Node
|
124
|
-
def initialize(children = [])
|
125
|
-
@children = children
|
126
|
-
end
|
127
|
-
|
128
|
-
attr_reader :children
|
129
|
-
|
130
|
-
def add_child(c)
|
131
|
-
@children.push(c)
|
132
|
-
end
|
133
|
-
|
134
|
-
def each_node(&block)
|
135
|
-
@children.each do |c|
|
136
|
-
yield c
|
137
|
-
c.each(&block)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def each_child(&block)
|
142
|
-
@children.each(&block)
|
143
|
-
end
|
144
|
-
|
145
|
-
def chapter?
|
146
|
-
false
|
147
|
-
end
|
148
|
-
|
149
|
-
def each_section(&block)
|
150
|
-
@children.each { |n| n.yield_section(&block) }
|
151
|
-
end
|
152
|
-
|
153
|
-
def each_section_with_index
|
154
|
-
i = 0
|
155
|
-
each_section do |n|
|
156
|
-
yield n, i
|
157
|
-
i += 1
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
def section_size
|
162
|
-
cnt = 0
|
163
|
-
@children.each { |n| n.yield_section { cnt += 1 } }
|
164
|
-
cnt
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
class Section < Node
|
169
|
-
def initialize(level, label, path = nil)
|
170
|
-
super()
|
171
|
-
@level = level
|
172
|
-
@label = label
|
173
|
-
@filename = path ? real_filename(path) : nil
|
174
|
-
end
|
175
|
-
|
176
|
-
def real_filename(path)
|
177
|
-
if FileTest.symlink?(path)
|
178
|
-
File.basename(File.readlink(path))
|
179
|
-
else
|
180
|
-
File.basename(path)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
private :real_filename
|
184
|
-
|
185
|
-
attr_reader :level
|
186
|
-
attr_reader :label
|
187
|
-
|
188
|
-
def estimated_lines
|
189
|
-
@children.inject(0) { |sum, n| sum + n.estimated_lines }
|
190
|
-
end
|
191
|
-
|
192
|
-
def yield_section
|
193
|
-
yield self
|
194
|
-
end
|
195
|
-
|
196
|
-
def inspect
|
197
|
-
"#<#{self.class} level=#{@level} #{@label}>"
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
class Chapter < Section
|
202
|
-
def initialize(label, chap)
|
203
|
-
super(1, label, chap.path)
|
204
|
-
@chapter = chap
|
205
|
-
@chapter_id = chap.id
|
206
|
-
@path = chap.path
|
207
|
-
@page_metric = chap.book.page_metric
|
208
|
-
@volume = nil
|
209
|
-
@number = nil
|
210
|
-
end
|
211
|
-
|
212
|
-
attr_accessor :number
|
213
|
-
|
214
|
-
def chapter?
|
215
|
-
true
|
216
|
-
end
|
217
|
-
|
218
|
-
attr_reader :chapter_id
|
219
|
-
|
220
|
-
def volume
|
221
|
-
return @volume if @volume
|
222
|
-
@volume = @chapter.volume
|
223
|
-
@volume.lines = estimated_lines
|
224
|
-
@volume
|
225
|
-
end
|
226
|
-
|
227
|
-
def inspect
|
228
|
-
"#<#{self.class} #{@filename}>"
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
class Paragraph < Node
|
233
|
-
def initialize(chap)
|
234
|
-
@bytes = 0
|
235
|
-
@page_metric = chap.book.page_metric
|
236
|
-
end
|
237
|
-
|
238
|
-
def inspect
|
239
|
-
"#<#{self.class}>"
|
240
|
-
end
|
241
|
-
|
242
|
-
def add(line)
|
243
|
-
@bytes += line.strip.bytesize
|
244
|
-
end
|
245
|
-
|
246
|
-
def estimated_lines
|
247
|
-
(@bytes + 2) / @page_metric.text.n_columns + 1
|
248
|
-
end
|
249
|
-
|
250
|
-
def yield_section
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
class List < Node
|
255
|
-
def initialize
|
256
|
-
@lines = 0
|
257
|
-
end
|
258
|
-
|
259
|
-
def inspect
|
260
|
-
"#<#{self.class}>"
|
261
|
-
end
|
262
|
-
|
263
|
-
def add(_line)
|
264
|
-
@lines += 1
|
265
|
-
end
|
266
|
-
|
267
|
-
def estimated_lines
|
268
|
-
@lines + 2
|
269
|
-
end
|
270
|
-
|
271
|
-
def yield_section
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
data/test/test_tocparser.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'review/tocparser'
|
3
|
-
|
4
|
-
class TOCParserTest < Test::Unit::TestCase
|
5
|
-
include ReVIEW
|
6
|
-
|
7
|
-
def test_tocparser_parse_null
|
8
|
-
dummy_book = ReVIEW::Book::Base.load
|
9
|
-
chap = ReVIEW::Book::Chapter.new(dummy_book, 1, '-', nil, StringIO.new)
|
10
|
-
ret = TOCParser.parse(chap)
|
11
|
-
assert_equal [], ret
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_tocparser_parse
|
15
|
-
dummy_book = ReVIEW::Book::Base.load
|
16
|
-
io = StringIO.new("= test\n\naaa\n//image[foo][bar]{\n//}\n\n== test2\n\n=== test3\n\n==test21\n\n=test11\n")
|
17
|
-
chap = ReVIEW::Book::Chapter.new(dummy_book, 1, 'foo', 'bar/foo.re', io)
|
18
|
-
ret = TOCParser.parse(chap)
|
19
|
-
assert_equal 2, ret.size ## XXX how to count chapters including multiple L1 headlines ??
|
20
|
-
chap_node = ret[0]
|
21
|
-
assert_equal ReVIEW::TOCParser::Chapter, chap_node.class
|
22
|
-
assert_equal 'foo', chap_node.chapter_id
|
23
|
-
assert_equal 1, chap_node.number
|
24
|
-
end
|
25
|
-
end
|