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
@@ -0,0 +1,418 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'book_test_helper'
3
+ class ChapterTest < Test::Unit::TestCase
4
+ include BookTestHelper
5
+
6
+ def setup
7
+
8
+ if "".respond_to?(:encode)
9
+ @utf8_str = "あいうえお"
10
+ @eucjp_str = "あいうえお".encode("EUC-JP")
11
+ @sjis_str = "あいうえお".encode("Shift_JIS")
12
+ @jis_str = "あいうえお".encode("ISO-2022-JP")
13
+ else
14
+ @utf8_str = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a" # "あいうえお"
15
+ @eucjp_str = "\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa"
16
+ @sjis_str = "\x82\xa0\x82\xa2\x82\xa4\x82\xa6\x82\xa8"
17
+ @jis_str = "\x1b\x24\x42\x24\x22\x24\x24\x24\x26\x24\x28\x24\x2a\x1b\x28\x42"
18
+ end
19
+ =begin
20
+ @utf8_str = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a" # "あいうえお"
21
+ @eucjp_str = "\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa"
22
+ @sjis_str = "\x82\xa0\x82\xa2\x82\xa4\x82\xa6\x82\xa8"
23
+ @jis_str = "\x1b\x24\x42\x24\x22\x24\x24\x24\x26\x24\x28\x24\x2a\x1b\x28\x42"
24
+ =end
25
+ end
26
+
27
+ def test_s_intern_pathes
28
+ dir1_files = {
29
+ 'CHAPS' => "ch1.re\nch2.re\n",
30
+ 'ch1.re' => 'ch1',
31
+ 'ch2.re' => 'ch2',
32
+ }
33
+ dir2_files = {
34
+ 'CHAPS' => "ch1.re\n",
35
+ 'ch1.re' => 'ch1',
36
+ }
37
+ mktmpbookdir dir1_files do |dir1, book1, files1|
38
+ mktmpbookdir dir2_files do |dir2, book2, files2|
39
+ paths = (files1.values + files2.values).flatten.grep(/\.re\z/)
40
+ chs = Book::Chapter.intern_pathes(paths)
41
+
42
+ assert_equal 3, chs.size
43
+ assert chs[0].book == chs[1].book
44
+ assert chs[0].book != chs[2].book
45
+ assert dir1, chs[0].book.basedir
46
+ assert dir2, chs[2].book.basedir
47
+ end
48
+ end
49
+
50
+ dir_files = {
51
+ 'CHAPS' => "ch1.re\n",
52
+ 'ch1.re' => 'ch1',
53
+ }
54
+ mktmpbookdir dir_files do |dir, book, files|
55
+ paths = files.values.grep(/\.re\z/)
56
+ paths << __FILE__ + ' not exist file.re'
57
+ assert_raises ReVIEW::FileNotFound do
58
+ Book::Chapter.intern_pathes(paths)
59
+ end
60
+ end
61
+
62
+ dir_files = {
63
+ 'ch1.re' => 'ch1 not in CHAPS',
64
+ 'ch2.re' => 'ch2 not in CHAPS',
65
+ }
66
+ mktmpbookdir dir_files do |dir, book, files|
67
+ paths = files.values.grep(/\.re\z/)
68
+ assert_nothing_raised do
69
+ Book::Chapter.intern_pathes(paths)
70
+ end
71
+ end
72
+
73
+ dir_files = {
74
+ 'CHAPS' => "ch1.re\n",
75
+ 'ch1.re' => 'ch1',
76
+ 'ch2.re' => 'ch2 not in CHAPS',
77
+ }
78
+ mktmpbookdir dir_files do |dir, book, files|
79
+ paths = files.values.grep(/\.re\z/)
80
+ assert_raises KeyError::FileNotFound do
81
+ Book::Chapter.intern_pathes(paths)
82
+ end
83
+ end
84
+
85
+ dir_files = {
86
+ 'CHAPS' => "ch1.re\n",
87
+ 'ch1.re' => 'ch1',
88
+ 'preface.re' => 'preface',
89
+ }
90
+ mktmpbookdir dir_files do |dir, book, files|
91
+ paths = files.values.grep(/\.re\z/)
92
+ assert_nothing_raised do
93
+ Book::Chapter.intern_pathes(paths)
94
+ end
95
+ end
96
+ end
97
+
98
+ def test_s_for_stdin
99
+ assert Book::Chapter.for_stdin
100
+ end
101
+
102
+ def test_s_for_path
103
+ assert Book::Chapter.for_path(1, __FILE__)
104
+ end
105
+
106
+ def test_initialize
107
+ ch = Book::Chapter.new(:book, :number, :name, '/foo/bar', :io)
108
+ assert_equal :book, ch.env
109
+ assert_equal :book, ch.book
110
+ assert_equal :number, ch.number
111
+ assert_equal '/foo/bar', ch.path
112
+ assert_equal "#<ReVIEW::Book::Chapter number /foo/bar>", ch.inspect
113
+ end
114
+
115
+ def test_dirname_and_basename
116
+ ch = Book::Chapter.new(nil, nil, nil, nil, nil)
117
+ assert_equal nil, ch.dirname
118
+ assert_equal nil, ch.basename
119
+
120
+ ch = Book::Chapter.new(nil, nil, nil, '/foo/bar', nil)
121
+ assert_equal '/foo', ch.dirname
122
+ assert_equal 'bar', ch.basename
123
+
124
+ ch = Book::Chapter.new(nil, nil, nil, 'bar', nil)
125
+ assert_equal '.', ch.dirname
126
+ assert_equal 'bar', ch.basename
127
+ end
128
+
129
+ def test_name
130
+ ch = Book::Chapter.new(nil, nil, 'foo', nil)
131
+ assert_equal 'foo', ch.name
132
+
133
+ ch = Book::Chapter.new(nil, nil, 'foo.bar', nil)
134
+ assert_equal 'foo', ch.name
135
+
136
+ ch = Book::Chapter.new(nil, nil, nil, nil)
137
+ assert_raises(TypeError) { ch.name } # XXX: OK?
138
+ end
139
+
140
+ def test_open
141
+ ch = Book::Chapter.new(nil, nil, nil, __FILE__, :io)
142
+ assert_equal :io, ch.open
143
+ assert_equal [:io], ch.open {|io| [io] }
144
+
145
+ ch = Book::Chapter.new(nil, nil, nil, __FILE__)
146
+ assert_equal __FILE__, ch.open.path
147
+ assert_equal [__FILE__], ch.open {|io| [io.path] }
148
+ end
149
+
150
+ def test_size
151
+ ch = Book::Chapter.new(nil, nil, nil, __FILE__, :io)
152
+ assert_equal File.size(__FILE__), ch.size
153
+
154
+ File.open(__FILE__, 'r') do |i|
155
+ ch = Book::Chapter.new(nil, nil, nil, nil, i)
156
+ assert_raises(TypeError) do # XXX: OK?
157
+ ch.size
158
+ end
159
+ end
160
+ end
161
+
162
+ def test_title
163
+ io = StringIO.new
164
+ ch = Book::Chapter.new(nil, nil, nil, nil, io)
165
+ assert_equal '', ch.title
166
+
167
+ io = StringIO.new("=1\n=2\n")
168
+ ch = Book::Chapter.new(nil, nil, nil, nil, io)
169
+ assert_equal '1', ch.title
170
+
171
+
172
+ [
173
+ ['EUC', @eucjp_str],
174
+ ['SJIS', @sjis_str],
175
+ # ['JIS', @jis_str],
176
+ ['XYZ', @eucjp_str],
177
+ ].each do |enc, instr|
178
+ io = StringIO.new("= #{instr}\n")
179
+ ch = Book::Chapter.new(nil, nil, nil, nil, io)
180
+ ReVIEW.book.param = {'inencoding' => enc}
181
+ assert_equal @utf8_str, ch.title
182
+ assert_equal @utf8_str, ch.instance_eval { @title }
183
+ end
184
+ end
185
+
186
+ def test_content
187
+ [
188
+ ['EUC', @eucjp_str],
189
+ ['SJIS', @sjis_str],
190
+ ['JIS', @jis_str],
191
+ ['XYZ', @eucjp_str],
192
+ ].each do |enc, instr|
193
+ tf = Tempfile.new('chapter_test')
194
+ begin
195
+ tf.print instr
196
+ tf.close
197
+
198
+ ch = Book::Chapter.new(nil, nil, nil, tf.path)
199
+ ReVIEW.book.param = {'inencoding' => enc}
200
+ assert_equal @utf8_str, ch.content
201
+ assert_equal @utf8_str, ch.instance_eval { @content }
202
+ ensure
203
+ tf.close(true)
204
+ end
205
+
206
+ tf1 = Tempfile.new('chapter_test1')
207
+ tf2 = Tempfile.new('chapter_test2')
208
+ begin
209
+ tf1.puts instr
210
+ tf1.puts instr
211
+ tf1.close
212
+ tf2.puts instr
213
+ tf1.close
214
+
215
+ ch = Book::Chapter.new(nil, nil, nil, tf1.path, tf2)
216
+ ReVIEW.book.param = {'inencoding' => enc}
217
+ assert_equal "#{@utf8_str}\n#{@utf8_str}\n", ch.content # XXX: OK?
218
+ ensure
219
+ tf1.close(true)
220
+ tf2.close(true)
221
+ end
222
+ end
223
+ end
224
+
225
+ def test_lines
226
+ lines = ["1\n", "2\n", "3"]
227
+ tf = Tempfile.new('chapter_test')
228
+ tf.print lines.join('')
229
+ tf.close
230
+
231
+ ch = Book::Chapter.new(nil, nil, nil, tf.path)
232
+ assert_equal lines, ch.lines
233
+
234
+ lines = ["1\n", "2\n", "3"]
235
+ tf1 = Tempfile.new('chapter_test1')
236
+ tf1.print lines.join('')
237
+ tf1.close
238
+ tf2 = Tempfile.new('chapter_test2')
239
+ tf2.puts lines.join('')
240
+ tf2.puts lines.join('')
241
+ tf2.close
242
+
243
+ ch = Book::Chapter.new(nil, nil, nil, tf1.path, tf2.path)
244
+ assert_equal lines, ch.lines # XXX: OK?
245
+ end
246
+
247
+ def test_volume
248
+ content = "abc\ndef"
249
+ tf1 = Tempfile.new('chapter_test1')
250
+ tf1.print content
251
+ tf1.close
252
+ tf2 = Tempfile.new('chapter_test2')
253
+ tf2.print content
254
+ tf2.print content
255
+ tf2.close
256
+
257
+ ch = Book::Chapter.new(nil, nil, nil, tf1.path)
258
+ assert ch.volume
259
+ assert_equal content.gsub(/\s/, '').size, ch.volume.bytes
260
+
261
+ ch = Book::Chapter.new(nil, nil, nil, tf1.path, tf2)
262
+ assert ch.volume
263
+ assert_equal content.gsub(/\s/, '').size, ch.volume.bytes # XXX: OK?
264
+ end
265
+
266
+ def test_on_CHAPS?
267
+ mktmpbookdir 'CHAPS' => "chapter1.re\nchapter2.re",
268
+ 'chapter1.re' => '12345', 'preface.re' => 'abcde' do |dir, book, files|
269
+ ch1 = Book::Chapter.new(book, 1, 'chapter1', files['chapter1.re'])
270
+ pre = Book::Chapter.new(book, nil, 'preface', files['preface.re'])
271
+
272
+ assert ch1.on_CHAPS?
273
+ assert !pre.on_CHAPS?
274
+
275
+ ch2_path = File.join(dir, 'chapter2.er')
276
+ File.open(ch2_path, 'w') {}
277
+ ch2 = Book::Chapter.new(book, 2, 'chapter2', ch2_path)
278
+
279
+ ch3_path = File.join(dir, 'chapter3.er')
280
+ File.open(ch3_path, 'w') {}
281
+ ch3 = Book::Chapter.new(book, 3, 'chapter3', ch3_path)
282
+
283
+ assert ch2.on_CHAPS?
284
+ assert !ch3.on_CHAPS?
285
+ end
286
+ end
287
+
288
+ def test_list_index
289
+ do_test_index(<<E, Book::ListIndex, :list_index, :list)
290
+ //list
291
+ //listnum [abc]
292
+ //list [def]
293
+ //table [def]
294
+ //table [others]
295
+ E
296
+ end
297
+
298
+ def test_table_index
299
+ do_test_index(<<E, Book::TableIndex, :table_index, :table)
300
+ //table
301
+ //table [abc]
302
+ //table [def]
303
+ //list [def]
304
+ //list [others]
305
+ E
306
+ end
307
+
308
+ def test_footnote_index
309
+ content = <<E
310
+ //footnote
311
+ //footnote [abc][text...]
312
+ //footnote [def][text...]
313
+ //footnote [xyz]
314
+ //list [def]
315
+ //list [others]
316
+ E
317
+ do_test_index(content, Book::FootnoteIndex, :footnote_index, :footnote) do |ch|
318
+ assert_raises ReVIEW::KeyError do
319
+ ch.footnote('xyz')
320
+ end
321
+ end
322
+ end
323
+
324
+ def test_bibpaper
325
+ do_test_index(<<E, Book::BibpaperIndex, :bibpaper_index, :bibpaper, :filename => 'bib.re')
326
+ //bibpaper
327
+ //bibpaper [abc][text...]
328
+ //bibpaper [def][text...]
329
+ //bibpaper [xyz]
330
+ //list [def]
331
+ //list [others]
332
+ E
333
+ assert_raises FileNotFound do
334
+ do_test_index('', Book::BibpaperIndex, :bibpaper_index, :bibpaper, :filename => 'bib')
335
+ end
336
+ end
337
+
338
+ def test_headline_index
339
+ do_test_index(<<E, Book::HeadlineIndex, :headline_index, :headline, :propagate => false)
340
+ ==
341
+ == abc
342
+ == def
343
+ === def
344
+ //table others
345
+ E
346
+ end
347
+
348
+
349
+ def test_headline_index_nullsection
350
+ do_test_index(<<E, Book::HeadlineIndex, :headline_index, :headline, :propagate => false)
351
+ == abc
352
+ ==== dummy
353
+ == def
354
+ E
355
+ end
356
+
357
+ def test_image
358
+ do_test_index(<<E, Book::ImageIndex, :image_index, :image)
359
+ //image
360
+ //image [abc]
361
+ //image [def]
362
+ //list [def]
363
+ //list [others]
364
+ E
365
+
366
+ do_test_index(<<E, Book::NumberlessImageIndex, :numberless_image_index, :image, :propagate => false)
367
+ //numberlessimage
368
+ //numberlessimage [abc]
369
+ //numberlessimage [def]
370
+ //list [def]
371
+ //list [others]
372
+ E
373
+
374
+ do_test_index(<<E, Book::ImageIndex, :image_index, :image)
375
+ //image
376
+ //numberlessimage [abc]
377
+ //image [def]
378
+ //list [def]
379
+ //list [others]
380
+ E
381
+
382
+ do_test_index(<<E, Book::NumberlessImageIndex, :numberless_image_index, :image, :propagate => false)
383
+ //image
384
+ //numberlessimage [abc]
385
+ //image [def]
386
+ //list [def]
387
+ //list [others]
388
+ E
389
+ end
390
+
391
+ def do_test_index(content, klass, list_method, ref_method, opts = {})
392
+ Dir.mktmpdir do |dir|
393
+ path = File.join(dir, opts[:filename] || 'chapter.re')
394
+
395
+ book = Book::Base.new(dir)
396
+
397
+ ch = nil
398
+ File.open(path, 'w') do |o|
399
+ o.print content
400
+ ch = Book::Chapter.new(book, 1, 'chapter', o.path)
401
+ end
402
+
403
+ assert ch.__send__(ref_method, 'abc')
404
+ assert ch.__send__(ref_method, 'def')
405
+ assert_raises ReVIEW::KeyError do
406
+ ch.__send__(ref_method, nil)
407
+ end
408
+ assert_raises ReVIEW::KeyError do
409
+ ch.__send__(ref_method, 'others')
410
+ end
411
+ assert_raises ReVIEW::KeyError do
412
+ ch.__send__(ref_method, 'not exist id')
413
+ end
414
+
415
+ yield(ch) if block_given?
416
+ end
417
+ end
418
+ end
@@ -0,0 +1,42 @@
1
+ require 'book_test_helper'
2
+
3
+ class ParametersTest < Test::Unit::TestCase
4
+ include BookTestHelper
5
+
6
+ def test_s_default
7
+ assert Book::Parameters.default
8
+ end
9
+
10
+ def test_s_load
11
+ Tempfile.open('parameters_test') do |io|
12
+ io.puts 'CHAPS_FILE = "x_CHAPS"'
13
+ io.puts 'PAPER = "B5"' # XXX: avoid erros of the last line of Parameters.get_page_metric
14
+ io.close
15
+
16
+ params = Book::Parameters.load(io.path)
17
+ assert_equal '/x_CHAPS', params.chapter_file # XXX: OK? (leading / and uninitialized @basedir)
18
+ assert_equal '/PART', params.part_file
19
+ end
20
+ end
21
+
22
+ def test_s_get_page_metric
23
+ mod = Module.new
24
+ assert_raises ArgumentError do # XXX: OK?
25
+ params = Book::Parameters.get_page_metric(mod)
26
+ assert params
27
+ end
28
+
29
+ mod = Module.new
30
+ mod.module_eval { const_set(:PAPER, 'A5') }
31
+ assert_nothing_raised do
32
+ params = Book::Parameters.get_page_metric(mod)
33
+ assert params
34
+ end
35
+
36
+ mod = Module.new
37
+ mod.module_eval { const_set(:PAPER, 'X5') }
38
+ assert_raises ConfigError do
39
+ Book::Parameters.get_page_metric(mod)
40
+ end
41
+ end
42
+ end