tmtms-review 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +9 -0
- data/COPYING +515 -0
- data/ChangeLog +2083 -0
- data/README.rdoc +50 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/bin/review-check +178 -0
- data/bin/review-checkdep +63 -0
- data/bin/review-compile +205 -0
- data/bin/review-epubmaker +661 -0
- data/bin/review-epubmaker-ng +176 -0
- data/bin/review-index +118 -0
- data/bin/review-pdfmaker +208 -0
- data/bin/review-preproc +142 -0
- data/bin/review-validate +51 -0
- data/bin/review-vol +102 -0
- data/debian/README.Debian +12 -0
- data/debian/README.source +5 -0
- data/debian/changelog +5 -0
- data/debian/compat +1 -0
- data/debian/control +22 -0
- data/debian/copyright +62 -0
- data/debian/docs +6 -0
- data/debian/manpage.1.ex +59 -0
- data/debian/patches/path.diff +91 -0
- data/debian/patches/series +1 -0
- data/debian/review.install +13 -0
- data/debian/review.links +4 -0
- data/debian/rules +13 -0
- data/debian/source/format +1 -0
- data/doc/format.rdoc +582 -0
- data/doc/format_idg.rdoc +180 -0
- data/doc/libepubmaker/sample.yaml +90 -0
- data/doc/quickstart.rdoc +188 -0
- data/doc/ruby-uuid/README +11 -0
- data/doc/ruby-uuid/README.ja +34 -0
- data/doc/sample.css +108 -0
- data/doc/sample.yaml +62 -0
- data/lib/epubmaker.rb +28 -0
- data/lib/epubmaker/content.rb +82 -0
- data/lib/epubmaker/epubv2.rb +418 -0
- data/lib/epubmaker/epubv3.rb +249 -0
- data/lib/epubmaker/producer.rb +204 -0
- data/lib/epubmaker/resource.rb +66 -0
- data/lib/lineinput.rb +155 -0
- data/lib/review.rb +3 -0
- data/lib/review/book.rb +46 -0
- data/lib/review/book/base.rb +235 -0
- data/lib/review/book/chapter.rb +81 -0
- data/lib/review/book/compilable.rb +159 -0
- data/lib/review/book/index.rb +339 -0
- data/lib/review/book/page_metric.rb +38 -0
- data/lib/review/book/parameters.rb +97 -0
- data/lib/review/book/part.rb +44 -0
- data/lib/review/book/volume.rb +65 -0
- data/lib/review/builder.rb +444 -0
- data/lib/review/compiler.rb +550 -0
- data/lib/review/configure.rb +38 -0
- data/lib/review/epubbuilder.rb +18 -0
- data/lib/review/exception.rb +21 -0
- data/lib/review/extentions.rb +3 -0
- data/lib/review/extentions/object.rb +9 -0
- data/lib/review/extentions/string.rb +33 -0
- data/lib/review/htmlbuilder.rb +1097 -0
- data/lib/review/htmllayout.rb +19 -0
- data/lib/review/htmlutils.rb +36 -0
- data/lib/review/i18n.rb +30 -0
- data/lib/review/i18n.yaml +34 -0
- data/lib/review/idgxmlbuilder.rb +1145 -0
- data/lib/review/latexbuilder.rb +815 -0
- data/lib/review/latexindex.rb +35 -0
- data/lib/review/latexutils.rb +79 -0
- data/lib/review/preprocessor.rb +563 -0
- data/lib/review/review.tex.erb +232 -0
- data/lib/review/textbuilder.rb +17 -0
- data/lib/review/textutils.rb +66 -0
- data/lib/review/tocparser.rb +342 -0
- data/lib/review/tocprinter.rb +221 -0
- data/lib/review/topbuilder.rb +785 -0
- data/lib/review/unfold.rb +138 -0
- data/lib/uuid.rb +312 -0
- data/review.gemspec +141 -0
- data/test/CHAPS +2 -0
- data/test/bib.re +13 -0
- data/test/book_test_helper.rb +35 -0
- data/test/test.re +43 -0
- data/test/test_book.rb +598 -0
- data/test/test_book_chapter.rb +418 -0
- data/test/test_book_parameter.rb +42 -0
- data/test/test_book_part.rb +50 -0
- data/test/test_builder.rb +144 -0
- data/test/test_compiler.rb +44 -0
- data/test/test_epubmaker.rb +507 -0
- data/test/test_helper.rb +27 -0
- data/test/test_htmlbuilder.rb +554 -0
- data/test/test_htmlutils.rb +28 -0
- data/test/test_i18n.rb +64 -0
- data/test/test_idgxmlbuilder.rb +589 -0
- data/test/test_index.rb +31 -0
- data/test/test_latexbuilder.rb +656 -0
- data/test/test_lineinput.rb +198 -0
- data/test/test_preprocessor.rb +23 -0
- data/test/test_textutils.rb +68 -0
- data/test/test_topbuilder.rb +244 -0
- data/test/test_uuid.rb +156 -0
- metadata +161 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
#
|
2
|
+
# $Id: book.rb 4315 2009-09-02 04:15:24Z kmuto $
|
3
|
+
#
|
4
|
+
# Copyright (c) 2002-2008 Minero Aoki
|
5
|
+
# 2009 Minero Aoki, Kenshi Muto
|
6
|
+
#
|
7
|
+
# This program is free software.
|
8
|
+
# You can distribute or modify this program under the terms of
|
9
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
10
|
+
# For details of the GNU LGPL, see the file "COPYING".
|
11
|
+
#
|
12
|
+
require 'review/book/compilable'
|
13
|
+
module ReVIEW
|
14
|
+
module Book
|
15
|
+
class Chapter
|
16
|
+
include Compilable
|
17
|
+
|
18
|
+
def Chapter.intern_pathes(pathes)
|
19
|
+
books = {}
|
20
|
+
pathes.map {|path|
|
21
|
+
basedir = File.dirname(path)
|
22
|
+
book = (books[File.expand_path(basedir)] ||= Book.load(basedir))
|
23
|
+
begin
|
24
|
+
book.chapter(File.basename(path, '.*'))
|
25
|
+
rescue KeyError => err
|
26
|
+
raise FileNotFound, "no such file: #{path}"
|
27
|
+
end
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def Chapter.for_stdin
|
32
|
+
new(nil, nil, '-', nil, $stdin)
|
33
|
+
end
|
34
|
+
|
35
|
+
def Chapter.for_path(number, path)
|
36
|
+
new(nil, number, File.basename(path), path)
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_reader :number
|
40
|
+
|
41
|
+
def initialize(book, number, name, path, io = nil)
|
42
|
+
@book = book
|
43
|
+
@number = number
|
44
|
+
@name = name
|
45
|
+
@path = path
|
46
|
+
@io = io
|
47
|
+
@title = nil
|
48
|
+
@content = nil
|
49
|
+
@list_index = nil
|
50
|
+
@table_index = nil
|
51
|
+
@footnote_index = nil
|
52
|
+
@image_index = nil
|
53
|
+
@icon_index = nil
|
54
|
+
@numberless_image_index = nil
|
55
|
+
@indepimage_index = nil
|
56
|
+
@headline_index = nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def inspect
|
60
|
+
"\#<#{self.class} #{@number} #{@path}>"
|
61
|
+
end
|
62
|
+
|
63
|
+
def on_CHAPS?
|
64
|
+
on_FILE?(@book.read_CHAPS())
|
65
|
+
end
|
66
|
+
|
67
|
+
def on_PREDEF?
|
68
|
+
on_FILE?(@book.read_PREDEF())
|
69
|
+
end
|
70
|
+
|
71
|
+
def on_POSTDEF?
|
72
|
+
on_FILE?(@book.read_POSTDEF())
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
def on_FILE?(contents)
|
77
|
+
contents.lines.map(&:strip).include?(id() + @book.ext())
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
#
|
2
|
+
# $Id: book.rb 4315 2009-09-02 04:15:24Z kmuto $
|
3
|
+
#
|
4
|
+
# Copyright (c) 2002-2008 Minero Aoki
|
5
|
+
# 2009 Minero Aoki, Kenshi Muto
|
6
|
+
#
|
7
|
+
# This program is free software.
|
8
|
+
# You can distribute or modify this program under the terms of
|
9
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
10
|
+
# For details of the GNU LGPL, see the file "COPYING".
|
11
|
+
#
|
12
|
+
require 'review/textutils'
|
13
|
+
module ReVIEW
|
14
|
+
module Book
|
15
|
+
module Compilable
|
16
|
+
include TextUtils
|
17
|
+
attr_reader :book
|
18
|
+
attr_reader :path
|
19
|
+
|
20
|
+
def env
|
21
|
+
@book
|
22
|
+
end
|
23
|
+
|
24
|
+
def dirname
|
25
|
+
return nil unless @path
|
26
|
+
File.dirname(@path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def basename
|
30
|
+
return nil unless @path
|
31
|
+
File.basename(@path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def name
|
35
|
+
File.basename(@name, '.*')
|
36
|
+
end
|
37
|
+
|
38
|
+
alias id name
|
39
|
+
|
40
|
+
def title
|
41
|
+
@title = ""
|
42
|
+
open {|f|
|
43
|
+
f.each_line {|l|
|
44
|
+
l = convert_inencoding(l, ReVIEW.book.param["inencoding"])
|
45
|
+
if l =~ /\A=+/
|
46
|
+
@title = l.sub(/\A=+/, '').strip
|
47
|
+
break
|
48
|
+
end
|
49
|
+
}
|
50
|
+
}
|
51
|
+
@title
|
52
|
+
end
|
53
|
+
|
54
|
+
def size
|
55
|
+
File.size(path())
|
56
|
+
end
|
57
|
+
|
58
|
+
def volume
|
59
|
+
@volume ||= Volume.count_file(path())
|
60
|
+
end
|
61
|
+
|
62
|
+
def open(&block)
|
63
|
+
return (block_given?() ? yield(@io) : @io) if @io
|
64
|
+
File.open(path(), &block)
|
65
|
+
end
|
66
|
+
|
67
|
+
def content
|
68
|
+
@content = convert_inencoding(File.read(path()),
|
69
|
+
ReVIEW.book.param["inencoding"])
|
70
|
+
end
|
71
|
+
|
72
|
+
def lines
|
73
|
+
# FIXME: we cannot duplicate Enumerator on ruby 1.9 HEAD
|
74
|
+
(@lines ||= content().lines.to_a).dup
|
75
|
+
end
|
76
|
+
|
77
|
+
def list(id)
|
78
|
+
list_index()[id]
|
79
|
+
end
|
80
|
+
|
81
|
+
def list_index
|
82
|
+
@list_index ||= ListIndex.parse(lines())
|
83
|
+
@list_index
|
84
|
+
end
|
85
|
+
|
86
|
+
def table(id)
|
87
|
+
table_index()[id]
|
88
|
+
end
|
89
|
+
|
90
|
+
def table_index
|
91
|
+
@table_index ||= TableIndex.parse(lines())
|
92
|
+
@table_index
|
93
|
+
end
|
94
|
+
|
95
|
+
def footnote(id)
|
96
|
+
footnote_index()[id]
|
97
|
+
end
|
98
|
+
|
99
|
+
def footnote_index
|
100
|
+
@footnote_index ||= FootnoteIndex.parse(lines())
|
101
|
+
@footnote_index
|
102
|
+
end
|
103
|
+
|
104
|
+
def image(id)
|
105
|
+
return image_index()[id] if image_index().has_key?(id)
|
106
|
+
return icon_index()[id] if icon_index().has_key?(id)
|
107
|
+
return numberless_image_index()[id] if numberless_image_index().has_key?(id)
|
108
|
+
indepimage_index()[id]
|
109
|
+
end
|
110
|
+
|
111
|
+
def numberless_image_index
|
112
|
+
@numberless_image_index ||=
|
113
|
+
NumberlessImageIndex.parse(lines(), id(),
|
114
|
+
"#{book.basedir}#{@book.image_dir}",
|
115
|
+
@book.image_types)
|
116
|
+
end
|
117
|
+
|
118
|
+
def image_index
|
119
|
+
@image_index ||= ImageIndex.parse(lines(), id(),
|
120
|
+
"#{book.basedir}#{@book.image_dir}",
|
121
|
+
@book.image_types)
|
122
|
+
@image_index
|
123
|
+
end
|
124
|
+
|
125
|
+
def icon_index
|
126
|
+
@icon_index ||= IconIndex.parse(lines(), id(),
|
127
|
+
"#{book.basedir}#{@book.image_dir}",
|
128
|
+
@book.image_types)
|
129
|
+
@icon_index
|
130
|
+
end
|
131
|
+
|
132
|
+
def indepimage_index
|
133
|
+
@indepimage_index ||=
|
134
|
+
IndepImageIndex.parse(lines(), id(),
|
135
|
+
"#{book.basedir}#{@book.image_dir}",
|
136
|
+
@book.image_types)
|
137
|
+
end
|
138
|
+
|
139
|
+
def bibpaper(id)
|
140
|
+
bibpaper_index()[id]
|
141
|
+
end
|
142
|
+
|
143
|
+
def bibpaper_index
|
144
|
+
raise FileNotFound, "no such bib file: #{@book.bib_file}" unless @book.bib_exist?
|
145
|
+
@bibpaper_index ||= BibpaperIndex.parse(@book.read_bib.lines.to_a)
|
146
|
+
@bibpaper_index
|
147
|
+
end
|
148
|
+
|
149
|
+
def headline(caption)
|
150
|
+
headline_index()[caption]
|
151
|
+
end
|
152
|
+
|
153
|
+
def headline_index
|
154
|
+
@headline_index ||= HeadlineIndex.parse(lines(), self)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
@@ -0,0 +1,339 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright (c) 2002-2007 Minero Aoki
|
4
|
+
# 2008-2009 Minero Aoki, Kenshi Muto
|
5
|
+
#
|
6
|
+
# This program is free software.
|
7
|
+
# You can distribute or modify this program under the terms of
|
8
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
9
|
+
# For details of LGPL, see the file "COPYING".
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'review/extentions'
|
13
|
+
require 'review/exception'
|
14
|
+
|
15
|
+
module ReVIEW
|
16
|
+
module Book
|
17
|
+
class Index
|
18
|
+
def Index.parse(src, *args)
|
19
|
+
items = []
|
20
|
+
seq = 1
|
21
|
+
src.grep(%r<^//#{item_type()}>) do |line|
|
22
|
+
if id = line.slice(/\[(.*?)\]/, 1)
|
23
|
+
items.push item_class().new(id, seq)
|
24
|
+
seq += 1
|
25
|
+
if id == ""
|
26
|
+
warn "warning: no ID of #{item_type()} in #{line}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
new(items, *args)
|
31
|
+
end
|
32
|
+
|
33
|
+
Item = Struct.new(:id, :number)
|
34
|
+
|
35
|
+
def Index.item_class
|
36
|
+
self::Item
|
37
|
+
end
|
38
|
+
|
39
|
+
include Enumerable
|
40
|
+
|
41
|
+
def item_type
|
42
|
+
self.class.item_type
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize(items)
|
46
|
+
@items = items
|
47
|
+
@index = {}
|
48
|
+
items.each do |i|
|
49
|
+
warn "warning: duplicate ID: #{i.id} (#{i})" unless @index[i.id].nil?
|
50
|
+
@index[i.id] = i
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def [](id)
|
55
|
+
@index.fetch(id)
|
56
|
+
rescue
|
57
|
+
raise KeyError
|
58
|
+
end
|
59
|
+
|
60
|
+
def number(id)
|
61
|
+
@index.fetch(id).number.to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
def each(&block)
|
65
|
+
@items.each(&block)
|
66
|
+
end
|
67
|
+
|
68
|
+
def has_key?(id)
|
69
|
+
return @index.has_key?(id)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
class ChapterIndex < Index
|
75
|
+
def item_type
|
76
|
+
'chapter'
|
77
|
+
end
|
78
|
+
|
79
|
+
def number(id)
|
80
|
+
chapter = @index.fetch(id)
|
81
|
+
if chapter.on_CHAPS?
|
82
|
+
"#{I18n.t("chapter", chapter.number)}"
|
83
|
+
elsif chapter.on_PREDEF?
|
84
|
+
"#{chapter.number}"
|
85
|
+
elsif chapter.on_POSTDEF?
|
86
|
+
"#{I18n.t("appendix", chapter.number)}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def title(id)
|
91
|
+
@index.fetch(id).title
|
92
|
+
end
|
93
|
+
|
94
|
+
def display_string(id)
|
95
|
+
"#{number(id)}「#{title(id)}」"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
class ListIndex < Index
|
101
|
+
def ListIndex.item_type
|
102
|
+
'(list|listnum)'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
class TableIndex < Index
|
108
|
+
def TableIndex.item_type
|
109
|
+
'table'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
class FootnoteIndex < Index
|
115
|
+
Item = Struct.new(:id, :number, :content)
|
116
|
+
|
117
|
+
def FootnoteIndex.parse(src)
|
118
|
+
items = []
|
119
|
+
seq = 1
|
120
|
+
src.grep(%r<^//footnote>) do |line|
|
121
|
+
if m = /\[(.*?)\]\[(.*)\]/.match(line)
|
122
|
+
m1 = m[1].gsub(/\\(\])/){$1}
|
123
|
+
m2 = m[2].gsub(/\\(\])/){$1}
|
124
|
+
items.push Item.new(m1, seq, m2)
|
125
|
+
end
|
126
|
+
seq += 1
|
127
|
+
end
|
128
|
+
new(items)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
class ImageIndex < Index
|
134
|
+
class Item
|
135
|
+
def initialize(id, number)
|
136
|
+
@id = id
|
137
|
+
@number = number
|
138
|
+
@pathes = nil
|
139
|
+
end
|
140
|
+
|
141
|
+
attr_reader :id
|
142
|
+
attr_reader :number
|
143
|
+
attr_writer :index # internal use only
|
144
|
+
|
145
|
+
def bound?
|
146
|
+
not pathes().empty?
|
147
|
+
end
|
148
|
+
|
149
|
+
def path
|
150
|
+
pathes().first
|
151
|
+
end
|
152
|
+
|
153
|
+
def pathes
|
154
|
+
@pathes ||= @index.find_pathes(id)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def ImageIndex.item_type
|
159
|
+
'(image|graph)'
|
160
|
+
end
|
161
|
+
|
162
|
+
def initialize(items, chapid, basedir, types)
|
163
|
+
super items
|
164
|
+
items.each do |i|
|
165
|
+
i.index = self
|
166
|
+
end
|
167
|
+
@chapid = chapid
|
168
|
+
@basedir = basedir
|
169
|
+
@types = types
|
170
|
+
end
|
171
|
+
|
172
|
+
# internal use only
|
173
|
+
def find_pathes(id)
|
174
|
+
if ReVIEW.book.param["subdirmode"]
|
175
|
+
re = /\A#{id}(?i:#{@types.join('|')})\z/x
|
176
|
+
entries().select {|ent| re =~ ent }\
|
177
|
+
.sort_by {|ent| @types.index(File.extname(ent).downcase) }\
|
178
|
+
.map {|ent| "#{@basedir}/#{@chapid}/#{ent}" }
|
179
|
+
elsif ReVIEW.book.param["singledirmode"]
|
180
|
+
re = /\A#{id}(?i:#{@types.join('|')})\z/x
|
181
|
+
entries().select {|ent| re =~ ent }\
|
182
|
+
.sort_by {|ent| @types.index(File.extname(ent).downcase) }\
|
183
|
+
.map {|ent| "#{@basedir}/#{ent}" }
|
184
|
+
else
|
185
|
+
re = /\A#{@chapid.gsub('+', '\\\+').gsub('-', '\\\-')}-#{id}(?i:#{@types.join('|')})\z/x
|
186
|
+
entries().select {|ent| re =~ ent }\
|
187
|
+
.sort_by {|ent| @types.index(File.extname(ent).downcase) }\
|
188
|
+
.map {|ent| "#{@basedir}/#{ent}" }
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
private
|
193
|
+
|
194
|
+
def entries
|
195
|
+
# @entries: do not cache for graph
|
196
|
+
if ReVIEW.book.param["subdirmode"]
|
197
|
+
@entries = Dir.entries(File.join(@basedir, @chapid))
|
198
|
+
else
|
199
|
+
@entries = Dir.entries(@basedir)
|
200
|
+
end
|
201
|
+
rescue Errno::ENOENT
|
202
|
+
@entries = []
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
class IconIndex < ImageIndex
|
207
|
+
def IconIndex.parse(src, *args)
|
208
|
+
items = []
|
209
|
+
seq = 1
|
210
|
+
src.grep(%r!@<icon>!) do |line|
|
211
|
+
line.gsub(/@<icon>\{(.+?)\}/) do |m|
|
212
|
+
items.push item_class().new($1, seq)
|
213
|
+
seq += 1
|
214
|
+
end
|
215
|
+
end
|
216
|
+
new(items, *args)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
class FormatRef
|
221
|
+
def initialize(locale, index)
|
222
|
+
@locale = locale
|
223
|
+
@index = index
|
224
|
+
end
|
225
|
+
|
226
|
+
def title(id)
|
227
|
+
sprintf(@locale["#{@index.item_type}_caption_format".intern],
|
228
|
+
@index.title(id))
|
229
|
+
end
|
230
|
+
|
231
|
+
def number(id)
|
232
|
+
sprintf(@locale["#{@index.item_type}_number_format".intern],
|
233
|
+
@index.number(id))
|
234
|
+
end
|
235
|
+
|
236
|
+
def method_missing(mid, *args, &block)
|
237
|
+
super unless @index.respond_to?(mid)
|
238
|
+
@index.__send__(mid, *args, &block)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
class BibpaperIndex < Index
|
243
|
+
Item = Struct.new(:id, :number, :caption)
|
244
|
+
|
245
|
+
def BibpaperIndex.parse(src)
|
246
|
+
items = []
|
247
|
+
seq = 1
|
248
|
+
src.grep(%r<^//bibpaper>) do |line|
|
249
|
+
if m = /\[(.*?)\]\[(.*)\]/.match(line)
|
250
|
+
m1 = m[1].gsub(/\\(.)/){$1}
|
251
|
+
m2 = m[2].gsub(/\\(.)/){$1}
|
252
|
+
items.push Item.new(m1, seq, m2)
|
253
|
+
end
|
254
|
+
seq += 1
|
255
|
+
end
|
256
|
+
new(items)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
class NumberlessImageIndex < ImageIndex
|
261
|
+
class Item < ImageIndex::Item
|
262
|
+
def initialize(id, number)
|
263
|
+
@id = id
|
264
|
+
@number = ""
|
265
|
+
@pathes = nil
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
def NumberlessImageIndex.item_type
|
270
|
+
'numberlessimage'
|
271
|
+
end
|
272
|
+
|
273
|
+
def number(id)
|
274
|
+
""
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
class IndepImageIndex < ImageIndex
|
279
|
+
class Item < ImageIndex::Item
|
280
|
+
def initialize(id, number)
|
281
|
+
@id = id
|
282
|
+
@number = ""
|
283
|
+
@pathes = nil
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
def IndepImageIndex.item_type
|
288
|
+
'indepimage'
|
289
|
+
end
|
290
|
+
|
291
|
+
def number(id)
|
292
|
+
""
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
class HeadlineIndex < Index
|
297
|
+
Item = Struct.new(:id, :number, :caption)
|
298
|
+
|
299
|
+
def HeadlineIndex.parse(src, chap)
|
300
|
+
items = []
|
301
|
+
indexs = []
|
302
|
+
headlines = []
|
303
|
+
src.each do |line|
|
304
|
+
if m = /\A(=+)(?:\[(.+?)\])?(?:\{(.+?)\})?(.*)/.match(line)
|
305
|
+
next if m[2] == 'column'
|
306
|
+
index = m[1].size - 2
|
307
|
+
if index >= 0
|
308
|
+
if indexs.size > (index + 1)
|
309
|
+
indexs = indexs.take(index + 1)
|
310
|
+
headlines = headlines.take(index + 1)
|
311
|
+
end
|
312
|
+
if indexs[index].nil?
|
313
|
+
(0..index).each{|i| indexs[i] = 0 if indexs[i].nil?}
|
314
|
+
end
|
315
|
+
indexs[index] += 1
|
316
|
+
headlines[index] = m[4].strip
|
317
|
+
items.push Item.new(headlines.join("|"), indexs.dup, m[4].strip)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
new(items, chap)
|
322
|
+
end
|
323
|
+
|
324
|
+
def initialize(items, chap)
|
325
|
+
@items = items
|
326
|
+
@chap = chap
|
327
|
+
@index = {}
|
328
|
+
items.each do |i|
|
329
|
+
warn "warning: duplicate ID: #{i.id}" unless @index[i.id].nil?
|
330
|
+
@index[i.id] = i
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
def number(id)
|
335
|
+
return ([@chap.number] + @index.fetch(id).number).join(".")
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|