review 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/.travis.yml +1 -2
  2. data/ChangeLog +65 -0
  3. data/Gemfile +5 -0
  4. data/README.rdoc +6 -1
  5. data/Rakefile +14 -28
  6. data/bin/review-check +9 -21
  7. data/bin/review-compile +45 -12
  8. data/bin/review-epubmaker +477 -220
  9. data/bin/review-epubmaker-ng +5 -14
  10. data/bin/review-index +4 -2
  11. data/bin/review-init +94 -0
  12. data/bin/review-pdfmaker +70 -287
  13. data/bin/review-preproc +5 -2
  14. data/bin/review-vol +4 -11
  15. data/debian/changelog +3 -3
  16. data/debian/copyright +5 -3
  17. data/debian/docs +1 -0
  18. data/doc/format.rdoc +57 -11
  19. data/doc/quickstart.rdoc +4 -4
  20. data/doc/sample.yaml +11 -7
  21. data/lib/epubmaker.rb +1 -1
  22. data/lib/epubmaker/epubv2.rb +26 -27
  23. data/lib/epubmaker/epubv3.rb +13 -13
  24. data/lib/epubmaker/producer.rb +1 -1
  25. data/lib/review.rb +3 -4
  26. data/lib/review/book.rb +17 -581
  27. data/lib/review/book/base.rb +247 -0
  28. data/lib/review/book/chapter.rb +81 -0
  29. data/lib/review/book/compilable.rb +163 -0
  30. data/lib/review/book/index.rb +339 -0
  31. data/lib/review/book/page_metric.rb +38 -0
  32. data/lib/review/book/parameters.rb +97 -0
  33. data/lib/review/book/part.rb +44 -0
  34. data/lib/review/book/volume.rb +65 -0
  35. data/lib/review/builder.rb +34 -40
  36. data/lib/review/compiler.rb +32 -13
  37. data/lib/review/configure.rb +38 -0
  38. data/lib/review/ewbbuilder.rb +23 -21
  39. data/lib/review/extentions.rb +3 -0
  40. data/lib/review/extentions/object.rb +9 -0
  41. data/lib/review/{compat.rb → extentions/string.rb} +11 -0
  42. data/lib/review/htmlbuilder.rb +162 -74
  43. data/lib/review/htmlutils.rb +28 -1
  44. data/lib/review/i18n.yaml +11 -0
  45. data/lib/review/idgxmlbuilder.rb +119 -35
  46. data/lib/review/inaobuilder.rb +355 -0
  47. data/lib/review/latexbuilder.rb +133 -59
  48. data/lib/review/latexutils.rb +15 -6
  49. data/lib/review/makerhelper.rb +59 -0
  50. data/lib/review/markdownbuilder.rb +129 -0
  51. data/lib/review/preprocessor.rb +20 -7
  52. data/lib/review/review.tex.erb +250 -0
  53. data/lib/review/textutils.rb +28 -3
  54. data/lib/review/tocparser.rb +20 -12
  55. data/lib/review/tocprinter.rb +7 -3
  56. data/lib/review/topbuilder.rb +44 -27
  57. data/lib/review/version.rb +3 -0
  58. data/review.gemspec +20 -117
  59. data/test/book_test_helper.rb +35 -0
  60. data/test/sample-book/README.md +5 -0
  61. data/test/sample-book/src/CHAPS +2 -0
  62. data/test/sample-book/src/PREDEF +1 -0
  63. data/test/sample-book/src/Rakefile +26 -0
  64. data/test/sample-book/src/_cover.html +3 -0
  65. data/test/sample-book/src/ch01.re +71 -0
  66. data/test/sample-book/src/ch02.re +3 -0
  67. data/test/sample-book/src/config.yml +55 -0
  68. data/test/sample-book/src/images/ch01-imgsample.jpg +0 -0
  69. data/test/sample-book/src/images/cover.jpg +0 -0
  70. data/test/sample-book/src/main.css +251 -0
  71. data/test/sample-book/src/preface.re +15 -0
  72. data/test/sample-book/src/sty/jumoline.sty +310 -0
  73. data/test/sample-book/src/sty/samplemacro.sty +21 -0
  74. data/test/sample-book/src/vendor/jumoline/README +29 -0
  75. data/test/sample-book/src/vendor/jumoline/jumoline.dtx +2988 -0
  76. data/test/sample-book/src/vendor/jumoline/jumoline.ins +6 -0
  77. data/test/test_book.rb +26 -646
  78. data/test/test_book_chapter.rb +418 -0
  79. data/test/test_book_parameter.rb +42 -0
  80. data/test/test_book_part.rb +53 -0
  81. data/test/test_builder.rb +17 -10
  82. data/test/test_compiler.rb +46 -0
  83. data/test/test_epubmaker.rb +1 -1
  84. data/test/test_epubmaker_cmd.rb +36 -0
  85. data/test/test_helper.rb +17 -0
  86. data/test/test_htmlbuilder.rb +156 -24
  87. data/test/test_htmlutils.rb +4 -0
  88. data/test/test_i18n.rb +6 -2
  89. data/test/test_idgxmlbuilder.rb +33 -11
  90. data/test/test_inaobuilder.rb +247 -0
  91. data/test/test_index.rb +31 -0
  92. data/test/test_latexbuilder.rb +115 -35
  93. data/test/test_makerhelper.rb +50 -0
  94. data/test/test_pdfmaker_cmd.rb +36 -0
  95. data/test/test_preprocessor.rb +7 -7
  96. data/test/test_topbuilder.rb +6 -7
  97. data/test/test_uuid.rb +1 -0
  98. metadata +117 -12
  99. data/lib/review/index.rb +0 -323
  100. data/lib/review/volume.rb +0 -66
@@ -4,6 +4,7 @@ require 'test_helper'
4
4
  require 'review/compiler'
5
5
  require 'review/book'
6
6
  require 'review/topbuilder'
7
+ require 'review/i18n'
7
8
 
8
9
  class TOPBuidlerTest < Test::Unit::TestCase
9
10
  include ReVIEW
@@ -18,7 +19,7 @@ class TOPBuidlerTest < Test::Unit::TestCase
18
19
  }
19
20
  ReVIEW.book.param = @param
20
21
  @compiler = ReVIEW::Compiler.new(@builder)
21
- @chapter = Chapter.new(nil, 1, '-', nil, StringIO.new)
22
+ @chapter = Book::Chapter.new(nil, 1, '-', nil, StringIO.new)
22
23
  location = Location.new(nil, nil)
23
24
  @builder.bind(@compiler, @chapter, location)
24
25
 
@@ -128,7 +129,7 @@ class TOPBuidlerTest < Test::Unit::TestCase
128
129
 
129
130
  def test_list
130
131
  def @chapter.list(id)
131
- ListIndex::Item.new("test",1)
132
+ Book::ListIndex::Item.new("test",1)
132
133
  end
133
134
  @builder.list(["foo", "bar"], "test", "this is @<b>{test}<&>_")
134
135
  assert_equal %Q|◆→開始:リスト←◆\nリスト1.1 this is ★test☆<&>_\n\nfoo\nbar\n◆→終了:リスト←◆\n\n|, @builder.raw_result
@@ -136,7 +137,7 @@ class TOPBuidlerTest < Test::Unit::TestCase
136
137
 
137
138
  def test_listnum
138
139
  def @chapter.list(id)
139
- ListIndex::Item.new("test",1)
140
+ Book::ListIndex::Item.new("test",1)
140
141
  end
141
142
  @builder.listnum(["foo", "bar"], "test", "this is @<b>{test}<&>_")
142
143
  assert_equal %Q|◆→開始:リスト←◆\nリスト1.1 this is ★test☆<&>_\n\n 1: foo\n 2: bar\n◆→終了:リスト←◆\n\n|, @builder.raw_result
@@ -149,7 +150,7 @@ class TOPBuidlerTest < Test::Unit::TestCase
149
150
 
150
151
  def test_image
151
152
  def @chapter.image(id)
152
- item = ImageIndex::Item.new("sampleimg",1)
153
+ item = Book::ImageIndex::Item.new("sampleimg",1)
153
154
  item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]}
154
155
  item
155
156
  end
@@ -160,7 +161,7 @@ class TOPBuidlerTest < Test::Unit::TestCase
160
161
 
161
162
  def test_image_with_metric
162
163
  def @chapter.image(id)
163
- item = ImageIndex::Item.new("sampleimg",1)
164
+ item = Book::ImageIndex::Item.new("sampleimg",1)
164
165
  item.instance_eval{@pathes=["./images/chap1-sampleimg.png"]}
165
166
  item
166
167
  end
@@ -201,7 +202,6 @@ class TOPBuidlerTest < Test::Unit::TestCase
201
202
  def test_block_raw0
202
203
  @builder.raw("<>!\"\\n& ")
203
204
  expect =<<-EOS
204
- It is recommended to set builder(s).
205
205
  <>!"
206
206
  &
207
207
  EOS
@@ -236,7 +236,6 @@ EOS
236
236
  def test_block_raw4
237
237
  @builder.raw("|top <>!\"\\n& ")
238
238
  expect =<<-EOS
239
- It is recommended to set builder(s).
240
239
  |top <>!\"
241
240
  &
242
241
  EOS
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: us-ascii
2
3
  #
3
4
  # Original license is below:
4
5
  #
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: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-01-30 00:00:00.000000000 Z
14
- dependencies: []
13
+ date: 2013-03-29 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - '='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.8.7
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - '='
29
+ - !ruby/object:Gem::Version
30
+ version: 0.8.7
15
31
  description: ReVIEW is a digital publishing system for books and ebooks. It supports
16
32
  InDesign, EPUB and LaTeX.
17
33
  email: kmuto@debian.org
@@ -22,6 +38,7 @@ executables:
22
38
  - review-epubmaker
23
39
  - review-epubmaker-ng
24
40
  - review-index
41
+ - review-init
25
42
  - review-pdfmaker
26
43
  - review-preproc
27
44
  - review-validate
@@ -34,6 +51,7 @@ files:
34
51
  - .travis.yml
35
52
  - COPYING
36
53
  - ChangeLog
54
+ - Gemfile
37
55
  - README.rdoc
38
56
  - Rakefile
39
57
  - VERSION
@@ -43,6 +61,7 @@ files:
43
61
  - bin/review-epubmaker
44
62
  - bin/review-epubmaker-ng
45
63
  - bin/review-index
64
+ - bin/review-init
46
65
  - bin/review-pdfmaker
47
66
  - bin/review-preproc
48
67
  - bin/review-validate
@@ -78,51 +97,93 @@ files:
78
97
  - lib/lineinput.rb
79
98
  - lib/review.rb
80
99
  - lib/review/book.rb
100
+ - lib/review/book/base.rb
101
+ - lib/review/book/chapter.rb
102
+ - lib/review/book/compilable.rb
103
+ - lib/review/book/index.rb
104
+ - lib/review/book/page_metric.rb
105
+ - lib/review/book/parameters.rb
106
+ - lib/review/book/part.rb
107
+ - lib/review/book/volume.rb
81
108
  - lib/review/builder.rb
82
- - lib/review/compat.rb
83
109
  - lib/review/compiler.rb
110
+ - lib/review/configure.rb
84
111
  - lib/review/epubbuilder.rb
85
112
  - lib/review/ewbbuilder.rb
86
113
  - lib/review/exception.rb
114
+ - lib/review/extentions.rb
115
+ - lib/review/extentions/object.rb
116
+ - lib/review/extentions/string.rb
87
117
  - lib/review/htmlbuilder.rb
88
118
  - lib/review/htmllayout.rb
89
119
  - lib/review/htmlutils.rb
90
120
  - lib/review/i18n.rb
91
121
  - lib/review/i18n.yaml
92
122
  - lib/review/idgxmlbuilder.rb
93
- - lib/review/index.rb
123
+ - lib/review/inaobuilder.rb
94
124
  - lib/review/latexbuilder.rb
95
125
  - lib/review/latexindex.rb
96
126
  - lib/review/latexutils.rb
127
+ - lib/review/makerhelper.rb
128
+ - lib/review/markdownbuilder.rb
97
129
  - lib/review/preprocessor.rb
130
+ - lib/review/review.tex.erb
98
131
  - lib/review/textbuilder.rb
99
132
  - lib/review/textutils.rb
100
133
  - lib/review/tocparser.rb
101
134
  - lib/review/tocprinter.rb
102
135
  - lib/review/topbuilder.rb
103
136
  - lib/review/unfold.rb
104
- - lib/review/volume.rb
137
+ - lib/review/version.rb
105
138
  - lib/uuid.rb
106
139
  - review.gemspec
107
140
  - test/CHAPS
108
141
  - test/bib.re
142
+ - test/book_test_helper.rb
143
+ - test/sample-book/README.md
144
+ - test/sample-book/src/CHAPS
145
+ - test/sample-book/src/PREDEF
146
+ - test/sample-book/src/Rakefile
147
+ - test/sample-book/src/_cover.html
148
+ - test/sample-book/src/ch01.re
149
+ - test/sample-book/src/ch02.re
150
+ - test/sample-book/src/config.yml
151
+ - test/sample-book/src/images/ch01-imgsample.jpg
152
+ - test/sample-book/src/images/cover.jpg
153
+ - test/sample-book/src/main.css
154
+ - test/sample-book/src/preface.re
155
+ - test/sample-book/src/sty/jumoline.sty
156
+ - test/sample-book/src/sty/samplemacro.sty
157
+ - test/sample-book/src/vendor/jumoline/README
158
+ - test/sample-book/src/vendor/jumoline/jumoline.dtx
159
+ - test/sample-book/src/vendor/jumoline/jumoline.ins
109
160
  - test/test.re
110
161
  - test/test_book.rb
162
+ - test/test_book_chapter.rb
163
+ - test/test_book_parameter.rb
164
+ - test/test_book_part.rb
111
165
  - test/test_builder.rb
166
+ - test/test_compiler.rb
112
167
  - test/test_epubmaker.rb
168
+ - test/test_epubmaker_cmd.rb
113
169
  - test/test_helper.rb
114
170
  - test/test_htmlbuilder.rb
115
171
  - test/test_htmlutils.rb
116
172
  - test/test_i18n.rb
117
173
  - test/test_idgxmlbuilder.rb
174
+ - test/test_inaobuilder.rb
175
+ - test/test_index.rb
118
176
  - test/test_latexbuilder.rb
119
177
  - test/test_lineinput.rb
178
+ - test/test_makerhelper.rb
179
+ - test/test_pdfmaker_cmd.rb
120
180
  - test/test_preprocessor.rb
121
181
  - test/test_textutils.rb
122
182
  - test/test_topbuilder.rb
123
183
  - test/test_uuid.rb
124
184
  homepage: http://github.com/kmuto/review
125
- licenses: []
185
+ licenses:
186
+ - LGPL
126
187
  post_install_message:
127
188
  rdoc_options: []
128
189
  require_paths:
@@ -130,19 +191,63 @@ require_paths:
130
191
  required_ruby_version: !ruby/object:Gem::Requirement
131
192
  none: false
132
193
  requirements:
133
- - - ! '>='
194
+ - - '>='
134
195
  - !ruby/object:Gem::Version
135
196
  version: '0'
136
197
  required_rubygems_version: !ruby/object:Gem::Requirement
137
198
  none: false
138
199
  requirements:
139
- - - ! '>='
200
+ - - '>='
140
201
  - !ruby/object:Gem::Version
141
202
  version: '0'
142
203
  requirements: []
143
204
  rubyforge_project:
144
- rubygems_version: 1.8.10
205
+ rubygems_version: 1.8.25
145
206
  signing_key:
146
207
  specification_version: 3
147
- summary: ! 'ReVIEW: a easy-to-use digital publishing system'
148
- test_files: []
208
+ summary: 'ReVIEW: a easy-to-use digital publishing system'
209
+ test_files:
210
+ - test/CHAPS
211
+ - test/bib.re
212
+ - test/book_test_helper.rb
213
+ - test/sample-book/README.md
214
+ - test/sample-book/src/CHAPS
215
+ - test/sample-book/src/PREDEF
216
+ - test/sample-book/src/Rakefile
217
+ - test/sample-book/src/_cover.html
218
+ - test/sample-book/src/ch01.re
219
+ - test/sample-book/src/ch02.re
220
+ - test/sample-book/src/config.yml
221
+ - test/sample-book/src/images/ch01-imgsample.jpg
222
+ - test/sample-book/src/images/cover.jpg
223
+ - test/sample-book/src/main.css
224
+ - test/sample-book/src/preface.re
225
+ - test/sample-book/src/sty/jumoline.sty
226
+ - test/sample-book/src/sty/samplemacro.sty
227
+ - test/sample-book/src/vendor/jumoline/README
228
+ - test/sample-book/src/vendor/jumoline/jumoline.dtx
229
+ - test/sample-book/src/vendor/jumoline/jumoline.ins
230
+ - test/test.re
231
+ - test/test_book.rb
232
+ - test/test_book_chapter.rb
233
+ - test/test_book_parameter.rb
234
+ - test/test_book_part.rb
235
+ - test/test_builder.rb
236
+ - test/test_compiler.rb
237
+ - test/test_epubmaker.rb
238
+ - test/test_epubmaker_cmd.rb
239
+ - test/test_helper.rb
240
+ - test/test_htmlbuilder.rb
241
+ - test/test_htmlutils.rb
242
+ - test/test_i18n.rb
243
+ - test/test_idgxmlbuilder.rb
244
+ - test/test_inaobuilder.rb
245
+ - test/test_index.rb
246
+ - test/test_latexbuilder.rb
247
+ - test/test_lineinput.rb
248
+ - test/test_makerhelper.rb
249
+ - test/test_pdfmaker_cmd.rb
250
+ - test/test_preprocessor.rb
251
+ - test/test_textutils.rb
252
+ - test/test_topbuilder.rb
253
+ - test/test_uuid.rb
@@ -1,323 +0,0 @@
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/compat'
13
- require 'review/exception'
14
-
15
- module ReVIEW
16
-
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
- end
57
-
58
- def number(id)
59
- @index.fetch(id).number.to_s
60
- end
61
-
62
- def each(&block)
63
- @items.each(&block)
64
- end
65
-
66
- def has_key?(id)
67
- return @index.has_key?(id)
68
- end
69
- end
70
-
71
-
72
- class ChapterIndex < Index
73
- def item_type
74
- 'chapter'
75
- end
76
-
77
- def number(id)
78
- "第#{@index.fetch(id).number}章"
79
- end
80
-
81
- def title(id)
82
- @index.fetch(id).title
83
- end
84
-
85
- def display_string(id)
86
- "#{number(id)}「#{title(id)}」"
87
- end
88
- end
89
-
90
-
91
- class ListIndex < Index
92
- def ListIndex.item_type
93
- '(list|listnum)'
94
- end
95
- end
96
-
97
-
98
- class TableIndex < Index
99
- def TableIndex.item_type
100
- 'table'
101
- end
102
- end
103
-
104
-
105
- class FootnoteIndex < Index
106
- Item = Struct.new(:id, :number, :content)
107
-
108
- def FootnoteIndex.parse(src)
109
- items = []
110
- seq = 1
111
- src.grep(%r<^//footnote>) do |line|
112
- if m = /\[(.*?)\]\[(.*)\]/.match(line)
113
- items.push Item.new(m[1], seq, m[2])
114
- end
115
- seq += 1
116
- end
117
- new(items)
118
- end
119
- end
120
-
121
-
122
- class ImageIndex < Index
123
- class Item
124
- def initialize(id, number)
125
- @id = id
126
- @number = number
127
- @pathes = nil
128
- end
129
-
130
- attr_reader :id
131
- attr_reader :number
132
- attr_writer :index # internal use only
133
-
134
- def bound?
135
- not pathes().empty?
136
- end
137
-
138
- def path
139
- pathes().first
140
- end
141
-
142
- def pathes
143
- @pathes ||= @index.find_pathes(id)
144
- end
145
- end
146
-
147
- def ImageIndex.item_type
148
- '(image|graph)'
149
- end
150
-
151
- def initialize(items, chapid, basedir, types)
152
- super items
153
- items.each do |i|
154
- i.index = self
155
- end
156
- @chapid = chapid
157
- @basedir = basedir
158
- @types = types
159
- end
160
-
161
- # internal use only
162
- def find_pathes(id)
163
- if ReVIEW.book.param["subdirmode"]
164
- re = /\A#{id}(?i:#{@types.join('|')})\z/x
165
- entries().select {|ent| re =~ ent }\
166
- .sort_by {|ent| @types.index(File.extname(ent).downcase) }\
167
- .map {|ent| "#{@basedir}/#{@chapid}/#{ent}" }
168
- elsif ReVIEW.book.param["singledirmode"]
169
- re = /\A#{id}(?i:#{@types.join('|')})\z/x
170
- entries().select {|ent| re =~ ent }\
171
- .sort_by {|ent| @types.index(File.extname(ent).downcase) }\
172
- .map {|ent| "#{@basedir}/#{ent}" }
173
- else
174
- re = /\A#{@chapid}-#{id}(?i:#{@types.join('|')})\z/x
175
- entries().select {|ent| re =~ ent }\
176
- .sort_by {|ent| @types.index(File.extname(ent).downcase) }\
177
- .map {|ent| "#{@basedir}/#{ent}" }
178
- end
179
- end
180
-
181
- private
182
-
183
- def entries
184
- # @entries: do not cache for graph
185
- if ReVIEW.book.param["subdirmode"]
186
- @entries = Dir.entries(File.join(@basedir, @chapid))
187
- else
188
- @entries = Dir.entries(@basedir)
189
- end
190
- rescue Errno::ENOENT
191
- @entries = []
192
- end
193
- end
194
-
195
- class IconIndex < ImageIndex
196
- def IconIndex.parse(src, *args)
197
- items = []
198
- seq = 1
199
- src.grep(%r!@<icon>!) do |line|
200
- line.gsub(/@<icon>\{(.+?)\}/) do |m|
201
- items.push item_class().new($1, seq)
202
- seq += 1
203
- end
204
- end
205
- new(items, *args)
206
- end
207
- end
208
-
209
- class FormatRef
210
- def initialize(locale, index)
211
- @locale = locale
212
- @index = index
213
- end
214
-
215
- def title(id)
216
- sprintf(@locale["#{@index.item_type}_caption_format".intern],
217
- @index.title(id))
218
- end
219
-
220
- def number(id)
221
- sprintf(@locale["#{@index.item_type}_number_format".intern],
222
- @index.number(id))
223
- end
224
-
225
- def method_missing(mid, *args, &block)
226
- super unless @index.respond_to?(mid)
227
- @index.__send__(mid, *args, &block)
228
- end
229
- end
230
-
231
- class BibpaperIndex < Index
232
- Item = Struct.new(:id, :number, :caption)
233
-
234
- def BibpaperIndex.parse(src)
235
- items = []
236
- seq = 1
237
- src.grep(%r<^//bibpaper>) do |line|
238
- if m = /\[(.*?)\]\[(.*)\]/.match(line)
239
- items.push Item.new(m[1], seq, m[2])
240
- end
241
- seq += 1
242
- end
243
- new(items)
244
- end
245
- end
246
-
247
- class NumberlessImageIndex < ImageIndex
248
- class Item < ImageIndex::Item
249
- def initialize(id, number)
250
- @id = id
251
- @number = ""
252
- @pathes = nil
253
- end
254
- end
255
-
256
- def NumberlessImageIndex.item_type
257
- 'numberlessimage'
258
- end
259
-
260
- def number(id)
261
- ""
262
- end
263
- end
264
-
265
- class IndepImageIndex < ImageIndex
266
- class Item < ImageIndex::Item
267
- def initialize(id, number)
268
- @id = id
269
- @number = ""
270
- @pathes = nil
271
- end
272
- end
273
-
274
- def IndepImageIndex.item_type
275
- 'indepimage'
276
- end
277
-
278
- def number(id)
279
- ""
280
- end
281
- end
282
-
283
- class HeadlineIndex < Index
284
- Item = Struct.new(:id, :number, :caption)
285
-
286
- def HeadlineIndex.parse(src, chap)
287
- items = []
288
- indexs = []
289
- headlines = []
290
- src.each do |line|
291
- if m = /\A(=+)(?:\[(.+?)\])?(?:\{(.+?)\})?(.*)/.match(line)
292
- next if m[2] == 'column'
293
- index = m[1].size - 2
294
- if index >= 0
295
- if indexs.size > (index + 1)
296
- indexs = indexs.take(index + 1)
297
- headlines = headlines.take(index + 1)
298
- end
299
- indexs << 0 if indexs[index].nil?
300
- indexs[index] += 1
301
- headlines[index] = m[4].strip
302
- items.push Item.new(headlines.join("|"), indexs.dup, m[4].strip)
303
- end
304
- end
305
- end
306
- new(items, chap)
307
- end
308
-
309
- def initialize(items, chap)
310
- @items = items
311
- @chap = chap
312
- @index = {}
313
- items.each do |i|
314
- warn "warning: duplicate ID: #{i.id}" unless @index[i.id].nil?
315
- @index[i.id] = i
316
- end
317
- end
318
-
319
- def number(id)
320
- return ([@chap.number] + @index.fetch(id).number).join(".")
321
- end
322
- end
323
- end