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,182 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+ require 'lineinput'
5
+ require 'tempfile'
6
+ require 'stringio'
7
+
8
+ class LineInputTest < Test::Unit::TestCase
9
+ def test_initialize
10
+ io = StringIO.new
11
+ li = LineInput.new(io)
12
+ assert_equal 0, li.lineno
13
+ assert !li.eof?
14
+ assert_equal "#<LineInput file=#{io.inspect} line=0>", li.inspect
15
+ end
16
+
17
+ def test_gets
18
+ content = "abc\ndef\r\nghi\rjkl"
19
+ do_test_gets(StringIO.new(content))
20
+ Tempfile.open("lineinput_test") do |io|
21
+ io.print content
22
+ io.rewind
23
+ do_test_gets(io)
24
+ end
25
+ end
26
+
27
+ def do_test_gets(io)
28
+ li = LineInput.new(io)
29
+
30
+ assert_equal "abc\n", li.gets
31
+ assert_equal "def\r\n", li.gets
32
+ assert_equal "ghi\rjkl", li.gets
33
+ assert_equal 3, li.lineno
34
+ assert !li.eof?
35
+
36
+ assert_equal nil, li.gets
37
+ assert_equal 4, li.lineno # XXX: OK?
38
+ assert li.eof?
39
+
40
+ assert_equal nil, li.gets
41
+ assert_equal 4, li.lineno
42
+ assert li.eof?
43
+ end
44
+
45
+ def test_ungets
46
+ io = StringIO.new('abc')
47
+ li = LineInput.new(io)
48
+
49
+ line = li.gets
50
+ assert_equal line, li.ungets(line)
51
+ assert_equal 0, li.lineno
52
+ assert_equal line, li.gets
53
+
54
+ li.ungets('xyz')
55
+ assert_equal 0, li.lineno
56
+ li.ungets('xyz')
57
+ assert_equal -1, li.lineno # XXX: OK?
58
+ end
59
+
60
+ =begin
61
+ def test_peek
62
+ li = LineInput.new(StringIO.new)
63
+ assert_equal nil, li.peek
64
+
65
+ li = LineInput.new(StringIO.new('abc'))
66
+ assert_equal 'abc', li.peek
67
+ end
68
+
69
+ def test_next?
70
+ li = LineInput.new(StringIO.new)
71
+ assert !li.next?
72
+
73
+ li = LineInput.new(StringIO.new('abc'))
74
+ assert li.next?
75
+ end
76
+
77
+ def test_gets_if
78
+ io = StringIO.new
79
+ li = LineInput.new(io)
80
+ assert_equal nil, li.gets_if(//)
81
+
82
+ io = StringIO.new("abc\ndef\nghi")
83
+ li = LineInput.new(io)
84
+
85
+ assert_equal "abc\n", li.gets_if(//)
86
+ assert_equal nil, li.gets_if(/^X/)
87
+ assert_equal nil, li.gets_if(/^g/)
88
+ assert_equal "def\n", li.gets_if(/^d/)
89
+ end
90
+
91
+ def test_gets_unless
92
+ io = StringIO.new
93
+ li = LineInput.new(io)
94
+ assert_equal nil, li.gets_unless(//)
95
+
96
+ io = StringIO.new("abc\ndef\nghi")
97
+ li = LineInput.new(io)
98
+
99
+ assert_equal nil, li.gets_unless(//)
100
+ assert_equal "abc\n", li.gets_unless(/^X/)
101
+ assert_equal nil, li.gets_unless(/^d/)
102
+ end
103
+ =end
104
+ def test_each
105
+ content = "abc\ndef\nghi"
106
+ io = StringIO.new(content)
107
+ li = LineInput.new(io)
108
+
109
+ data = ''
110
+ li.each {|l| data << l }
111
+ assert_equal content, data
112
+ end
113
+
114
+ def test_while_match
115
+ io = StringIO.new("abc\ndef\nghi")
116
+ li = LineInput.new(io)
117
+
118
+ li.while_match(/^[ad]/) {}
119
+ assert_equal 2, li.lineno
120
+ assert_equal "ghi", li.gets
121
+ end
122
+ =begin
123
+ def test_getlines_while
124
+ io = StringIO.new("abc\ndef\nghi")
125
+ li = LineInput.new(io)
126
+
127
+ buf = li.getlines_while(/^[ad]/)
128
+ assert_equal ["abc\n", "def\n"], buf
129
+ assert_equal 2, li.lineno
130
+ assert_equal "ghi", li.gets
131
+ end
132
+ =end
133
+ def test_until_match
134
+ io = StringIO.new("abc\ndef\nghi")
135
+ li = LineInput.new(io)
136
+
137
+ li.until_match(/^[^a]/) {}
138
+ assert_equal 1, li.lineno
139
+ assert_equal "def\n", li.gets
140
+ end
141
+ =begin
142
+ def test_getlines_until
143
+ io = StringIO.new("abc\ndef\nghi")
144
+ li = LineInput.new(io)
145
+
146
+ buf = li.getlines_until(/^[^a]/)
147
+ assert_equal ["abc\n"], buf
148
+ assert_equal 1, li.lineno
149
+ assert_equal "def\n", li.gets
150
+ end
151
+
152
+ def test_until_terminator
153
+ io = StringIO.new("abc\n//}\ndef\nghi\n//}\njkl\nmno")
154
+ li = LineInput.new(io)
155
+
156
+ data = ''
157
+ li.until_terminator(%r<\A//\}>) {|l| data << l }
158
+ assert_equal "abc\n", data
159
+ assert_equal 2, li.lineno
160
+
161
+ data = ''
162
+ li.until_terminator(%r<\A//\}>) {|l| data << l }
163
+ assert_equal "def\nghi\n", data
164
+ assert_equal 5, li.lineno
165
+
166
+ data = ''
167
+ li.until_terminator(%r<\A//\}>) {|l| data << l }
168
+ assert_equal "jkl\nmno", data
169
+ assert_equal 8, li.lineno
170
+ end
171
+
172
+ def test_until_terminator2
173
+ io = StringIO.new("abc\ndef\n//}\nghi\n//}")
174
+ li = LineInput.new(io)
175
+
176
+ data = li.getblock(%r<\A//\}>)
177
+ assert_equal ["abc\n", "def\n"], data
178
+ assert_equal 3, li.lineno
179
+ end
180
+ =end
181
+ end
182
+
@@ -0,0 +1,66 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'test_helper'
4
+ require 'review/makerhelper'
5
+ require 'tmpdir'
6
+ require 'fileutils'
7
+
8
+
9
+ class MakerHelperTest < Test::Unit::TestCase
10
+ include ReVIEW
11
+
12
+ def setup
13
+ @tmpdir1 = Dir.mktmpdir
14
+ @tmpdir2 = Dir.mktmpdir
15
+ end
16
+
17
+ def teardown
18
+ FileUtils.rm_rf @tmpdir1
19
+ FileUtils.rm_rf @tmpdir2
20
+ end
21
+
22
+ def test_copy_images_to_dir
23
+ types = %w{png gif jpg jpeg svg pdf eps}
24
+ types.each do |type|
25
+ touch_file("#{@tmpdir1}/foo.#{type}")
26
+ end
27
+ FileUtils.mkdir("#{@tmpdir1}/subdir")
28
+ touch_file("#{@tmpdir1}/subdir/foo.png")
29
+
30
+ image_files = MakerHelper.copy_images_to_dir(@tmpdir1, @tmpdir2)
31
+
32
+ types.each do |type|
33
+ assert File.exist?("#{@tmpdir2}/foo.#{type}"), "Copying #{type} file failed"
34
+ assert image_files.include?("#{@tmpdir1}/foo.#{type}")
35
+ end
36
+ assert File.exist?("#{@tmpdir2}/subdir/foo.png"), "Copying a image file in a subdirectory"
37
+ assert image_files.include?("#{@tmpdir1}/subdir/foo.png")
38
+ end
39
+
40
+ def test_copy_images_to_dir_convert
41
+ touch_file("#{@tmpdir1}/foo.eps")
42
+
43
+ image_files = MakerHelper.copy_images_to_dir(@tmpdir1, @tmpdir2,
44
+ :convert => {:eps => :png})
45
+
46
+ assert File.exist?("#{@tmpdir2}/foo.eps.png"), "EPS to PNG conversion failed"
47
+ assert image_files.include?("#{@tmpdir1}/foo.eps.png")
48
+ end
49
+
50
+ def test_copy_images_to_dir_with_exts
51
+ types = %w{png gif jpg jpeg svg pdf eps}
52
+ types4epub = %w{png gif jpg jpeg svg}
53
+ types.each do |type|
54
+ touch_file("#{@tmpdir1}/foo.#{type}")
55
+ end
56
+ image_files = MakerHelper.copy_images_to_dir(@tmpdir1, @tmpdir2, :exts=>types4epub)
57
+
58
+ types4epub.each do |type|
59
+ assert image_files.include?("#{@tmpdir1}/foo.#{type}"), "foo.#{type} is not included"
60
+ end
61
+ (types - types4epub).each do |type|
62
+ assert !image_files.include?("#{@tmpdir1}/foo.#{type}"), "foo.#{type} is included"
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,125 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+ require 'review/compiler'
5
+ require 'review/book'
6
+ require 'review/markdownbuilder'
7
+ require 'review/i18n'
8
+
9
+ class MARKDOWNBuilderTest < Test::Unit::TestCase
10
+ include ReVIEW
11
+
12
+ def setup
13
+ @builder = MARKDOWNBuilder.new()
14
+ @config = {
15
+ "secnolevel" => 2, # for IDGXMLBuilder, HTMLBuilder
16
+ "stylesheet" => nil, # for HTMLBuilder
17
+ }
18
+ @book = Book::Base.new(nil)
19
+ @book.config = @config
20
+ @compiler = ReVIEW::Compiler.new(@builder)
21
+ @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
22
+ location = Location.new(nil, nil)
23
+ @builder.bind(@compiler, @chapter, location)
24
+ end
25
+
26
+ def test_quote
27
+ actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
28
+ assert_equal %Q|\n> foobar\n> \n> buz\n\n|, actual
29
+ end
30
+
31
+ def test_inline_em
32
+ assert_equal "test*foo*abc", compile_inline("test@<em>{foo}abc")
33
+ end
34
+
35
+ def test_inline_strong
36
+ assert_equal "test**foo**abc", compile_inline("test@<strong>{foo}abc")
37
+ end
38
+
39
+ def test_ul
40
+ src =<<-EOS
41
+ * AAA
42
+ * BBB
43
+ EOS
44
+ expected = "\n* AAA\n* BBB\n\n"
45
+ actual = compile_block(src)
46
+ assert_equal expected, actual
47
+ end
48
+
49
+ def test_ul_nest1
50
+ src =<<-EOS
51
+ * AAA
52
+ ** AA
53
+ *** A
54
+ EOS
55
+ expected = "\n* AAA\n * AA\n * A\n\n"
56
+ actual = compile_block(src)
57
+ assert_equal expected, actual
58
+ end
59
+
60
+ def test_cmd
61
+ actual = compile_block("//cmd{\nlineA\nlineB\n//}\n")
62
+ assert_equal "```shell-session\nlineA\nlineB\n```\n", actual
63
+ end
64
+
65
+ def test_list
66
+ actual = compile_block(<<-EOS)
67
+ //list[name][caption]{
68
+ AAA
69
+ BBB
70
+ //}
71
+ EOS
72
+
73
+ assert_equal <<-EOS, actual
74
+ リスト1.1 caption
75
+
76
+ ```
77
+ AAA
78
+ BBB
79
+ ```
80
+ EOS
81
+ end
82
+
83
+ def test_list_lang
84
+ actual = compile_block(<<-EOS)
85
+ //list[name][caption][ruby]{
86
+ AAA
87
+ BBB
88
+ //}
89
+ EOS
90
+
91
+ assert_equal <<-EOS, actual
92
+ リスト1.1 caption
93
+
94
+ ```ruby
95
+ AAA
96
+ BBB
97
+ ```
98
+ EOS
99
+ end
100
+
101
+ def test_emlist_lang
102
+ actual = compile_block(<<-EOS)
103
+ //emlist[caption][ruby]{
104
+ AAA
105
+ BBB
106
+ //}
107
+ EOS
108
+
109
+ assert_equal <<-EOS, actual
110
+
111
+ caption
112
+
113
+ ```ruby
114
+ AAA
115
+ BBB
116
+ ```
117
+
118
+ EOS
119
+ end
120
+
121
+ def test_table
122
+ actual = compile_block("//table{\ntestA\ttestB\n------------\ncontentA\tcontentB\n//}\n")
123
+ assert_equal "|testA|testB|\n|:--|:--|\n|contentA|contentB|\n\n", actual
124
+ end
125
+ end
@@ -0,0 +1,171 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+ require 'review/pdfmaker'
5
+
6
+ class PDFMakerTest < Test::Unit::TestCase
7
+ include ReVIEW
8
+
9
+ def setup
10
+ @maker = ReVIEW::PDFMaker.new
11
+ @config = ReVIEW::Configure.values
12
+ @config.merge!({
13
+ "bookname" => "sample",
14
+ "title" => "Sample Book",
15
+ "version" => 2,
16
+ "urnid" => "http://example.jp/",
17
+ "date" => "2011-01-01",
18
+ "language" => "ja",
19
+ })
20
+ @maker.config = @config
21
+ @output = StringIO.new
22
+ I18n.setup(@config["language"])
23
+ end
24
+
25
+ def test_check_book_existed
26
+ Dir.mktmpdir do |dir|
27
+ Dir.chdir(dir) do
28
+ pdf_file = File.join(dir, "sample.pdf")
29
+ FileUtils.touch(pdf_file)
30
+ @maker.basedir = Dir.pwd
31
+ @maker.remove_old_file
32
+ assert !File.exist?(pdf_file)
33
+ end
34
+ end
35
+ ensure
36
+ $stderr = STDERR
37
+ end
38
+
39
+ def test_check_book_none
40
+ Dir.mktmpdir do |dir|
41
+ assert_nothing_raised do
42
+ @maker.remove_old_file
43
+ end
44
+ end
45
+ end
46
+
47
+ def test_buildpath
48
+ assert_equal(@maker.build_path, "./sample-pdf")
49
+ end
50
+
51
+ def test_parse_opts_help
52
+ io = StringIO.new
53
+ $stdout = io
54
+ assert_raises SystemExit do
55
+ @maker.parse_opts(["-h"])
56
+ end
57
+ $stdout = STDOUT
58
+ io.rewind
59
+ str = io.gets
60
+ assert_equal "Usage: review-pdfmaker configfile\n", str
61
+ end
62
+
63
+ def test_parse_opts_ignore_errors
64
+ io = StringIO.new
65
+ conf, yml = @maker.parse_opts(["--ignore-errors", "hoge.yml"])
66
+ assert_equal conf["ignore-errors"], true
67
+ assert_equal yml, "hoge.yml"
68
+ end
69
+
70
+ def test_make_custom_page
71
+ Dir.mktmpdir do |dir|
72
+ coverfile = "cover.html"
73
+ content = "<html><body>test</body></html>"
74
+ File.open(File.join(dir, "cover.tex"),"w"){|f| f.write(content) }
75
+ page = @maker.make_custom_page(File.join(dir, coverfile))
76
+ assert_equal(content, page)
77
+ end
78
+ end
79
+
80
+ def test_make_authors
81
+ @config.merge!({"aut"=>["テスト太郎","テスト次郎"],
82
+ "csl"=>["監修三郎"],
83
+ "trl"=>["翻訳四郎","翻訳五郎",]})
84
+ Dir.mktmpdir do |dir|
85
+ authors = @maker.make_authors
86
+ assert_equal("テスト太郎、テスト次郎 著 \\\\\n監修三郎 監修 \\\\\n翻訳四郎、翻訳五郎 訳",
87
+ authors)
88
+ end
89
+ end
90
+
91
+ def test_make_authors_only_aut
92
+ @config.merge!({"aut"=>"テスト太郎"})
93
+ Dir.mktmpdir do |dir|
94
+ authors = @maker.make_authors
95
+ assert_equal("テスト太郎 著", authors)
96
+ end
97
+ end
98
+
99
+ def test_make_okuduke
100
+ @config.merge!({
101
+ "aut"=>["テスト太郎","テスト次郎"],
102
+ "csl"=>["監修三郎"],
103
+ "trl"=>["翻訳四郎","翻訳五郎"],
104
+ "dsr"=>["デザイン六郎"],
105
+ "ill"=>["イラスト七郎","イラスト八郎"],
106
+ "cov"=>["表紙九郎"],
107
+ "edt"=>["編集十郎"],
108
+ "prt"=>"テスト出版",
109
+ })
110
+ Dir.mktmpdir do |dir|
111
+ okuduke = @maker.make_colophon
112
+ assert_equal("著 者 & テスト太郎、テスト次郎 \\\\\n監 修 & 監修三郎 \\\\\n翻 訳 & 翻訳四郎、翻訳五郎 \\\\\nデザイン & デザイン六郎 \\\\\nイラスト & イラスト七郎、イラスト八郎 \\\\\n表 紙 & 表紙九郎 \\\\\n編 集 & 編集十郎 \\\\\n発行所 & テスト出版 \\\\\n",
113
+ okuduke)
114
+ end
115
+ end
116
+
117
+
118
+ def test_make_okuduke_dojin
119
+ @config.merge!({
120
+ "aut"=>["テスト太郎","テスト次郎"],
121
+ "csl"=>["監修三郎"],
122
+ "ill"=>["イラスト七郎","イラスト八郎"],
123
+ "pbl"=>"テスト出版",
124
+ "prt"=>"テスト印刷",
125
+ "contact"=>"tarou@example.jp",
126
+ })
127
+ Dir.mktmpdir do |dir|
128
+ I18n.update({"prt" => "印刷所"},"ja")
129
+ okuduke = @maker.make_colophon
130
+ assert_equal("著 者 & テスト太郎、テスト次郎 \\\\\n監 修 & 監修三郎 \\\\\nイラスト & イラスト七郎、イラスト八郎 \\\\\n発行所 & テスト出版 \\\\\n連絡先 & tarou@example.jp \\\\\n印刷所 & テスト印刷 \\\\\n",
131
+ okuduke)
132
+ end
133
+ end
134
+
135
+ def test_gettemplate
136
+ Dir.mktmpdir do |dir|
137
+ tmpl = @maker.get_template
138
+ expect = File.read(File.join(assets_dir,"test_template.tex"))
139
+ assert_equal(expect, tmpl)
140
+ end
141
+ end
142
+
143
+ def test_gettemplate_with_backmatter
144
+ if RUBY_VERSION =~ /^1.8/
145
+ $stderr.puts "skip test_gettemplate_with_backmatter (for travis error)"
146
+ return
147
+ end
148
+ @config.merge!({
149
+ "backcover"=>"backcover.html",
150
+ "profile"=>"profile.html",
151
+ "advfile"=>"advfile.html",
152
+ })
153
+ Dir.mktmpdir do |dir|
154
+ Dir.chdir(dir) do
155
+ profile = "\\thispagestyle{empty}\\chapter*{Profile}\nsome profile\n"
156
+ File.open(File.join(dir, "profile.tex"),"w"){|f| f.write(profile) }
157
+ advfile = "\\thispagestyle{empty}\\chapter*{Ad}\nsome ad content\n"
158
+ File.open(File.join(dir, "advfile.tex"),"w"){|f| f.write(advfile) }
159
+ backcover = "\\clearpage\n\\thispagestyle{empty}\\AddToShipoutPictureBG{%\n\\AtPageLowerLeft{\\includegraphics[width=\\paperwidth,height=\\paperheight]{images/backcover.png}}\n}\n\\null"
160
+ File.open(File.join(dir, "backcover.tex"),"w"){|f| f.write(backcover) }
161
+
162
+ expect = File.read(File.join(assets_dir,"test_template_backmatter.tex"))
163
+
164
+ tmpl = @maker.get_template
165
+ tmpl.gsub!(/\A.*%% backmatter begins\n/m,"")
166
+ assert_equal(expect, tmpl)
167
+ end
168
+ end
169
+ end
170
+
171
+ end