tmtms-review 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +9 -0
  3. data/COPYING +515 -0
  4. data/ChangeLog +2083 -0
  5. data/README.rdoc +50 -0
  6. data/Rakefile +56 -0
  7. data/VERSION +1 -0
  8. data/bin/review-check +178 -0
  9. data/bin/review-checkdep +63 -0
  10. data/bin/review-compile +205 -0
  11. data/bin/review-epubmaker +661 -0
  12. data/bin/review-epubmaker-ng +176 -0
  13. data/bin/review-index +118 -0
  14. data/bin/review-pdfmaker +208 -0
  15. data/bin/review-preproc +142 -0
  16. data/bin/review-validate +51 -0
  17. data/bin/review-vol +102 -0
  18. data/debian/README.Debian +12 -0
  19. data/debian/README.source +5 -0
  20. data/debian/changelog +5 -0
  21. data/debian/compat +1 -0
  22. data/debian/control +22 -0
  23. data/debian/copyright +62 -0
  24. data/debian/docs +6 -0
  25. data/debian/manpage.1.ex +59 -0
  26. data/debian/patches/path.diff +91 -0
  27. data/debian/patches/series +1 -0
  28. data/debian/review.install +13 -0
  29. data/debian/review.links +4 -0
  30. data/debian/rules +13 -0
  31. data/debian/source/format +1 -0
  32. data/doc/format.rdoc +582 -0
  33. data/doc/format_idg.rdoc +180 -0
  34. data/doc/libepubmaker/sample.yaml +90 -0
  35. data/doc/quickstart.rdoc +188 -0
  36. data/doc/ruby-uuid/README +11 -0
  37. data/doc/ruby-uuid/README.ja +34 -0
  38. data/doc/sample.css +108 -0
  39. data/doc/sample.yaml +62 -0
  40. data/lib/epubmaker.rb +28 -0
  41. data/lib/epubmaker/content.rb +82 -0
  42. data/lib/epubmaker/epubv2.rb +418 -0
  43. data/lib/epubmaker/epubv3.rb +249 -0
  44. data/lib/epubmaker/producer.rb +204 -0
  45. data/lib/epubmaker/resource.rb +66 -0
  46. data/lib/lineinput.rb +155 -0
  47. data/lib/review.rb +3 -0
  48. data/lib/review/book.rb +46 -0
  49. data/lib/review/book/base.rb +235 -0
  50. data/lib/review/book/chapter.rb +81 -0
  51. data/lib/review/book/compilable.rb +159 -0
  52. data/lib/review/book/index.rb +339 -0
  53. data/lib/review/book/page_metric.rb +38 -0
  54. data/lib/review/book/parameters.rb +97 -0
  55. data/lib/review/book/part.rb +44 -0
  56. data/lib/review/book/volume.rb +65 -0
  57. data/lib/review/builder.rb +444 -0
  58. data/lib/review/compiler.rb +550 -0
  59. data/lib/review/configure.rb +38 -0
  60. data/lib/review/epubbuilder.rb +18 -0
  61. data/lib/review/exception.rb +21 -0
  62. data/lib/review/extentions.rb +3 -0
  63. data/lib/review/extentions/object.rb +9 -0
  64. data/lib/review/extentions/string.rb +33 -0
  65. data/lib/review/htmlbuilder.rb +1097 -0
  66. data/lib/review/htmllayout.rb +19 -0
  67. data/lib/review/htmlutils.rb +36 -0
  68. data/lib/review/i18n.rb +30 -0
  69. data/lib/review/i18n.yaml +34 -0
  70. data/lib/review/idgxmlbuilder.rb +1145 -0
  71. data/lib/review/latexbuilder.rb +815 -0
  72. data/lib/review/latexindex.rb +35 -0
  73. data/lib/review/latexutils.rb +79 -0
  74. data/lib/review/preprocessor.rb +563 -0
  75. data/lib/review/review.tex.erb +232 -0
  76. data/lib/review/textbuilder.rb +17 -0
  77. data/lib/review/textutils.rb +66 -0
  78. data/lib/review/tocparser.rb +342 -0
  79. data/lib/review/tocprinter.rb +221 -0
  80. data/lib/review/topbuilder.rb +785 -0
  81. data/lib/review/unfold.rb +138 -0
  82. data/lib/uuid.rb +312 -0
  83. data/review.gemspec +141 -0
  84. data/test/CHAPS +2 -0
  85. data/test/bib.re +13 -0
  86. data/test/book_test_helper.rb +35 -0
  87. data/test/test.re +43 -0
  88. data/test/test_book.rb +598 -0
  89. data/test/test_book_chapter.rb +418 -0
  90. data/test/test_book_parameter.rb +42 -0
  91. data/test/test_book_part.rb +50 -0
  92. data/test/test_builder.rb +144 -0
  93. data/test/test_compiler.rb +44 -0
  94. data/test/test_epubmaker.rb +507 -0
  95. data/test/test_helper.rb +27 -0
  96. data/test/test_htmlbuilder.rb +554 -0
  97. data/test/test_htmlutils.rb +28 -0
  98. data/test/test_i18n.rb +64 -0
  99. data/test/test_idgxmlbuilder.rb +589 -0
  100. data/test/test_index.rb +31 -0
  101. data/test/test_latexbuilder.rb +656 -0
  102. data/test/test_lineinput.rb +198 -0
  103. data/test/test_preprocessor.rb +23 -0
  104. data/test/test_textutils.rb +68 -0
  105. data/test/test_topbuilder.rb +244 -0
  106. data/test/test_uuid.rb +156 -0
  107. metadata +161 -0
@@ -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