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
@@ -93,16 +93,16 @@ EOT
93
93
  FileUtils.mkdir_p(File.dirname("#{tmpdir}/OEBPS/#{item.file}")) unless File.exist?(File.dirname("#{tmpdir}/OEBPS/#{item.file}"))
94
94
  FileUtils.cp(fname, "#{tmpdir}/OEBPS/#{item.file}")
95
95
  end
96
-
96
+
97
97
  fork {
98
98
  Dir.chdir(tmpdir) {|d|
99
- exec("zip -0X #{epubfile} mimetype")
99
+ exec("zip", "-0X", "#{epubfile}", "mimetype")
100
100
  }
101
101
  }
102
102
  Process.waitall
103
103
  fork {
104
104
  Dir.chdir(tmpdir) {|d|
105
- exec("zip -Xr9D #{epubfile} META-INF OEBPS")
105
+ exec("zip", "-Xr9D", "#{epubfile}", "META-INF", "OEBPS")
106
106
  }
107
107
  }
108
108
  Process.waitall
@@ -119,11 +119,11 @@ EOT
119
119
  %w[title language date type format source description relation coverage subject rights].each do |item|
120
120
  next if @producer.params[item].nil?
121
121
  if @producer.params[item].instance_of?(Array)
122
- s << @producer.params[item].map {|i| %Q[ <dc:#{item} prefer="#{item}">#{i}</dc:#{item}>\n]}.join
123
- s << @producer.params[item].map {|i| %Q[ <meta id="#{item}" property="dcterms:#{item}>#{i}</meta>\n]}.join
122
+ s << @producer.params[item].map {|i| %Q[ <dc:#{item} prefer="#{item}">#{CGI.escapeHTML(i.to_s)}</dc:#{item}>\n]}.join
123
+ s << @producer.params[item].map {|i| %Q[ <meta id="#{item}" property="dcterms:#{item}">#{CGI.escapeHTML(i.to_s)}</meta>\n]}.join
124
124
  else
125
- s << %Q[ <dc:#{item} prefer="#{item}">#{@producer.params[item]}</dc:#{item}>\n]
126
- s << %Q[ <meta id="#{item}" property="dcterms:#{item}">#{@producer.params[item]}</meta>\n]
125
+ s << %Q[ <dc:#{item} prefer="#{item}">#{CGI.escapeHTML(@producer.params[item].to_s)}</dc:#{item}>\n]
126
+ s << %Q[ <meta id="#{item}" property="dcterms:#{item}">#{CGI.escapeHTML(@producer.params[item].to_s)}</meta>\n]
127
127
  end
128
128
  end
129
129
 
@@ -140,20 +140,20 @@ EOT
140
140
  %w[aut a-adp a-ann a-arr a-art a-asn a-aqt a-aft a-aui a-ant a-bkp a-clb a-cmm a-dsr a-edt a-ill a-lyr a-mdc a-mus a-nrt a-oth a-pht a-prt a-red a-rev a-spn a-ths a-trc a-trl].each do |role|
141
141
  next if @producer.params[role].nil?
142
142
  @producer.params[role].each_with_index do |v, i|
143
- s << %Q[ <dc:creator opf:role="#{role.sub('a-', '')}" prefer="creator-#{i}">#{v}</dc:creator>\n]
144
- s << %Q[ <meta property="dcterms:creator" id="creator-#{i}" opf:role="#{role.sub('a-', '')}">#{v}</meta>\n]
143
+ s << %Q[ <dc:creator opf:role="#{role.sub('a-', '')}" prefer="creator-#{i}">#{CGI.escapeHTML(v)}</dc:creator>\n]
144
+ s << %Q[ <meta property="dcterms:creator" id="creator-#{i}" opf:role="#{role.sub('a-', '')}">#{CGI.escapeHTML(v)}</meta>\n]
145
145
  end
146
146
  end
147
147
  # contributor
148
148
  %w[adp ann arr art asn aqt aft aui ant bkp clb cmm dsr edt ill lyr mdc mus nrt oth pht prt red rev spn ths trc trl].each do |role|
149
149
  next if @producer.params[role].nil?
150
150
  @producer.params[role].each_with_index do |v, i|
151
- s << %Q[ <dc:contributor opf:role="#{role}" prefer="contributor-#{i}">#{v}</dc:contributor>\n]
152
- s << %Q[ <meta property="dcterms:contributor" id="contributor-#{i}" opf:role="#{role}">#{v}</meta>\n]
151
+ s << %Q[ <dc:contributor opf:role="#{role}" prefer="contributor-#{i}">#{CGI.escapeHTML(v)}</dc:contributor>\n]
152
+ s << %Q[ <meta property="dcterms:contributor" id="contributor-#{i}" opf:role="#{role}">#{CGI.escapeHTML(v)}</meta>\n]
153
153
 
154
154
  if role == "prt"
155
- s << %Q[ <dc:publisher prefer="publisher">#{v}</dc:publisher>\n]
156
- s << %Q[ <meta property="dcterms:publisher" id="publisher">#{v}</meta>\n]
155
+ s << %Q[ <dc:publisher prefer="publisher">#{CGI.escapeHTML(v)}</dc:publisher>\n]
156
+ s << %Q[ <meta property="dcterms:publisher" id="publisher">#{CGI.escapeHTML(v)}</meta>\n]
157
157
  end
158
158
  end
159
159
  end
@@ -74,7 +74,7 @@ module EPUBMaker
74
74
  # Write mimetype file to IO object +wobj+.
75
75
  def mimetype(wobj)
76
76
  s = @epub.mimetype
77
- wobj.puts s if !s.nil? && !wobj.nil?
77
+ wobj.print s if !s.nil? && !wobj.nil?
78
78
  end
79
79
 
80
80
  # Write opf file to IO object +wobj+.
@@ -1,4 +1,3 @@
1
- require 'review/i18n'
2
- require 'review/exception'
3
- require 'review/compiler'
4
- require 'review/htmlbuilder'
1
+ Dir["#{File.dirname(__FILE__)}/review/*.rb"].sort.each do |path|
2
+ require "review/#{File.basename(path, '.rb')}"
3
+ end
@@ -10,601 +10,37 @@
10
10
  # For details of the GNU LGPL, see the file "COPYING".
11
11
  #
12
12
 
13
- require 'review/index'
14
- require 'review/volume'
15
13
  require 'review/exception'
16
- require 'review/compat'
14
+ require 'review/extentions'
17
15
  require 'forwardable'
18
16
  require 'nkf'
19
17
 
20
- module ReVIEW
18
+ require 'review/book/base'
19
+ require 'review/book/chapter'
20
+ require 'review/book/part'
21
+ require 'review/book/parameters'
22
+ require 'review/book/page_metric'
23
+ require 'review/book/volume'
24
+ require 'review/book/index'
21
25
 
26
+ module ReVIEW
22
27
  @default_book = nil
23
28
 
24
29
  def ReVIEW.book
25
- @default_book ||= Book.load_default
26
- end
27
-
28
- class Book
29
-
30
- attr_accessor :param
31
-
32
- def Book.load_default
33
- %w( . .. ../.. ).each do |basedir|
34
- if File.file?("#{basedir}/CHAPS")
35
- book = load(basedir)
36
- if File.file?("#{basedir}/config.rb")
37
- book.instance_variable_set("@parameters", Parameters.load("#{basedir}/config.rb"))
38
- end
39
- return book
40
- end
41
- end
42
- new('.')
43
- end
44
-
45
- def Book.load(dir)
46
- update_rubyenv dir
47
- new(dir)
48
- end
49
-
50
- @basedir_seen = {}
51
-
52
- def Book.update_rubyenv(dir)
53
- return if @basedir_seen.key?(dir)
54
- if File.directory?("#{dir}/lib/review")
55
- $LOAD_PATH.unshift "#{dir}/lib"
56
- end
57
- if File.file?("#{dir}/review-ext.rb")
58
- Kernel.load File.expand_path("#{dir}/review-ext.rb")
59
- end
60
- @basedir_seen[dir] = true
61
- end
62
-
63
- def initialize(basedir, parameters = Parameters.default)
64
- @basedir = basedir
65
- @parameters = parameters
66
- @parts = nil
67
- @chapter_index = nil
68
- end
69
-
70
- extend Forwardable
71
- def_delegators '@parameters',
72
- :chapter_file,
73
- :part_file,
74
- :bib_file,
75
- :reject_file,
76
- :predef_file,
77
- :postdef_file,
78
- :ext,
79
- :image_dir,
80
- :image_types,
81
- :page_metric
82
-
83
- def no_part?
84
- false
85
- end
86
-
87
- def parts
88
- @parts ||= read_parts()
89
- end
90
-
91
- def part(n)
92
- parts.detect {|part| part.number == n }
93
- end
94
-
95
- def each_part(&block)
96
- parts.each(&block)
97
- end
98
-
99
- def chapters
100
- parts().map {|p| p.chapters }.flatten
101
- end
102
-
103
- def each_chapter(&block)
104
- chapters.each(&block)
105
- end
106
-
107
- def chapter_index
108
- @chapter_index ||= ChapterIndex.new(chapters())
109
- @chapter_index
110
- end
111
-
112
- def chapter(id)
113
- chapter_index()[id]
114
- end
115
-
116
- def volume
117
- Volume.sum(chapters.map {|chap| chap.volume })
118
- end
119
-
120
- def read_CHAPS
121
- res = ""
122
- File.open("#{@basedir}/#{chapter_file}") do |f|
123
- while line = f.gets
124
- if /\A#/ =~ line
125
- next
126
- end
127
- line.gsub!(/#.*$/, "")
128
- res << line
129
- end
130
- end
131
- res
132
- rescue Errno::ENOENT
133
- Dir.glob("#{@basedir}/*#{ext()}").sort.join("\n")
134
- end
135
-
136
- def read_PART
137
- @read_PART ||= File.read("#{@basedir}/#{part_file}")
138
- end
139
-
140
- def part_exist?
141
- File.exist?("#{@basedir}/#{part_file}")
142
- end
143
-
144
- def read_bib
145
- File.read("#{@basedir}/#{bib_file}")
146
- end
147
-
148
- def bib_exist?
149
- File.exist?("#{@basedir}/#{bib_file}")
150
- end
151
-
152
- def prefaces
153
- if File.file?("#{@basedir}/#{predef_file}")
154
- begin
155
- return mkpart_from_namelistfile("#{@basedir}/#{predef_file}")
156
- rescue FileNotFound => err
157
- raise FileNotFound, "preface #{err.message}"
158
- end
159
- else
160
- mkpart_from_namelist(%w(preface))
161
- end
162
- end
163
-
164
- def postscripts
165
- if File.file?("#{@basedir}/#{postdef_file}")
166
- begin
167
- return mkpart_from_namelistfile("#{@basedir}/#{postdef_file}")
168
- rescue FileNotFound => err
169
- raise FileNotFound, "postscript #{err.message}"
170
- end
171
- else
172
- mkpart_from_namelist(%w(appendix postscript))
173
- end
174
- end
175
-
176
- def basedir
177
- @basedir
178
- end
179
-
180
- private
181
-
182
- def read_parts
183
- list = parse_chapters
184
- if pre = prefaces
185
- list.unshift pre
186
- end
187
- if post = postscripts
188
- list.push post
189
- end
190
- list
191
- end
192
-
193
- def parse_chapters
194
- part = 0
195
- num = 0
196
- chap = read_CHAPS()\
197
- .strip.lines.map {|line| line.strip }.join("\n").split(/\n{2,}/)\
198
- .map {|part_chunk|
199
- chaps = part_chunk.split.map {|chapid|
200
- Chapter.new(self, (num += 1), chapid, "#{@basedir}/#{chapid}")
201
- }
202
- if part_exist? && read_PART.split("\n").size >= part
203
- Part.new((part += 1), chaps, read_PART.split("\n")[part-1])
204
- else
205
- Part.new((part += 1), chaps)
206
- end
207
- }
208
- return chap
209
- end
210
-
211
- def mkpart_from_namelistfile(path)
212
- mkpart(File.read(path).split.map {|name| mkchap(name) })
213
- end
214
-
215
- def mkpart_from_namelist(names)
216
- mkpart(names.map {|n| mkchap_ifexist(n) }.compact)
217
- end
218
-
219
- def mkpart(chaps)
220
- chaps.empty? ? nil : Part.new(nil, chaps)
221
- end
222
-
223
- def mkchap(name)
224
- name += ext if File.extname(name) == ""
225
- path = "#{@basedir}/#{name}"
226
- raise FileNotFound, "file not exist: #{path}" unless File.file?(path)
227
- Chapter.new(self, nil, name, path)
228
- end
229
-
230
- def mkchap_ifexist(id)
231
- name = "#{id}#{ext()}"
232
- path = "#{@basedir}/#{name}"
233
- File.file?(path) ? Chapter.new(self, nil, name, path) : nil
234
- end
235
-
236
- end
237
-
238
-
239
- class ChapterSet
240
-
241
- def ChapterSet.for_argv
242
- if ARGV.empty?
243
- new([Chapter.for_stdin])
244
- else
245
- for_pathes(ARGV)
246
- end
247
- end
248
-
249
- def ChapterSet.for_pathes(pathes)
250
- new(Chapter.intern_pathes(pathes))
251
- end
252
-
253
- def initialize(chapters)
254
- @chapters = chapters
255
- end
256
-
257
- def no_part?
258
- true
259
- end
260
-
261
- attr_reader :chapters
262
-
263
- def each_chapter(&block)
264
- @chapters.each(&block)
265
- end
266
-
267
- def ext
268
- '.re'
269
- end
270
-
30
+ @default_book ||= Book::Base.load_default
271
31
  end
272
32
 
273
-
274
- class Parameters
275
-
276
- def Parameters.default
277
- new()
278
- end
279
-
280
- def Parameters.load(path)
281
- mod = Module.new
282
- mod.module_eval File.read(path), path
283
- new(
284
- :chapter_file => const_get_safe(mod, :CHAPS_FILE),
285
- :part_file => const_get_safe(mod, :PART_FILE),
286
- :bib_file => const_get_safe(mod, :BIB_FILE),
287
- :reject_file => const_get_safe(mod, :REJECT_FILE) ||
288
- const_get_safe(mod, :WORDS_FILE),
289
- :predef_file => const_get_safe(mod, :PREDEF_FILE),
290
- :postdef_file => const_get_safe(mod, :POSTDEF_FILE),
291
- :ext => const_get_safe(mod, :EXT),
292
- :image_dir => const_get_safe(mod, :IMAGE_DIR),
293
- :image_types => const_get_safe(mod, :IMAGE_TYPES),
294
- :page_metric => get_page_metric(mod)
295
- )
296
- end
297
-
298
- def Parameters.get_page_metric(mod)
299
- if paper = const_get_safe(mod, :PAPER)
300
- unless PageMetric.respond_to?(paper.downcase)
301
- raise ConfigError, "unknown paper size: #{paper}"
302
- end
303
- return PageMetric.send(paper.downcase)
304
- end
305
- PageMetric.new(const_get_safe(mod, :LINES_PER_PAGE_list) || 46,
306
- const_get_safe(mod, :COLUMNS_list) || 80,
307
- const_get_safe(mod, :LINES_PER_PAGE_text) || 30,
308
- const_get_safe(mod, :COLUMNS_text) || 74) # 37zw
309
- end
310
-
311
- def Parameters.const_get_safe(mod, name)
312
- return nil unless mod.const_defined?(name)
313
- mod.const_get(name)
314
- end
315
- private_class_method :const_get_safe
316
-
317
- def initialize(params = {})
318
- @chapter_file = params[:chapter_file] || 'CHAPS'
319
- @part_file = params[:part_file] || 'CHAPS'
320
- @reject_file = params[:reject_file] || 'REJECT'
321
- @predef_file = params[:predef_file] || 'PREDEF'
322
- @postdef_file = params[:postdef_file] || 'POSTDEF'
323
- @page_metric = params[:page_metric] || PageMetric.a5
324
- @ext = params[:ext] || '.re'
325
- @image_dir = params[:image_dir] || 'images'
326
- @image_types = unify_exts(params[:image_types] ||
327
- %w( eps ai tif tiff png bmp jpg jpeg gif svg pdf ))
328
- @bib_file = params[:bib_file] || "bib#{@ext}"
329
- end
330
-
331
- def unify_exts(list)
332
- list.map {|ext| (ext[0] == '.') ? ext : ".#{ext}" }
333
- end
334
- private :unify_exts
335
-
336
- def self.path_param(name)
337
- module_eval(<<-End, __FILE__, __LINE__ + 1)
338
- def #{name}
339
- "\#{@basedir}/\#{@#{name}}"
340
- end
341
- End
342
- end
343
-
344
- path_param :chapter_file
345
- path_param :part_file
346
- path_param :bib_file
347
- path_param :reject_file
348
- path_param :predef_file
349
- path_param :postdef_file
350
- attr_reader :ext
351
- path_param :image_dir
352
- attr_reader :image_types
353
- attr_reader :page_metric
354
-
355
- end
356
-
357
-
358
- class PageMetric
359
-
360
- MetricData = Struct.new(:n_lines, :n_columns)
361
-
362
- def PageMetric.a5
363
- new(46, 80, 30, 74, 1)
364
- end
365
-
366
- def PageMetric.b5
367
- new(46, 80, 30, 74, 2)
368
- end
369
-
370
- def initialize(list_lines, list_columns, text_lines, text_columns, page_per_kbyte)
371
- @list = MetricData.new(list_lines, list_columns)
372
- @text = MetricData.new(text_lines, text_columns)
373
- @page_per_kbyte = page_per_kbyte
374
- end
375
-
376
- attr_reader :list
377
- attr_reader :text
378
- attr_reader :page_per_kbyte
379
-
380
- end
381
-
382
-
383
- class Part
384
-
385
- def initialize(number, chapters, name="")
386
- @number = number
387
- @chapters = chapters
388
- @name = name
389
- end
390
-
391
- attr_reader :number
392
- attr_reader :chapters
393
- attr_reader :name
394
-
395
- def each_chapter(&block)
396
- @chapters.each(&block)
397
- end
398
-
399
- def volume
400
- Volume.sum(@chapters.map {|chap| chap.volume })
401
- end
402
-
403
- end
404
-
405
-
406
- class Chapter
407
-
408
- def Chapter.intern_pathes(pathes)
409
- books = {}
410
- pathes.map {|path|
411
- basedir = File.dirname(path)
412
- book = (books[File.expand_path(basedir)] ||= Book.load(basedir))
413
- begin
414
- book.chapter(File.basename(path, '.*'))
415
- rescue KeyError => err
416
- raise FileNotFound, "no such file: #{path}"
417
- end
418
- }
419
- end
420
-
421
- def Chapter.for_stdin
422
- new(nil, nil, '-', nil, $stdin)
423
- end
424
-
425
- def Chapter.for_path(number, path)
426
- new(nil, number, File.basename(path), path)
427
- end
428
-
429
- def initialize(book, number, name, path, io = nil)
430
- @book = book
431
- @number = number
432
- @name = name
433
- @path = path
434
- @io = io
435
- @title = nil
436
- @content = nil
437
- @list_index = nil
438
- @table_index = nil
439
- @footnote_index = nil
440
- @image_index = nil
441
- @icon_index = nil
442
- @numberless_image_index = nil
443
- @indepimage_index = nil
444
- @headline_index = nil
445
- end
446
-
447
- def env
448
- @book
449
- end
450
-
451
- def inspect
452
- "\#<#{self.class} #{@number} #{@path}>"
453
- end
454
-
455
- attr_reader :book
456
- attr_reader :number
457
- attr_reader :path
458
-
459
- def dirname
460
- return nil unless @path
461
- File.dirname(@path)
462
- end
463
-
464
- def basename
465
- return nil unless @path
466
- File.basename(@path)
467
- end
468
-
469
- def name
470
- File.basename(@name, '.*')
471
- end
472
-
473
- alias id name
474
-
475
- def title
476
- @title = ""
477
- open {|f|
478
- f.each_line {|l|
479
- if l =~ /\A=+/
480
- @title = l.sub(/\A=+/, '').strip
481
- break
482
- end
483
- }
484
- }
485
- if ReVIEW.book.param["inencoding"] =~ /^EUC$/
486
- @title = NKF.nkf("-E -w", @title)
487
- elsif ReVIEW.book.param["inencoding"] =~ /^SJIS$/
488
- @title = NKF.nkf("-S -w", @title)
489
- elsif ReVIEW.book.param["inencoding"] =~ /^JIS$/
490
- @title = NKF.nkf("-J -w", @title)
491
- else
492
- @title = NKF.nkf("-w", @title)
493
- end
494
- end
495
-
496
- def size
497
- File.size(path())
498
- end
499
-
500
- def volume
501
- @volume ||= Volume.count_file(path())
502
- end
503
-
504
- def open(&block)
505
- return (block_given?() ? yield(@io) : @io) if @io
506
- File.open(path(), &block)
507
- end
508
-
509
- def content
510
- if ReVIEW.book.param["inencoding"] =~ /^EUC$/i
511
- @content = NKF.nkf("-E -w", File.read(path()))
512
- elsif ReVIEW.book.param["inencoding"] =~ /^SJIS$/i
513
- @content = NKF.nkf("-S -w", File.read(path()))
514
- elsif ReVIEW.book.param["inencoding"] =~ /^JIS$/i
515
- @content = NKF.nkf("-J -w", File.read(path()))
516
- else
517
- @content = NKF.nkf("-w", File.read(path())) # auto detect
518
- end
519
- end
520
-
521
- def lines
522
- # FIXME: we cannot duplicate Enumerator on ruby 1.9 HEAD
523
- (@lines ||= content().lines.to_a).dup
524
- end
525
-
526
- def list(id)
527
- list_index()[id]
528
- end
529
-
530
- def list_index
531
- @list_index ||= ListIndex.parse(lines())
532
- @list_index
533
- end
534
-
535
- def table(id)
536
- table_index()[id]
537
- end
538
-
539
- def table_index
540
- @table_index ||= TableIndex.parse(lines())
541
- @table_index
542
- end
543
-
544
- def footnote(id)
545
- footnote_index()[id]
546
- end
547
-
548
- def footnote_index
549
- @footnote_index ||= FootnoteIndex.parse(lines())
550
- @footnote_index
551
- end
552
-
553
- def image(id)
554
- return image_index()[id] if image_index().has_key?(id)
555
- return icon_index()[id] if icon_index().has_key?(id)
556
- return numberless_image_index()[id] if numberless_image_index().has_key?(id)
557
- indepimage_index()[id]
558
- end
559
-
560
- def numberless_image_index
561
- @numberless_image_index ||=
562
- NumberlessImageIndex.parse(lines(), id(),
563
- "#{book.basedir}#{@book.image_dir}",
564
- @book.image_types)
565
- end
566
-
567
- def image_index
568
- @image_index ||= ImageIndex.parse(lines(), id(),
569
- "#{book.basedir}#{@book.image_dir}",
570
- @book.image_types)
571
- @image_index
572
- end
573
-
574
- def icon_index
575
- @icon_index ||= IconIndex.parse(lines(), id(),
576
- "#{book.basedir}#{@book.image_dir}",
577
- @book.image_types)
578
- @icon_index
579
- end
580
-
581
- def indepimage_index
582
- @indepimage_index ||=
583
- IndepImageIndex.parse(lines(), id(),
584
- "#{book.basedir}#{@book.image_dir}",
585
- @book.image_types)
586
- end
587
-
588
- def bibpaper(id)
589
- bibpaper_index()[id]
590
- end
591
-
592
- def bibpaper_index
593
- raise FileNotFound, "no such bib file: #{@book.bib_file}" unless @book.bib_exist?
594
- @bibpaper_index ||= BibpaperIndex.parse(@book.read_bib.lines.to_a)
595
- @bibpaper_index
596
- end
597
-
598
- def headline(caption)
599
- headline_index()[caption]
33
+ module Book
34
+ def self.load_default
35
+ Base.load_default
600
36
  end
601
37
 
602
- def headline_index
603
- @headline_index ||= HeadlineIndex.parse(lines(), self)
38
+ def self.load(dir)
39
+ Base.load dir
604
40
  end
605
41
 
606
- def on_CHAPS?
607
- @book.read_CHAPS().lines.map(&:strip).include?(id() + @book.ext())
42
+ def self.update_rubyenv(dir)
43
+ Base.update_rubyenv dir
608
44
  end
609
45
  end
610
46
  end