review-peg 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +36 -0
  3. data/.rubocop.yml +47 -0
  4. data/.rubocop_todo.yml +605 -0
  5. data/.travis.yml +18 -0
  6. data/COPYING +515 -0
  7. data/ChangeLog +2449 -0
  8. data/Dockerfile +22 -0
  9. data/Gemfile +6 -0
  10. data/README.rdoc +81 -0
  11. data/Rakefile +51 -0
  12. data/bin/review-catalog-converter-peg +129 -0
  13. data/bin/review-check-peg +169 -0
  14. data/bin/review-checkdep-peg +63 -0
  15. data/bin/review-compile-peg +202 -0
  16. data/bin/review-epubmaker-legacy-peg +1024 -0
  17. data/bin/review-epubmaker-peg +44 -0
  18. data/bin/review-index-peg +110 -0
  19. data/bin/review-init-peg +151 -0
  20. data/bin/review-pdfmaker-peg +18 -0
  21. data/bin/review-preproc-peg +131 -0
  22. data/bin/review-validate-peg +51 -0
  23. data/bin/review-vol-peg +100 -0
  24. data/debian/README.Debian +12 -0
  25. data/debian/README.source +5 -0
  26. data/debian/changelog +5 -0
  27. data/debian/compat +1 -0
  28. data/debian/control +22 -0
  29. data/debian/copyright +62 -0
  30. data/debian/docs +6 -0
  31. data/debian/manpage.1.ex +59 -0
  32. data/debian/patches/path.diff +91 -0
  33. data/debian/patches/series +1 -0
  34. data/debian/review.install +13 -0
  35. data/debian/review.links +4 -0
  36. data/debian/rules +13 -0
  37. data/debian/source/format +1 -0
  38. data/doc/NEWS.ja.md +350 -0
  39. data/doc/NEWS.md +354 -0
  40. data/doc/catalog.ja.md +53 -0
  41. data/doc/catalog.md +52 -0
  42. data/doc/format.ja.md +734 -0
  43. data/doc/format.md +746 -0
  44. data/doc/format_idg.ja.md +203 -0
  45. data/doc/quickstart.ja.md +222 -0
  46. data/doc/quickstart.md +252 -0
  47. data/doc/ruby-uuid/README +11 -0
  48. data/doc/ruby-uuid/README.ja +34 -0
  49. data/doc/sample.css +108 -0
  50. data/doc/sample.yml +238 -0
  51. data/lib/epubmaker.rb +24 -0
  52. data/lib/epubmaker/content.rb +93 -0
  53. data/lib/epubmaker/epubcommon.rb +424 -0
  54. data/lib/epubmaker/epubv2.rb +139 -0
  55. data/lib/epubmaker/epubv3.rb +222 -0
  56. data/lib/epubmaker/producer.rb +330 -0
  57. data/lib/lineinput.rb +107 -0
  58. data/lib/review.rb +3 -0
  59. data/lib/review/book.rb +43 -0
  60. data/lib/review/book/base.rb +401 -0
  61. data/lib/review/book/chapter.rb +100 -0
  62. data/lib/review/book/compilable.rb +184 -0
  63. data/lib/review/book/image_finder.rb +71 -0
  64. data/lib/review/book/index.rb +413 -0
  65. data/lib/review/book/page_metric.rb +47 -0
  66. data/lib/review/book/part.rb +54 -0
  67. data/lib/review/book/volume.rb +67 -0
  68. data/lib/review/builder.rb +452 -0
  69. data/lib/review/catalog.rb +52 -0
  70. data/lib/review/compiler.rb +5183 -0
  71. data/lib/review/compiler/literals_1_9.kpeg +22 -0
  72. data/lib/review/compiler/literals_1_9.rb +435 -0
  73. data/lib/review/configure.rb +64 -0
  74. data/lib/review/epubbuilder.rb +18 -0
  75. data/lib/review/epubmaker.rb +480 -0
  76. data/lib/review/ewbbuilder.rb +381 -0
  77. data/lib/review/exception.rb +21 -0
  78. data/lib/review/extentions.rb +4 -0
  79. data/lib/review/extentions/array.rb +25 -0
  80. data/lib/review/extentions/object.rb +9 -0
  81. data/lib/review/extentions/string.rb +33 -0
  82. data/lib/review/htmlbuilder.rb +1166 -0
  83. data/lib/review/htmllayout.rb +41 -0
  84. data/lib/review/htmltoc.rb +45 -0
  85. data/lib/review/htmlutils.rb +90 -0
  86. data/lib/review/i18n.rb +96 -0
  87. data/lib/review/i18n.yml +169 -0
  88. data/lib/review/idgxmlbuilder.rb +1233 -0
  89. data/lib/review/inaobuilder.rb +357 -0
  90. data/lib/review/latexbuilder.rb +941 -0
  91. data/lib/review/latexindex.rb +35 -0
  92. data/lib/review/latexutils.rb +95 -0
  93. data/lib/review/layout.tex.erb +340 -0
  94. data/lib/review/lineinput.rb +17 -0
  95. data/lib/review/location.rb +24 -0
  96. data/lib/review/makerhelper.rb +67 -0
  97. data/lib/review/markdownbuilder.rb +339 -0
  98. data/lib/review/node.rb +288 -0
  99. data/lib/review/pdfmaker.rb +332 -0
  100. data/lib/review/preprocessor.rb +530 -0
  101. data/lib/review/review.kpeg +745 -0
  102. data/lib/review/sec_counter.rb +69 -0
  103. data/lib/review/template.rb +21 -0
  104. data/lib/review/textbuilder.rb +17 -0
  105. data/lib/review/textutils.rb +16 -0
  106. data/lib/review/tocparser.rb +348 -0
  107. data/lib/review/tocprinter.rb +205 -0
  108. data/lib/review/topbuilder.rb +796 -0
  109. data/lib/review/unfold.rb +138 -0
  110. data/lib/review/version.rb +3 -0
  111. data/lib/uuid.rb +312 -0
  112. data/review.gemspec +32 -0
  113. data/templates/html/layout-html5.html.erb +17 -0
  114. data/templates/html/layout-xhtml1.html.erb +20 -0
  115. data/templates/ncx/epubv2.ncx.erb +11 -0
  116. data/templates/opf/epubv2.opf.erb +21 -0
  117. data/templates/opf/epubv3.opf.erb +18 -0
  118. data/templates/xml/container.xml.erb +6 -0
  119. data/test/CHAPS +2 -0
  120. data/test/assets/test.xml.erb +3 -0
  121. data/test/assets/test_template.tex +255 -0
  122. data/test/assets/test_template_backmatter.tex +32 -0
  123. data/test/bib.re +13 -0
  124. data/test/book_test_helper.rb +35 -0
  125. data/test/sample-book/README.md +7 -0
  126. data/test/sample-book/src/Rakefile +58 -0
  127. data/test/sample-book/src/_cover.html +3 -0
  128. data/test/sample-book/src/catalog.yml +10 -0
  129. data/test/sample-book/src/ch01.re +71 -0
  130. data/test/sample-book/src/ch02.re +3 -0
  131. data/test/sample-book/src/config.yml +186 -0
  132. data/test/sample-book/src/images/ch01-imgsample.jpg +0 -0
  133. data/test/sample-book/src/images/cover.jpg +0 -0
  134. data/test/sample-book/src/preface.re +15 -0
  135. data/test/sample-book/src/sty/jumoline.sty +310 -0
  136. data/test/sample-book/src/sty/reviewmacro.sty +39 -0
  137. data/test/sample-book/src/style.css +251 -0
  138. data/test/sample-book/src/vendor/jumoline/README +29 -0
  139. data/test/sample-book/src/vendor/jumoline/jumoline.dtx +2988 -0
  140. data/test/sample-book/src/vendor/jumoline/jumoline.ins +6 -0
  141. data/test/test.re +43 -0
  142. data/test/test_book.rb +556 -0
  143. data/test/test_book_chapter.rb +280 -0
  144. data/test/test_book_part.rb +54 -0
  145. data/test/test_builder.rb +80 -0
  146. data/test/test_catalog.rb +119 -0
  147. data/test/test_catalog_converter_cmd.rb +73 -0
  148. data/test/test_compiler.rb +92 -0
  149. data/test/test_configure.rb +50 -0
  150. data/test/test_epub3maker.rb +529 -0
  151. data/test/test_epubmaker.rb +569 -0
  152. data/test/test_epubmaker_cmd.rb +40 -0
  153. data/test/test_helper.rb +92 -0
  154. data/test/test_htmlbuilder.rb +1114 -0
  155. data/test/test_htmltoc.rb +32 -0
  156. data/test/test_htmlutils.rb +50 -0
  157. data/test/test_i18n.rb +180 -0
  158. data/test/test_idgxmlbuilder.rb +608 -0
  159. data/test/test_image_finder.rb +82 -0
  160. data/test/test_inaobuilder.rb +245 -0
  161. data/test/test_index.rb +174 -0
  162. data/test/test_latexbuilder.rb +732 -0
  163. data/test/test_lineinput.rb +182 -0
  164. data/test/test_makerhelper.rb +66 -0
  165. data/test/test_markdownbuilder.rb +125 -0
  166. data/test/test_pdfmaker.rb +171 -0
  167. data/test/test_pdfmaker_cmd.rb +40 -0
  168. data/test/test_preprocessor.rb +23 -0
  169. data/test/test_review_ext.rb +31 -0
  170. data/test/test_template.rb +26 -0
  171. data/test/test_textutils.rb +32 -0
  172. data/test/test_topbuilder.rb +291 -0
  173. data/test/test_uuid.rb +157 -0
  174. metadata +357 -0
@@ -0,0 +1,6 @@
1
+ \input docstrip.tex
2
+ \keepsilent
3
+ \askonceonly
4
+ \generate{\file{jumoline.sty}{\from{jumoline.dtx}{package}}
5
+ \file{jumoline-man.tex}{\from{jumoline.dtx}{driver}}}
6
+ \endbatchfile
data/test/test.re ADDED
@@ -0,0 +1,43 @@
1
+ = 見出し
2
+ 以下を実行
3
+ //emlist{
4
+ ./bin/review-compile --hdnumberingmode test.re --target=html
5
+ }
6
+ == 節1
7
+
8
+ == 節2
9
+
10
+ ==[column]コラム
11
+
12
+ == 節3
13
+
14
+ ソースコードの引用
15
+
16
+ //source[/hello/world.rb]{
17
+ puts "hello world!"
18
+ //}
19
+
20
+ ■行番号付きキャプションなしリスト
21
+ //emlistnum{
22
+ hoge
23
+ fuge
24
+ //}
25
+
26
+ ■行番号付きキャプションありリスト
27
+ //listnum[hoge][ほげ]{
28
+ hoge
29
+ fuge
30
+ //}
31
+
32
+ ほげは@<list>{hoge}でもわかるとおり
33
+
34
+ ■本文中でのソースコード引用
35
+ 擬似コード内のの@<code>{p = obj.ref_cnt}では…
36
+
37
+ ■参考文献の参照方法
38
+ …がしられています( @<bib>{lins} )
39
+
40
+
41
+ //emlist{
42
+ hoge
43
+ //}
data/test/test_book.rb ADDED
@@ -0,0 +1,556 @@
1
+ # encoding: utf-8
2
+ require 'book_test_helper'
3
+
4
+ class BookTest < Test::Unit::TestCase
5
+ include BookTestHelper
6
+
7
+ def assert_same_path(expected, result, *options)
8
+ require 'pathname'
9
+ ex_path = Pathname(expected).realpath
10
+ re_path = Pathname(result).realpath
11
+ assert_equal ex_path, re_path, *options
12
+ end
13
+
14
+ def test_s_update_rubyenv
15
+ save_load_path = $LOAD_PATH.dup
16
+
17
+ Dir.mktmpdir do |dir|
18
+ Book.update_rubyenv(dir)
19
+ assert_equal save_load_path, $LOAD_PATH
20
+ end
21
+
22
+ Dir.mktmpdir do |dir|
23
+ local_lib_path = File.join(dir, 'lib')
24
+ Dir.mkdir(local_lib_path)
25
+ Book.update_rubyenv(dir)
26
+ assert_equal save_load_path, $LOAD_PATH
27
+ end
28
+
29
+ num = rand(99999)
30
+ test_const = "ReVIEW__BOOK__TEST__#{num}"
31
+ begin
32
+ Dir.mktmpdir do |dir|
33
+ File.open(File.join(dir, 'review-ext.rb'), 'w') do |o|
34
+ o.puts "#{test_const} = #{num}"
35
+ end
36
+ Book.update_rubyenv(dir)
37
+ assert_equal num, Object.class_eval { const_get(test_const) }
38
+ end
39
+ ensure
40
+ Object.class_eval { remove_const(test_const) }
41
+ end
42
+ end
43
+
44
+ def test_ext
45
+ book = Book::Base.new(File.dirname(__FILE__))
46
+ assert_equal '.re', book.ext
47
+ end
48
+
49
+ def test_read_CHAPS
50
+ Dir.mktmpdir do |dir|
51
+ book = Book::Base.new(dir)
52
+ assert_equal "", book.read_CHAPS
53
+
54
+ chaps_path = File.join(dir, 'CHAPS')
55
+ re1_path = File.join(dir, "123#{book.ext}")
56
+ re2_path = File.join(dir, "456#{book.ext}")
57
+
58
+ File.open(chaps_path, 'w') {|o| o.print "abc\n" }
59
+ File.open(re1_path, 'w') {|o| o.print "123\n" }
60
+ File.open(re2_path, 'w') {|o| o.print "456\n" }
61
+
62
+ assert_equal "abc\n", book.read_CHAPS
63
+
64
+ File.unlink(chaps_path)
65
+ assert_equal "#{re1_path}\n#{re2_path}", book.read_CHAPS
66
+
67
+ File.unlink(re1_path)
68
+ assert_equal "#{re2_path}", book.read_CHAPS
69
+
70
+ File.unlink(re2_path)
71
+ assert_equal "", book.read_CHAPS
72
+ end
73
+ end
74
+
75
+ def test_read_PART
76
+ Dir.mktmpdir do |dir|
77
+ book = Book::Base.new(dir)
78
+ assert !book.part_exist?
79
+ assert_raises Errno::ENOENT do # XXX: OK?
80
+ book.read_PART
81
+ end
82
+
83
+ chaps_path = File.join(dir, 'PART')
84
+ chaps_content = "abc\n"
85
+ File.open(chaps_path, 'w') {|o| o.print chaps_content }
86
+
87
+ assert book.part_exist?
88
+ assert_equal chaps_content, book.read_PART
89
+
90
+ File.open(chaps_path, 'w') {|o| o.print "XYZ\n" }
91
+ assert_equal chaps_content, book.read_PART
92
+ end
93
+ end
94
+
95
+ def test_read_APPENDIX
96
+ Dir.mktmpdir do |dir|
97
+ book = Book::Base.new(dir)
98
+ assert_equal "", book.read_APPENDIX
99
+
100
+ post_path = File.join(dir, 'POSTDEF')
101
+ re1_path = File.join(dir, "123#{book.ext}")
102
+ re2_path = File.join(dir, "456#{book.ext}")
103
+
104
+ File.open(post_path, 'w') {|o| o.print "abc\n" }
105
+ File.open(re1_path, 'w') {|o| o.print "123\n" }
106
+ File.open(re2_path, 'w') {|o| o.print "456\n" }
107
+
108
+ assert_equal "abc\n", book.read_APPENDIX
109
+
110
+ File.unlink(post_path)
111
+ assert_equal "#{re1_path}\n#{re2_path}", book.read_APPENDIX
112
+
113
+ File.unlink(re1_path)
114
+ assert_equal "#{re2_path}", book.read_APPENDIX
115
+
116
+ File.unlink(re2_path)
117
+ assert_equal "", book.read_APPENDIX
118
+ end
119
+ end
120
+
121
+ def test_read_POSTDEF
122
+ Dir.mktmpdir do |dir|
123
+ book = Book::Base.new(dir)
124
+ assert_equal "", book.read_POSTDEF
125
+
126
+ post_path = File.join(dir, 'POSTDEF')
127
+ re1_path = File.join(dir, "123#{book.ext}")
128
+ re2_path = File.join(dir, "456#{book.ext}")
129
+
130
+ File.open(post_path, 'w') {|o| o.print "abc\n" }
131
+ File.open(re1_path, 'w') {|o| o.print "123\n" }
132
+ File.open(re2_path, 'w') {|o| o.print "456\n" }
133
+
134
+ assert_equal "", book.read_POSTDEF
135
+
136
+ File.unlink(post_path)
137
+ assert_equal "", book.read_POSTDEF
138
+ end
139
+ end
140
+
141
+ def test_read_bib
142
+ Dir.mktmpdir do |dir|
143
+ book = Book::Base.new(dir)
144
+ assert !book.bib_exist?
145
+ assert_raises Errno::ENOENT do # XXX: OK?
146
+ book.read_bib
147
+ end
148
+
149
+ bib_path = File.join(dir, "bib#{book.ext}")
150
+ File.open(bib_path, 'w') {|o| o.print "abc\n" }
151
+
152
+ assert book.bib_exist?
153
+ assert_equal "abc\n", book.read_bib
154
+ end
155
+ end
156
+
157
+ # backword compatible
158
+ def test_setParameter
159
+ book = Book::Base.new(File.dirname(__FILE__))
160
+ book.param = :test
161
+ assert_equal :test, book.param # old way
162
+ assert_equal :test, book.config # new way
163
+ end
164
+
165
+ def test_setConfig
166
+ book = Book::Base.new(File.dirname(__FILE__))
167
+ book.config = :test
168
+ assert_equal :test, book.param # old way
169
+ assert_equal :test, book.config # new way
170
+ end
171
+
172
+ def test_parse_chapters
173
+ mktmpbookdir 'CHAPS' => '' do |dir, book, files|
174
+ parts = book.instance_eval { parse_chapters }
175
+ assert_equal 0, parts.size
176
+ end
177
+
178
+ mktmpbookdir 'CHAPS' => "chapter1.re\nchapter2\n" do |dir, book, files|
179
+ parts = book.instance_eval { parse_chapters }
180
+ assert_equal 1, parts.size
181
+
182
+ assert_equal 1, parts[0].number
183
+ assert_equal 2, parts[0].chapters.size
184
+ chaps = parts[0].chapters.map {|ch| [ch.number, ch.name, ch.path] }
185
+ expect = [
186
+ [1, 'chapter1', File.join(dir, 'chapter1.re')],
187
+ [2, 'chapter2', File.join(dir, 'chapter2')],
188
+ ]
189
+ assert_equal expect, chaps
190
+ end
191
+
192
+ mktmpbookdir 'CHAPS' => <<EOC do |dir, book, files|
193
+ part1_chapter1.re
194
+ part1_chapter2.re
195
+
196
+
197
+ part2_chapter1.re
198
+ part2_chapter2.re
199
+ part2_chapter3.re
200
+
201
+ part3_chapter1.re
202
+ EOC
203
+ parts = book.instance_eval { parse_chapters }
204
+ assert_equal 3, parts.size
205
+
206
+ assert_equal 1, parts[0].number
207
+ assert_equal 2, parts[0].chapters.size
208
+ chaps = parts[0].chapters.map {|ch| [ch.number, ch.name, ch.path] }
209
+ expect = [
210
+ [1, 'part1_chapter1', File.join(dir, 'part1_chapter1.re')],
211
+ [2, 'part1_chapter2', File.join(dir, 'part1_chapter2.re')],
212
+ ]
213
+ assert_equal expect, chaps
214
+
215
+ assert_equal 2, parts[1].number
216
+ assert_equal 3, parts[1].chapters.size
217
+ chaps = parts[1].chapters.map {|ch| [ch.number, ch.name, ch.path] }
218
+ expect = [
219
+ [3, 'part2_chapter1', File.join(dir, 'part2_chapter1.re')],
220
+ [4, 'part2_chapter2', File.join(dir, 'part2_chapter2.re')],
221
+ [5, 'part2_chapter3', File.join(dir, 'part2_chapter3.re')],
222
+ ]
223
+ assert_equal expect, chaps
224
+
225
+ assert_equal 3, parts[2].number
226
+ assert_equal 1, parts[2].chapters.size
227
+ chaps = parts[2].chapters.map {|ch| [ch.number, ch.name, ch.path] }
228
+ expect = [
229
+ [6, 'part3_chapter1', File.join(dir, 'part3_chapter1.re')],
230
+ ]
231
+ assert_equal expect, chaps
232
+ end
233
+ end
234
+
235
+ def test_parse_chpaters_with_parts_file
236
+ n_test = 0
237
+ [
238
+ [
239
+ # 期待されるパートの数, :chapter_fileの内容, :part_fileの内容, 期待されるパートタイトルのリスト
240
+ 2,
241
+ "part1_chapter1.re\n\npart2_chpater1.re\n",
242
+ "part1\npart2\npart3\n",
243
+ %w(part1 part2),
244
+ ],
245
+ [
246
+ 3,
247
+ "part1_chapter1.re\n\npart2_chapter1.re\n\npart3_chapter1.re",
248
+ "part1\n",
249
+ [
250
+ "part1",
251
+ nil, # XXX: OK?
252
+ ""
253
+ ],
254
+ ],
255
+ [
256
+ 1,
257
+ "part1_chapter1.re\n",
258
+ "",
259
+ [
260
+ nil, # XXX: OK?
261
+ ],
262
+ ],
263
+ [
264
+ 1,
265
+ "part1_chapter1.re\n",
266
+ nil,
267
+ [
268
+ "",
269
+ ],
270
+ ],
271
+ ].each do |n_parts, chaps_text, parts_text, part_names|
272
+ n_test += 1
273
+ Dir.mktmpdir do |dir|
274
+ book = Book::Base.new(dir)
275
+ chaps_path = File.join(dir, 'CHAPS')
276
+ File.open(chaps_path, 'w') {|o| o.print chaps_text }
277
+ unless parts_text.nil?
278
+ parts_path = File.join(dir, 'PART')
279
+ File.open(parts_path, 'w') {|o| o.print parts_text }
280
+ end
281
+
282
+ parts = book.instance_eval { parse_chapters }
283
+ assert_equal n_parts, parts.size, "\##{n_test}"
284
+ assert_equal part_names, parts.map {|p| p.name }, "\##{n_test}"
285
+ end
286
+ end
287
+ end
288
+
289
+ def test_prefaces
290
+ mktmpbookdir do |dir, book, files|
291
+ assert_equal nil, book.prefaces
292
+ end
293
+
294
+ mktmpbookdir 'PREDEF' => '' do |dir, book, files|
295
+ assert_equal nil, book.prefaces # XXX: OK?
296
+ end
297
+
298
+ mktmpbookdir 'PREDEF' => 'chapter1',
299
+ 'chapter1.re' => '' do |dir, book, files|
300
+ assert_kind_of Book::Part, book.prefaces
301
+ assert_equal '', book.prefaces.name
302
+ assert_equal 1, book.prefaces.chapters.size
303
+ assert_equal "chapter1", book.prefaces.chapters.first.name
304
+ assert_equal files['chapter1.re'], book.prefaces.chapters.first.path
305
+ end
306
+
307
+ mktmpbookdir 'PREDEF' => "chapter1\n\nchapter2",
308
+ 'chapter1.re' => '', 'chapter2.re' => '' do |dir, book, files|
309
+ assert_kind_of Book::Part, book.prefaces
310
+ assert_equal '', book.prefaces.name
311
+ assert_equal 2, book.prefaces.chapters.size
312
+ assert_equal "chapter1", book.prefaces.chapters.first.name
313
+ assert_equal files['chapter1.re'], book.prefaces.chapters.first.path
314
+ assert_equal "chapter2", book.prefaces.chapters.last.name
315
+ assert_equal files['chapter2.re'], book.prefaces.chapters.last.path
316
+ end
317
+
318
+ mktmpbookdir 'PREDEF' => "chapter1 chapter2",
319
+ 'chapter1.re' => '', 'chapter2.re' => '' do |dir, book, files|
320
+ assert_kind_of Book::Part, book.prefaces
321
+ assert_equal '', book.prefaces.name
322
+ assert_equal 2, book.prefaces.chapters.size # XXX: OK?
323
+ end
324
+
325
+ mktmpbookdir 'PREDEF' => 'not_exist' do |dir, book, files|
326
+ assert_raises FileNotFound do
327
+ assert_equal nil, book.prefaces
328
+ end
329
+ end
330
+
331
+ mktmpbookdir 'PREDEF' => 'chapter1.re',
332
+ 'chapter1.re' => '' do |dir, book, files|
333
+ assert_kind_of Book::Part, book.prefaces
334
+ assert_equal '', book.prefaces.name
335
+ assert_equal 1, book.prefaces.chapters.size
336
+ end
337
+
338
+ mktmpbookdir 'PREDEF' => 'chapter1.txt',
339
+ 'chapter1.txt' => '' do |dir, book, files|
340
+ assert_kind_of Book::Part, book.prefaces
341
+ assert_equal '', book.prefaces.name
342
+ assert_equal 1, book.prefaces.chapters.size
343
+ end
344
+ end
345
+
346
+ def test_appendix
347
+ mktmpbookdir do |dir, book, files|
348
+ assert_equal nil, book.appendix
349
+ end
350
+
351
+ mktmpbookdir 'POSTDEF' => '' do |dir, book, files|
352
+ assert_equal nil, book.appendix
353
+ end
354
+
355
+ mktmpbookdir 'POSTDEF' => 'chapter1',
356
+ 'chapter1.re' => '' do |dir, book, files|
357
+ assert_kind_of Book::Part, book.appendix
358
+ assert_equal '', book.appendix.name
359
+ assert_equal 1, book.appendix.chapters.size
360
+ assert_equal "chapter1", book.appendix.chapters.first.name
361
+ assert_equal files['chapter1.re'], book.appendix.chapters.first.path
362
+ assert_equal 1, book.appendix.chapters.first.number
363
+ end
364
+
365
+ mktmpbookdir 'POSTDEF' => "chapter1\n\nchapter2",
366
+ 'chapter1.re' => '', 'chapter2.re' => '' do |dir, book, files|
367
+ assert_kind_of Book::Part, book.appendix
368
+ assert_equal '', book.appendix.name
369
+ assert_equal 2, book.appendix.chapters.size
370
+ assert_equal "chapter1", book.appendix.chapters.first.name
371
+ assert_equal files['chapter1.re'], book.appendix.chapters.first.path
372
+ assert_equal "chapter2", book.appendix.chapters.last.name
373
+ assert_equal files['chapter2.re'], book.appendix.chapters.last.path
374
+ assert_equal 1, book.appendix.chapters.first.number
375
+ assert_equal 2, book.appendix.chapters.last.number
376
+ end
377
+
378
+ mktmpbookdir 'POSTDEF' => "chapter1 chapter2",
379
+ 'chapter1.re' => '', 'chapter2.re' => '' do |dir, book, files|
380
+ assert_kind_of Book::Part, book.appendix
381
+ assert_equal '', book.appendix.name
382
+ assert_equal 2, book.appendix.chapters.size # XXX: OK?
383
+ assert_equal 1, book.appendix.chapters.first.number
384
+ assert_equal 2, book.appendix.chapters.last.number
385
+ end
386
+
387
+ mktmpbookdir 'POSTDEF' => 'not_exist' do |dir, book, files|
388
+ assert_raises FileNotFound do
389
+ assert_equal nil, book.appendix
390
+ end
391
+ end
392
+
393
+ mktmpbookdir 'catalog.yml' => "APPENDIX:\n - p01.re",
394
+ 'p01.re' => '= appendix' do |dir, book, files|
395
+ assert_equal 'appendix', book.appendix.chapters.first.title
396
+ assert_equal 1, book.appendix.chapters.first.number
397
+ end
398
+ end
399
+
400
+ def test_postscripts
401
+ mktmpbookdir 'catalog.yml' => "POSTDEF:\n - b01.re",
402
+ 'b01.re' => '= back' do |dir, book, files|
403
+ assert_kind_of Book::Part, book.postscripts
404
+ assert_equal 1, book.postscripts.chapters.size
405
+ assert_equal 'back', book.postscripts.chapters.first.title
406
+ assert_equal nil, book.postscripts.chapters.first.number
407
+ end
408
+ end
409
+
410
+ def test_parts
411
+ mktmpbookdir do |dir, book, files|
412
+ assert book.parts.empty?
413
+ assert !book.part(0)
414
+ assert !book.part(1)
415
+
416
+ tmp = []
417
+ book.each_part { tmp << true }
418
+ assert tmp.empty?
419
+ end
420
+
421
+ mktmpbookdir 'CHAPS' => "ch1\nch2\n\nch3" do |dir, book, files|
422
+ parts = book.parts
423
+ assert_equal 2, parts.size
424
+ assert !book.part(0)
425
+ assert book.part(1)
426
+ assert book.part(2)
427
+ assert !book.part(3)
428
+
429
+ tmp = []
430
+ book.each_part {|p| tmp << p.number }
431
+ assert_equal [1, 2], tmp
432
+ end
433
+ end
434
+
435
+ def test_chapters
436
+ mktmpbookdir 'CHAPS' => "ch1\nch2\n\nch3" do |dir, book, files|
437
+ chapters = book.chapters
438
+ assert_equal 3, chapters.size
439
+
440
+ ch_names = %w(ch1 ch2 ch3)
441
+ tmp = []
442
+ book.each_chapter {|ch| tmp << ch.name }
443
+ assert_equal ch_names, tmp
444
+
445
+ ch_names.each do |name|
446
+ assert book.chapter(name)
447
+ assert_equal name, book.chapter(name).name
448
+ end
449
+
450
+ assert_raises ReVIEW::KeyError do
451
+ book.chapter('not exist')
452
+ end
453
+ end
454
+
455
+ mktmpbookdir 'CHAPS' => "ch1.txt\nch2.txt\n\nch3.txt" do |dir, book, files|
456
+ chapters = book.chapters
457
+ assert_equal 3, chapters.size
458
+
459
+ ch_names = %w(ch1 ch2 ch3)
460
+ tmp = []
461
+ book.each_chapter {|ch| tmp << ch.name }
462
+ assert_equal ch_names, tmp
463
+
464
+ ch_names.each do |name|
465
+ assert book.chapter(name)
466
+ assert_equal name, book.chapter(name).name
467
+ end
468
+
469
+ assert_raises ReVIEW::KeyError do
470
+ book.chapter('not exist')
471
+ end
472
+ end
473
+ end
474
+
475
+ def test_next_chapter
476
+ mktmpbookdir 'CHAPS' => "ch1\nch2" do |dir, book, files|
477
+ chapter = book.chapter('ch1')
478
+ assert_equal book.chapter('ch2'), book.next_chapter(chapter)
479
+
480
+ chapter = book.chapter('ch2')
481
+ assert_equal nil, book.next_chapter(chapter)
482
+ end
483
+ end
484
+
485
+ def test_prev_chapter
486
+ mktmpbookdir 'CHAPS' => "ch1\nch2" do |dir, book, files|
487
+ chapter = book.chapter('ch2')
488
+ assert_equal book.chapter('ch1'), book.prev_chapter(chapter)
489
+
490
+ chapter = book.chapter('ch1')
491
+ assert_equal nil, book.prev_chapter(chapter)
492
+ end
493
+ end
494
+
495
+ def test_volume
496
+ mktmpbookdir do |dir, book, files|
497
+ assert book.volume
498
+ assert_equal 0, book.volume.bytes
499
+ assert_equal 0, book.volume.chars
500
+ assert_equal 0, book.volume.lines
501
+ end
502
+
503
+ mktmpbookdir 'CHAPS' => 'chapter1.re', 'chapter1.re' => '12345' do |dir, book, files|
504
+ assert book.volume
505
+ assert book.volume.bytes > 0
506
+ assert book.volume.chars > 0
507
+ assert book.volume.lines > 0
508
+ end
509
+
510
+ mktmpbookdir 'preface.re' => '12345' do |dir, book, files|
511
+ assert_raises Errno::ENOENT do # XXX: OK?
512
+ book.volume
513
+ end
514
+
515
+ Dir.chdir(dir) do
516
+ book2 = Book::Base.new('.')
517
+ assert book2.volume
518
+ assert book2.volume.bytes > 0
519
+ assert book2.volume.chars > 0
520
+ assert book2.volume.lines > 0
521
+ end
522
+ end
523
+ end
524
+
525
+ def test_basedir
526
+ Dir.mktmpdir do |dir|
527
+ book = Book::Base.new(dir)
528
+ assert_equal dir, book.basedir
529
+ end
530
+ end
531
+
532
+ def test_page_metric
533
+ Dir.mktmpdir do |dir|
534
+ book = Book::Base.new(dir)
535
+ assert_equal ReVIEW::Book::PageMetric::A5, book.page_metric
536
+ end
537
+ end
538
+
539
+ def test_page_metric_config
540
+ mktmpbookdir('config.yml'=>"bookname: book\npage_metric: B5\n") do |dir, book, files|
541
+ book = Book::Base.new(dir)
542
+ config_file = File.join(dir,"config.yml")
543
+ book.load_config(config_file)
544
+ assert_equal ReVIEW::Book::PageMetric::B5, book.page_metric
545
+ end
546
+ end
547
+
548
+ def test_page_metric_config_array
549
+ mktmpbookdir('config.yml'=>"bookname: book\npage_metric: [46, 80, 30, 74, 2]\n") do |dir, book, files|
550
+ book = Book::Base.new(dir)
551
+ config_file = File.join(dir,"config.yml")
552
+ book.load_config(config_file)
553
+ assert_equal ReVIEW::Book::PageMetric::B5, book.page_metric
554
+ end
555
+ end
556
+ end