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
@@ -1,8 +1,5 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
# Copyright (c) 2002-2008 Minero Aoki
|
5
|
-
# 2009-2017 Minero Aoki, Kenshi Muto
|
1
|
+
# Copyright (c) 2009-2017 Minero Aoki, Kenshi Muto
|
2
|
+
# 2002-2008 Minero Aoki
|
6
3
|
#
|
7
4
|
# This program is free software.
|
8
5
|
# You can distribute or modify this program under the terms of
|
@@ -10,6 +7,7 @@
|
|
10
7
|
# For details of the GNU LGPL, see the file "COPYING".
|
11
8
|
#
|
12
9
|
require 'review/textutils'
|
10
|
+
|
13
11
|
module ReVIEW
|
14
12
|
module Book
|
15
13
|
module Compilable
|
@@ -42,7 +40,7 @@ module ReVIEW
|
|
42
40
|
return @title if @title
|
43
41
|
|
44
42
|
@title = ''
|
45
|
-
return @title
|
43
|
+
return @title unless content
|
46
44
|
content.each_line do |line|
|
47
45
|
if line =~ /\A=+/
|
48
46
|
@title = line.sub(/\A=+(\[.+?\])?(\{.+?\})?/, '').strip
|
@@ -57,16 +55,16 @@ module ReVIEW
|
|
57
55
|
end
|
58
56
|
|
59
57
|
def volume
|
60
|
-
|
61
|
-
@volume = Volume.count_file(path
|
58
|
+
unless @volume
|
59
|
+
@volume = Volume.count_file(path)
|
62
60
|
@volume.page_per_kbyte = @book.page_metric.page_per_kbyte
|
63
61
|
end
|
64
62
|
@volume
|
65
63
|
end
|
66
64
|
|
67
65
|
# deprecated; use content()
|
68
|
-
def open(&
|
69
|
-
return (block_given?
|
66
|
+
def open(&_block)
|
67
|
+
return (block_given? ? yield(@io) : @io) if @io
|
70
68
|
StringIO.new(content)
|
71
69
|
end
|
72
70
|
|
@@ -78,59 +76,59 @@ module ReVIEW
|
|
78
76
|
|
79
77
|
def lines
|
80
78
|
# FIXME: we cannot duplicate Enumerator on ruby 1.9 HEAD
|
81
|
-
(@lines ||= content
|
79
|
+
(@lines ||= content.lines.to_a).dup
|
82
80
|
end
|
83
81
|
|
84
82
|
def list(id)
|
85
|
-
list_index
|
83
|
+
list_index[id]
|
86
84
|
end
|
87
85
|
|
88
86
|
def list_index
|
89
|
-
@list_index ||= ListIndex.parse(lines
|
87
|
+
@list_index ||= ListIndex.parse(lines)
|
90
88
|
@list_index
|
91
89
|
end
|
92
90
|
|
93
91
|
def table(id)
|
94
|
-
table_index
|
92
|
+
table_index[id]
|
95
93
|
end
|
96
94
|
|
97
95
|
def table_index
|
98
|
-
@table_index ||= TableIndex.parse(lines
|
96
|
+
@table_index ||= TableIndex.parse(lines)
|
99
97
|
@table_index
|
100
98
|
end
|
101
99
|
|
102
100
|
def footnote(id)
|
103
|
-
footnote_index
|
101
|
+
footnote_index[id]
|
104
102
|
end
|
105
103
|
|
106
104
|
def footnote_index
|
107
|
-
@footnote_index ||= FootnoteIndex.parse(lines
|
105
|
+
@footnote_index ||= FootnoteIndex.parse(lines)
|
108
106
|
@footnote_index
|
109
107
|
end
|
110
108
|
|
111
109
|
def image(id)
|
112
|
-
return image_index
|
113
|
-
return icon_index
|
114
|
-
return numberless_image_index
|
115
|
-
indepimage_index
|
110
|
+
return image_index[id] if image_index.key?(id)
|
111
|
+
return icon_index[id] if icon_index.key?(id)
|
112
|
+
return numberless_image_index[id] if numberless_image_index.key?(id)
|
113
|
+
indepimage_index[id]
|
116
114
|
end
|
117
115
|
|
118
116
|
def numberless_image_index
|
119
117
|
@numberless_image_index ||=
|
120
|
-
NumberlessImageIndex.parse(lines
|
118
|
+
NumberlessImageIndex.parse(lines, id,
|
121
119
|
"#{book.basedir}/#{@book.config['imagedir']}",
|
122
120
|
@book.image_types, @book.config['builder'])
|
123
121
|
end
|
124
122
|
|
125
123
|
def image_index
|
126
|
-
@image_index ||= ImageIndex.parse(lines
|
124
|
+
@image_index ||= ImageIndex.parse(lines, id,
|
127
125
|
"#{book.basedir}/#{@book.config['imagedir']}",
|
128
126
|
@book.image_types, @book.config['builder'])
|
129
127
|
@image_index
|
130
128
|
end
|
131
129
|
|
132
130
|
def icon_index
|
133
|
-
@icon_index ||= IconIndex.parse(lines
|
131
|
+
@icon_index ||= IconIndex.parse(lines, id,
|
134
132
|
"#{book.basedir}/#{@book.config['imagedir']}",
|
135
133
|
@book.image_types, @book.config['builder'])
|
136
134
|
@icon_index
|
@@ -138,13 +136,13 @@ module ReVIEW
|
|
138
136
|
|
139
137
|
def indepimage_index
|
140
138
|
@indepimage_index ||=
|
141
|
-
IndepImageIndex.parse(lines
|
139
|
+
IndepImageIndex.parse(lines, id,
|
142
140
|
"#{book.basedir}/#{@book.config['imagedir']}",
|
143
141
|
@book.image_types, @book.config['builder'])
|
144
142
|
end
|
145
143
|
|
146
144
|
def bibpaper(id)
|
147
|
-
bibpaper_index
|
145
|
+
bibpaper_index[id]
|
148
146
|
end
|
149
147
|
|
150
148
|
def bibpaper_index
|
@@ -154,19 +152,19 @@ module ReVIEW
|
|
154
152
|
end
|
155
153
|
|
156
154
|
def headline(caption)
|
157
|
-
headline_index
|
155
|
+
headline_index[caption]
|
158
156
|
end
|
159
157
|
|
160
158
|
def headline_index
|
161
|
-
@headline_index ||= HeadlineIndex.parse(lines
|
159
|
+
@headline_index ||= HeadlineIndex.parse(lines, self)
|
162
160
|
end
|
163
161
|
|
164
162
|
def column(id)
|
165
|
-
column_index
|
163
|
+
column_index[id]
|
166
164
|
end
|
167
165
|
|
168
166
|
def column_index
|
169
|
-
@column_index ||= ColumnIndex.parse(lines
|
167
|
+
@column_index ||= ColumnIndex.parse(lines)
|
170
168
|
end
|
171
169
|
|
172
170
|
def next_chapter
|
@@ -179,4 +177,3 @@ module ReVIEW
|
|
179
177
|
end
|
180
178
|
end
|
181
179
|
end
|
182
|
-
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright (c) 2014 Minero Aoki, Kenshi Muto, Masayoshi Takahashi
|
2
|
+
# Copyright (c) 2014-2017 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
|
@@ -18,28 +18,22 @@ module ReVIEW
|
|
18
18
|
@chapid = chapid
|
19
19
|
@builder = builder
|
20
20
|
@exts = exts
|
21
|
-
@entries =
|
21
|
+
@entries = dir_entries
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
Dir.glob(File.join(@basedir,
|
24
|
+
def dir_entries
|
25
|
+
Dir.glob(File.join(@basedir, '**{,/*/**}/*.*')).uniq
|
26
26
|
end
|
27
27
|
|
28
28
|
def add_entry(path)
|
29
|
-
unless @entries.include?(path)
|
30
|
-
@entries << path
|
31
|
-
end
|
29
|
+
@entries << path unless @entries.include?(path)
|
32
30
|
@entries
|
33
31
|
end
|
34
32
|
|
35
33
|
def find_path(id)
|
36
34
|
targets = target_list(id)
|
37
35
|
targets.each do |target|
|
38
|
-
@exts.each
|
39
|
-
if @entries.include?("#{target}#{ext}")
|
40
|
-
return "#{target}#{ext}"
|
41
|
-
end
|
42
|
-
end
|
36
|
+
@exts.each { |ext| return "#{target}#{ext}" if @entries.include?("#{target}#{ext}") }
|
43
37
|
end
|
44
38
|
nil
|
45
39
|
end
|
@@ -65,7 +59,6 @@ module ReVIEW
|
|
65
59
|
"#{@basedir}/#{id}"
|
66
60
|
]
|
67
61
|
end
|
68
|
-
|
69
62
|
end
|
70
63
|
end
|
71
64
|
end
|
data/lib/review/book/index.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
# Copyright (c) 2002-2007 Minero Aoki
|
4
|
-
# 2008-2017 Minero Aoki, Kenshi Muto
|
1
|
+
# Copyright (c) 2008-2017 Minero Aoki, 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,20 +11,19 @@ require 'review/extentions'
|
|
13
11
|
require 'review/exception'
|
14
12
|
require 'review/book/image_finder'
|
15
13
|
require 'review/i18n'
|
14
|
+
require 'review/logger'
|
16
15
|
|
17
16
|
module ReVIEW
|
18
17
|
module Book
|
19
18
|
class Index
|
20
|
-
def
|
19
|
+
def self.parse(src, *args)
|
21
20
|
items = []
|
22
21
|
seq = 1
|
23
|
-
src.grep(%r
|
22
|
+
src.grep(%r{\A//#{item_type}}) do |line|
|
24
23
|
if id = line.slice(/\[(.*?)\]/, 1)
|
25
|
-
items.push item_class
|
24
|
+
items.push item_class.new(id, seq)
|
26
25
|
seq += 1
|
27
|
-
|
28
|
-
warn "warning: no ID of #{item_type()} in #{line}"
|
29
|
-
end
|
26
|
+
ReVIEW.logger.warn "warning: no ID of #{item_type} in #{line}" if id.empty?
|
30
27
|
end
|
31
28
|
end
|
32
29
|
new(items, *args)
|
@@ -34,7 +31,7 @@ module ReVIEW
|
|
34
31
|
|
35
32
|
Item = Struct.new(:id, :number)
|
36
33
|
|
37
|
-
def
|
34
|
+
def self.item_class
|
38
35
|
self::Item
|
39
36
|
end
|
40
37
|
|
@@ -47,8 +44,9 @@ module ReVIEW
|
|
47
44
|
def initialize(items)
|
48
45
|
@items = items
|
49
46
|
@index = {}
|
47
|
+
@logger = ReVIEW.logger
|
50
48
|
items.each do |i|
|
51
|
-
warn "warning: duplicate ID: #{i.id} (#{i})"
|
49
|
+
@logger.warn "warning: duplicate ID: #{i.id} (#{i})" if @index[i.id]
|
52
50
|
@index[i.id] = i
|
53
51
|
end
|
54
52
|
@image_finder = nil
|
@@ -57,16 +55,14 @@ module ReVIEW
|
|
57
55
|
def [](id)
|
58
56
|
@index.fetch(id)
|
59
57
|
rescue
|
60
|
-
if @index.keys.map{|i| i.split(
|
61
|
-
each_with_object(Hash.new(0)){|i, h| h[i] += 1}. # number of occurrences
|
62
|
-
select{|k, v| k == id && v > 1 }.present? # detect duplicated
|
58
|
+
if @index.keys.map { |i| i.split('|').last }.flatten. # unfold all ids
|
59
|
+
each_with_object(Hash.new(0)) { |i, h| h[i] += 1 }. # number of occurrences
|
60
|
+
select { |k, v| k == id && v > 1 }.present? # detect duplicated
|
63
61
|
raise KeyError, "key '#{id}' is ambiguous for #{self.class}"
|
64
62
|
end
|
65
63
|
|
66
64
|
@items.each do |i|
|
67
|
-
if i.id.split(
|
68
|
-
return i
|
69
|
-
end
|
65
|
+
return i if i.id.split('|').include?(id)
|
70
66
|
end
|
71
67
|
raise KeyError, "not found key '#{id}' for #{self.class}"
|
72
68
|
end
|
@@ -80,12 +76,11 @@ module ReVIEW
|
|
80
76
|
end
|
81
77
|
|
82
78
|
def key?(id)
|
83
|
-
|
79
|
+
@index.key?(id)
|
84
80
|
end
|
85
81
|
alias_method :has_key?, :key?
|
86
82
|
end
|
87
83
|
|
88
|
-
|
89
84
|
class ChapterIndex < Index
|
90
85
|
def item_type
|
91
86
|
'chapter'
|
@@ -95,7 +90,7 @@ module ReVIEW
|
|
95
90
|
chapter = @index.fetch(id)
|
96
91
|
chapter.format_number
|
97
92
|
rescue # part
|
98
|
-
|
93
|
+
I18n.t('part', chapter.number)
|
99
94
|
end
|
100
95
|
|
101
96
|
def title(id)
|
@@ -105,35 +100,32 @@ module ReVIEW
|
|
105
100
|
end
|
106
101
|
|
107
102
|
def display_string(id)
|
108
|
-
"#{number(id)}#{I18n.t(
|
103
|
+
"#{number(id)}#{I18n.t('chapter_quote', title(id))}"
|
109
104
|
end
|
110
105
|
end
|
111
106
|
|
112
|
-
|
113
107
|
class ListIndex < Index
|
114
|
-
def
|
108
|
+
def self.item_type
|
115
109
|
'(list|listnum)'
|
116
110
|
end
|
117
111
|
end
|
118
112
|
|
119
|
-
|
120
113
|
class TableIndex < Index
|
121
|
-
def
|
114
|
+
def self.item_type
|
122
115
|
'(table|imgtable)'
|
123
116
|
end
|
124
117
|
end
|
125
118
|
|
126
|
-
|
127
119
|
class FootnoteIndex < Index
|
128
120
|
Item = Struct.new(:id, :number, :content)
|
129
121
|
|
130
|
-
def
|
122
|
+
def self.parse(src)
|
131
123
|
items = []
|
132
124
|
seq = 1
|
133
|
-
src.grep(%r
|
125
|
+
src.grep(%r{\A//footnote}) do |line|
|
134
126
|
if m = /\[(.*?)\]\[(.*)\]/.match(line)
|
135
|
-
m1 = m[1].gsub(/\\(\])/){$1}
|
136
|
-
m2 = m[2].gsub(/\\(\])/){$1}
|
127
|
+
m1 = m[1].gsub(/\\(\])/) { $1 }
|
128
|
+
m2 = m[2].gsub(/\\(\])/) { $1 }
|
137
129
|
items.push Item.new(m1, seq, m2)
|
138
130
|
end
|
139
131
|
seq += 1
|
@@ -142,31 +134,31 @@ module ReVIEW
|
|
142
134
|
end
|
143
135
|
end
|
144
136
|
|
145
|
-
|
146
137
|
class ImageIndex < Index
|
147
138
|
def self.parse(src, *args)
|
148
139
|
items = []
|
149
140
|
seq = 1
|
150
|
-
src.grep(%r
|
141
|
+
src.grep(%r{\A//#{item_type}}) do |line|
|
151
142
|
# ex. ["//image", "id", "", "caption"]
|
152
143
|
elements = line.split(/\[(.*?)\]/)
|
153
144
|
if elements[1].present?
|
154
|
-
if line =~ %r{
|
155
|
-
items.push item_class
|
156
|
-
else ## %r
|
157
|
-
items.push item_class
|
145
|
+
if line =~ %r{\A//imgtable}
|
146
|
+
items.push item_class.new(elements[1], 0, elements[3])
|
147
|
+
else ## %r<\A//(image|graph)>
|
148
|
+
items.push item_class.new(elements[1], seq, elements[3])
|
158
149
|
seq += 1
|
159
150
|
end
|
160
|
-
if elements[1] ==
|
161
|
-
warn "warning: no ID of #{item_type()} in #{line}"
|
162
|
-
end
|
151
|
+
ReVIEW.logger.warn "warning: no ID of #{item_type} in #{line}" if elements[1] == ''
|
163
152
|
end
|
164
153
|
end
|
165
154
|
new(items, *args)
|
166
155
|
end
|
167
156
|
|
168
|
-
|
157
|
+
def self.item_type
|
158
|
+
'(image|graph|imgtable)'
|
159
|
+
end
|
169
160
|
|
161
|
+
class Item
|
170
162
|
def initialize(id, number, caption = nil)
|
171
163
|
@id = id
|
172
164
|
@number = number
|
@@ -188,10 +180,6 @@ module ReVIEW
|
|
188
180
|
end
|
189
181
|
end
|
190
182
|
|
191
|
-
def ImageIndex.item_type
|
192
|
-
'(image|graph|imgtable)'
|
193
|
-
end
|
194
|
-
|
195
183
|
attr_reader :image_finder
|
196
184
|
|
197
185
|
def initialize(items, chapid, basedir, types, builder)
|
@@ -203,8 +191,7 @@ module ReVIEW
|
|
203
191
|
@basedir = basedir
|
204
192
|
@types = types
|
205
193
|
|
206
|
-
@image_finder = ReVIEW::Book::ImageFinder.new(basedir, chapid,
|
207
|
-
builder, types)
|
194
|
+
@image_finder = ReVIEW::Book::ImageFinder.new(basedir, chapid, builder, types)
|
208
195
|
end
|
209
196
|
|
210
197
|
def find_path(id)
|
@@ -216,13 +203,8 @@ module ReVIEW
|
|
216
203
|
def initialize(items, chapid, basedir, types, builder)
|
217
204
|
@items = items
|
218
205
|
@index = {}
|
219
|
-
items.each
|
220
|
-
|
221
|
-
@index[i.id] = i
|
222
|
-
end
|
223
|
-
items.each do |i|
|
224
|
-
i.index = self
|
225
|
-
end
|
206
|
+
items.each { |i| @index[i.id] = i }
|
207
|
+
items.each { |i| i.index = self }
|
226
208
|
@chapid = chapid
|
227
209
|
@basedir = basedir
|
228
210
|
@types = types
|
@@ -230,12 +212,12 @@ module ReVIEW
|
|
230
212
|
@image_finder = ImageFinder.new(basedir, chapid, builder, types)
|
231
213
|
end
|
232
214
|
|
233
|
-
def
|
215
|
+
def self.parse(src, *args)
|
234
216
|
items = []
|
235
217
|
seq = 1
|
236
|
-
src.grep(
|
237
|
-
line.gsub(/@<icon>\{(.+?)\}/) do
|
238
|
-
items.push item_class
|
218
|
+
src.grep(/@<icon>/) do |line|
|
219
|
+
line.gsub(/@<icon>\{(.+?)\}/) do
|
220
|
+
items.push item_class.new($1, seq)
|
239
221
|
seq += 1
|
240
222
|
end
|
241
223
|
end
|
@@ -246,13 +228,13 @@ module ReVIEW
|
|
246
228
|
class BibpaperIndex < Index
|
247
229
|
Item = Struct.new(:id, :number, :caption)
|
248
230
|
|
249
|
-
def
|
231
|
+
def self.parse(src)
|
250
232
|
items = []
|
251
233
|
seq = 1
|
252
|
-
src.grep(%r
|
234
|
+
src.grep(%r{\A//bibpaper}) do |line|
|
253
235
|
if m = /\[(.*?)\]\[(.*)\]/.match(line)
|
254
|
-
m1 = m[1].gsub(/\\(.)/){$1}
|
255
|
-
m2 = m[2].gsub(/\\(.)/){$1}
|
236
|
+
m1 = m[1].gsub(/\\(.)/) { $1 }
|
237
|
+
m2 = m[2].gsub(/\\(.)/) { $1 }
|
256
238
|
items.push Item.new(m1, seq, m2)
|
257
239
|
end
|
258
240
|
seq += 1
|
@@ -262,15 +244,15 @@ module ReVIEW
|
|
262
244
|
end
|
263
245
|
|
264
246
|
class NumberlessImageIndex < ImageIndex
|
265
|
-
|
247
|
+
def self.item_type
|
248
|
+
'numberlessimage'
|
266
249
|
end
|
267
250
|
|
268
|
-
|
269
|
-
'numberlessimage'
|
251
|
+
class Item < ImageIndex::Item
|
270
252
|
end
|
271
253
|
|
272
|
-
def number(
|
273
|
-
|
254
|
+
def number(_id)
|
255
|
+
''
|
274
256
|
end
|
275
257
|
end
|
276
258
|
|
@@ -278,12 +260,12 @@ module ReVIEW
|
|
278
260
|
class Item < ImageIndex::Item
|
279
261
|
end
|
280
262
|
|
281
|
-
def
|
263
|
+
def self.item_type
|
282
264
|
'(indepimage|imgtable)'
|
283
265
|
end
|
284
266
|
|
285
|
-
def number(
|
286
|
-
|
267
|
+
def number(_id)
|
268
|
+
''
|
287
269
|
end
|
288
270
|
end
|
289
271
|
|
@@ -292,45 +274,48 @@ module ReVIEW
|
|
292
274
|
Item = Struct.new(:id, :number, :caption)
|
293
275
|
attr_reader :items
|
294
276
|
|
295
|
-
def
|
277
|
+
def self.parse(src, chap)
|
296
278
|
items = []
|
297
279
|
indexs = []
|
298
280
|
headlines = []
|
299
281
|
inside_column = false
|
282
|
+
inside_block = nil
|
300
283
|
src.each do |line|
|
301
|
-
if
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
if m[2] == '/column'
|
311
|
-
inside_column = false
|
312
|
-
next
|
313
|
-
end
|
314
|
-
if indexs.blank? || index <= indexs[-1]
|
315
|
-
inside_column = false
|
316
|
-
end
|
317
|
-
if inside_column
|
318
|
-
next
|
319
|
-
end
|
284
|
+
if line =~ %r{\A//[a-z]+.*\{\Z}
|
285
|
+
inside_block = true
|
286
|
+
next
|
287
|
+
elsif line =~ %r{\A//\}}
|
288
|
+
inside_block = nil
|
289
|
+
next
|
290
|
+
elsif inside_block
|
291
|
+
next
|
292
|
+
end
|
320
293
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
294
|
+
m = HEADLINE_PATTERN.match(line)
|
295
|
+
next if m.nil? || m[1].size > 10 # Ignore too deep index
|
296
|
+
next if m[4].strip.empty? # no title
|
297
|
+
index = m[1].size - 2
|
298
|
+
|
299
|
+
# column
|
300
|
+
if m[2] == 'column'
|
301
|
+
inside_column = true
|
302
|
+
next
|
303
|
+
elsif m[2] == '/column'
|
304
|
+
inside_column = false
|
305
|
+
next
|
306
|
+
end
|
307
|
+
inside_column = false if indexs.blank? || index <= indexs[-1]
|
308
|
+
next if inside_column
|
309
|
+
|
310
|
+
next unless index >= 0
|
311
|
+
if indexs.size > (index + 1)
|
312
|
+
indexs = indexs.take(index + 1)
|
313
|
+
headlines = headlines.take(index + 1)
|
333
314
|
end
|
315
|
+
(0..index).each { |i| indexs[i] = 0 if indexs[i].nil? } if indexs[index].nil?
|
316
|
+
indexs[index] += 1
|
317
|
+
headlines[index] = m[3].present? ? m[3].strip : m[4].strip
|
318
|
+
items.push Item.new(headlines.join('|'), indexs.dup, m[4].strip)
|
334
319
|
end
|
335
320
|
new(items, chap)
|
336
321
|
end
|
@@ -340,17 +325,15 @@ module ReVIEW
|
|
340
325
|
@chap = chap
|
341
326
|
@index = {}
|
342
327
|
items.each do |i|
|
343
|
-
warn "warning: duplicate ID: #{i.id}"
|
328
|
+
@logger.warn "warning: duplicate ID: #{i.id}" if @index[i.id]
|
344
329
|
@index[i.id] = i
|
345
330
|
end
|
346
331
|
end
|
347
332
|
|
348
333
|
def number(id)
|
349
334
|
n = @chap.number
|
350
|
-
if @chap.
|
351
|
-
|
352
|
-
end
|
353
|
-
return ([n] + self[id].number).join(".")
|
335
|
+
n = @chap.format_number(false) if @chap.on_appendix? && @chap.number > 0 && @chap.number < 28
|
336
|
+
([n] + self[id].number).join('.')
|
354
337
|
end
|
355
338
|
end
|
356
339
|
|
@@ -358,26 +341,22 @@ module ReVIEW
|
|
358
341
|
COLUMN_PATTERN = /\A(=+)\[column\](?:\{(.+?)\})?(.*)/
|
359
342
|
Item = Struct.new(:id, :number, :caption)
|
360
343
|
|
361
|
-
def
|
344
|
+
def self.parse(src, *_args)
|
362
345
|
items = []
|
363
346
|
seq = 1
|
364
347
|
src.each do |line|
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
seq += 1
|
375
|
-
end
|
348
|
+
m = COLUMN_PATTERN.match(line)
|
349
|
+
next unless m
|
350
|
+
_level = m[1] ## not use it yet
|
351
|
+
id = m[2]
|
352
|
+
caption = m[3].strip
|
353
|
+
id = caption if id.nil? || id.empty?
|
354
|
+
|
355
|
+
items.push item_class.new(id, seq, caption)
|
356
|
+
seq += 1
|
376
357
|
end
|
377
358
|
new(items)
|
378
359
|
end
|
379
|
-
|
380
360
|
end
|
381
|
-
|
382
361
|
end
|
383
362
|
end
|