review 2.3.0 → 2.4.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 (160) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +90 -66
  3. data/.travis.yml +1 -1
  4. data/Gemfile +0 -1
  5. data/NEWS.ja.md +82 -0
  6. data/NEWS.md +83 -0
  7. data/README.md +5 -3
  8. data/Rakefile +8 -8
  9. data/bin/review +1 -5
  10. data/bin/review-catalog-converter +22 -27
  11. data/bin/review-check +36 -43
  12. data/bin/review-checkdep +10 -15
  13. data/bin/review-compile +37 -55
  14. data/bin/review-epubmaker +4 -5
  15. data/bin/review-index +21 -29
  16. data/bin/review-init +26 -37
  17. data/bin/review-pdfmaker +0 -2
  18. data/bin/review-preproc +25 -45
  19. data/bin/review-validate +19 -18
  20. data/bin/review-vol +15 -27
  21. data/doc/config.yml.sample +5 -2
  22. data/doc/format.ja.md +20 -1
  23. data/doc/format.md +21 -5
  24. data/doc/images/review-generate.png +0 -0
  25. data/lib/epubmaker.rb +1 -3
  26. data/lib/epubmaker/content.rb +24 -27
  27. data/lib/epubmaker/epubcommon.rb +135 -148
  28. data/lib/epubmaker/epubv2.rb +39 -46
  29. data/lib/epubmaker/epubv3.rb +93 -103
  30. data/lib/epubmaker/producer.rb +138 -151
  31. data/lib/epubmaker/zip_exporter.rb +21 -26
  32. data/lib/review/book.rb +3 -6
  33. data/lib/review/book/base.rb +78 -103
  34. data/lib/review/book/chapter.rb +36 -40
  35. data/lib/review/book/compilable.rb +28 -31
  36. data/lib/review/book/image_finder.rb +6 -13
  37. data/lib/review/book/index.rb +100 -121
  38. data/lib/review/book/page_metric.rb +2 -7
  39. data/lib/review/book/part.rb +18 -20
  40. data/lib/review/book/volume.rb +9 -13
  41. data/lib/review/builder.rb +81 -116
  42. data/lib/review/catalog.rb +15 -19
  43. data/lib/review/compiler.rb +64 -83
  44. data/lib/review/configure.rb +87 -97
  45. data/lib/review/converter.rb +2 -7
  46. data/lib/review/epubbuilder.rb +1 -3
  47. data/lib/review/epubmaker.rb +213 -205
  48. data/lib/review/exception.rb +2 -4
  49. data/lib/review/extentions.rb +0 -1
  50. data/lib/review/extentions/hash.rb +2 -2
  51. data/lib/review/extentions/string.rb +5 -30
  52. data/lib/review/htmlbuilder.rb +320 -375
  53. data/lib/review/htmltoc.rb +4 -7
  54. data/lib/review/htmlutils.rb +29 -32
  55. data/lib/review/i18n.rb +33 -44
  56. data/lib/review/i18n.yml +3 -3
  57. data/lib/review/idgxmlbuilder.rb +309 -345
  58. data/lib/review/latexbuilder.rb +175 -212
  59. data/lib/review/latexindex.rb +2 -8
  60. data/lib/review/latexutils.rb +33 -43
  61. data/lib/review/lineinput.rb +1 -1
  62. data/lib/review/logger.rb +21 -0
  63. data/lib/review/makerhelper.rb +1 -4
  64. data/lib/review/markdownbuilder.rb +44 -53
  65. data/lib/review/md2inaobuilder.rb +6 -12
  66. data/lib/review/pdfmaker.rb +143 -173
  67. data/lib/review/preprocessor.rb +64 -101
  68. data/lib/review/rstbuilder.rb +126 -158
  69. data/lib/review/sec_counter.rb +18 -34
  70. data/lib/review/template.rb +4 -5
  71. data/lib/review/textbuilder.rb +2 -3
  72. data/lib/review/textutils.rb +7 -13
  73. data/lib/review/tocparser.rb +31 -56
  74. data/lib/review/tocprinter.rb +26 -52
  75. data/lib/review/topbuilder.rb +219 -247
  76. data/lib/review/unfold.rb +15 -24
  77. data/lib/review/version.rb +1 -1
  78. data/lib/review/webmaker.rb +75 -99
  79. data/lib/review/webtocprinter.rb +15 -20
  80. data/lib/review/yamlloader.rb +13 -15
  81. data/review.gemspec +20 -22
  82. data/templates/latex/layout.tex.erb +2 -2
  83. data/templates/opf/epubv2.opf.erb +7 -7
  84. data/templates/opf/epubv3.opf.erb +7 -7
  85. data/templates/web/html/layout-html5.html.erb +2 -2
  86. data/test/assets/black.eps +280 -0
  87. data/test/assets/fit.png +0 -0
  88. data/test/assets/large.gif +0 -0
  89. data/test/assets/large.jpg +0 -0
  90. data/test/assets/large.png +0 -0
  91. data/test/assets/large.svg +65 -0
  92. data/test/assets/test_template.tex +1 -1
  93. data/test/book_test_helper.rb +2 -2
  94. data/test/run_test.rb +4 -4
  95. data/test/sample-book/src/Rakefile +21 -22
  96. data/test/syntax-book/Gemfile +4 -0
  97. data/test/syntax-book/Rakefile +72 -0
  98. data/test/syntax-book/appA.re +22 -0
  99. data/test/syntax-book/bib.re +6 -0
  100. data/test/syntax-book/catalog.yml +15 -0
  101. data/test/syntax-book/ch01.re +136 -0
  102. data/test/syntax-book/ch02.re +351 -0
  103. data/test/syntax-book/ch03.re +82 -0
  104. data/test/syntax-book/config.yml +35 -0
  105. data/test/syntax-book/images/ball.png +0 -0
  106. data/test/syntax-book/images/cover.jpg +0 -0
  107. data/test/syntax-book/images/fractal.png +0 -0
  108. data/test/syntax-book/images/img3-1.png +0 -0
  109. data/test/syntax-book/images/inlineicon.jpg +0 -0
  110. data/test/syntax-book/images/logic.png +0 -0
  111. data/test/syntax-book/images/logic2.png +0 -0
  112. data/test/syntax-book/images/puzzle.jpg +0 -0
  113. data/test/syntax-book/images/table.jpg +0 -0
  114. data/test/syntax-book/part2.re +6 -0
  115. data/test/syntax-book/pre01.re +26 -0
  116. data/test/syntax-book/review-ext.rb +14 -0
  117. data/test/syntax-book/sty/jumoline.sty +310 -0
  118. data/test/syntax-book/sty/reviewmacro.sty +39 -0
  119. data/test/syntax-book/style.css +494 -0
  120. data/test/syntax-book/syntax.dic +2 -0
  121. data/test/test_book.rb +106 -111
  122. data/test/test_book_chapter.rb +21 -22
  123. data/test/test_book_part.rb +3 -5
  124. data/test/test_builder.rb +11 -22
  125. data/test/test_catalog.rb +17 -18
  126. data/test/test_catalog_converter_cmd.rb +5 -5
  127. data/test/test_compiler.rb +18 -16
  128. data/test/test_configure.rb +35 -38
  129. data/test/test_converter.rb +3 -4
  130. data/test/test_epub3maker.rb +136 -117
  131. data/test/test_epubmaker.rb +107 -114
  132. data/test/test_epubmaker_cmd.rb +2 -4
  133. data/test/test_extentions_hash.rb +32 -33
  134. data/test/test_helper.rb +9 -11
  135. data/test/test_htmlbuilder.rb +454 -420
  136. data/test/test_htmltoc.rb +8 -12
  137. data/test/test_htmlutils.rb +0 -2
  138. data/test/test_i18n.rb +159 -150
  139. data/test/test_idgxmlbuilder.rb +190 -197
  140. data/test/test_image_finder.rb +21 -22
  141. data/test/test_index.rb +24 -29
  142. data/test/test_latexbuilder.rb +274 -264
  143. data/test/test_lineinput.rb +7 -10
  144. data/test/test_location.rb +7 -7
  145. data/test/test_makerhelper.rb +13 -25
  146. data/test/test_markdownbuilder.rb +23 -26
  147. data/test/test_md2inaobuilder.rb +8 -11
  148. data/test/test_pdfmaker.rb +114 -123
  149. data/test/test_pdfmaker_cmd.rb +1 -3
  150. data/test/test_review_ext.rb +3 -5
  151. data/test/test_rstbuilder.rb +92 -97
  152. data/test/test_template.rb +3 -7
  153. data/test/test_textutils.rb +27 -27
  154. data/test/test_tocparser.rb +2 -2
  155. data/test/test_topbuilder.rb +98 -103
  156. data/test/test_webtocprinter.rb +5 -6
  157. data/test/test_yamlloader.rb +42 -42
  158. data/test/test_zip_exporter.rb +12 -18
  159. metadata +86 -9
  160. data/lib/review/ewbbuilder.rb +0 -382
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'test_helper'
4
2
  require 'lineinput'
5
3
  require 'tempfile'
@@ -17,7 +15,7 @@ class LineInputTest < Test::Unit::TestCase
17
15
  def test_gets
18
16
  content = "abc\ndef\r\nghi\rjkl"
19
17
  do_test_gets(StringIO.new(content))
20
- Tempfile.open("lineinput_test") do |io|
18
+ Tempfile.open('lineinput_test') do |io|
21
19
  io.print content
22
20
  io.rewind
23
21
  do_test_gets(io)
@@ -106,7 +104,7 @@ class LineInputTest < Test::Unit::TestCase
106
104
  li = LineInput.new(io)
107
105
 
108
106
  data = ''
109
- li.each {|l| data << l }
107
+ li.each { |l| data << l }
110
108
  assert_equal content, data
111
109
  end
112
110
 
@@ -116,7 +114,7 @@ class LineInputTest < Test::Unit::TestCase
116
114
 
117
115
  li.while_match(/^[ad]/) {}
118
116
  assert_equal 2, li.lineno
119
- assert_equal "ghi", li.gets
117
+ assert_equal 'ghi', li.gets
120
118
  end
121
119
 
122
120
  def test_getlines_while
@@ -126,7 +124,7 @@ class LineInputTest < Test::Unit::TestCase
126
124
  buf = li.getlines_while(/^[ad]/)
127
125
  assert_equal ["abc\n", "def\n"], buf
128
126
  assert_equal 2, li.lineno
129
- assert_equal "ghi", li.gets
127
+ assert_equal 'ghi', li.gets
130
128
  end
131
129
 
132
130
  def test_until_match
@@ -153,17 +151,17 @@ class LineInputTest < Test::Unit::TestCase
153
151
  li = LineInput.new(io)
154
152
 
155
153
  data = ''
156
- li.until_terminator(%r<\A//\}>) {|l| data << l }
154
+ li.until_terminator(%r<\A//\}>) { |l| data << l }
157
155
  assert_equal "abc\n", data
158
156
  assert_equal 2, li.lineno
159
157
 
160
158
  data = ''
161
- li.until_terminator(%r<\A//\}>) {|l| data << l }
159
+ li.until_terminator(%r<\A//\}>) { |l| data << l }
162
160
  assert_equal "def\nghi\n", data
163
161
  assert_equal 5, li.lineno
164
162
 
165
163
  data = ''
166
- li.until_terminator(%r<\A//\}>) {|l| data << l }
164
+ li.until_terminator(%r<\A//\}>) { |l| data << l }
167
165
  assert_equal "jkl\nmno", data
168
166
  assert_equal 8, li.lineno
169
167
  end
@@ -177,4 +175,3 @@ class LineInputTest < Test::Unit::TestCase
177
175
  assert_equal 3, li.lineno
178
176
  end
179
177
  end
180
-
@@ -7,24 +7,24 @@ class LocationTest < Test::Unit::TestCase
7
7
 
8
8
  def test_lineno
9
9
  f = StringIO.new("a\nb\nc\n")
10
- location = ReVIEW::Location.new("foo", f)
10
+ location = ReVIEW::Location.new('foo', f)
11
11
  assert_equal 0, location.lineno
12
12
  f.gets
13
13
  assert_equal 1, location.lineno
14
14
  end
15
15
 
16
16
  def test_string
17
- location = ReVIEW::Location.new("foo", StringIO.new("a\nb\nc\n"))
18
- assert_equal "foo:0", location.string
17
+ location = ReVIEW::Location.new('foo', StringIO.new("a\nb\nc\n"))
18
+ assert_equal 'foo:0', location.string
19
19
  end
20
20
 
21
21
  def test_to_s
22
- location = ReVIEW::Location.new("foo", StringIO.new("a\nb\nc\n"))
23
- assert_equal "foo:0", "#{location}"
22
+ location = ReVIEW::Location.new('foo', StringIO.new("a\nb\nc\n"))
23
+ assert_equal 'foo:0', location.to_s
24
24
  end
25
25
 
26
26
  def test_to_s_nil
27
- location = ReVIEW::Location.new("foo", nil)
28
- assert_equal "foo:nil", "#{location}"
27
+ location = ReVIEW::Location.new('foo', nil)
28
+ assert_equal 'foo:nil', location.to_s
29
29
  end
30
30
  end
@@ -1,11 +1,8 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  require 'test_helper'
4
2
  require 'review/makerhelper'
5
3
  require 'tmpdir'
6
4
  require 'fileutils'
7
5
 
8
-
9
6
  class MakerHelperTest < Test::Unit::TestCase
10
7
  include ReVIEW
11
8
 
@@ -20,10 +17,8 @@ class MakerHelperTest < Test::Unit::TestCase
20
17
  end
21
18
 
22
19
  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
20
+ types = %w[png gif jpg jpeg svg pdf eps]
21
+ types.each { |type| touch_file("#{@tmpdir1}/foo.#{type}") }
27
22
  FileUtils.mkdir("#{@tmpdir1}/subdir")
28
23
  touch_file("#{@tmpdir1}/subdir/foo.png")
29
24
 
@@ -33,36 +28,29 @@ class MakerHelperTest < Test::Unit::TestCase
33
28
  assert File.exist?("#{@tmpdir2}/foo.#{type}"), "Copying #{type} file failed"
34
29
  assert image_files.include?("#{@tmpdir1}/foo.#{type}")
35
30
  end
36
- assert File.exist?("#{@tmpdir2}/subdir/foo.png"), "Copying a image file in a subdirectory"
31
+ assert File.exist?("#{@tmpdir2}/subdir/foo.png"), 'Copying a image file in a subdirectory'
37
32
  assert image_files.include?("#{@tmpdir1}/subdir/foo.png")
38
33
  end
39
34
 
40
35
  def test_copy_images_to_dir_convert
41
- if /mswin|mingw|cygwin/ !~ RUBY_PLATFORM && (`convert -version` rescue nil)
42
- touch_file("#{@tmpdir1}/foo.eps")
36
+ if /mswin|mingw|cygwin/ !~ RUBY_PLATFORM && (`convert -version` rescue nil) && (`gs --version` rescue nil)
37
+ FileUtils.cp File.join(assets_dir, 'black.eps'), File.join(@tmpdir1, 'foo.eps')
43
38
 
44
39
  image_files = MakerHelper.copy_images_to_dir(@tmpdir1, @tmpdir2,
45
- :convert => {:eps => :png})
40
+ convert: { eps: :png })
46
41
 
47
- assert File.exist?("#{@tmpdir2}/foo.eps.png"), "EPS to PNG conversion failed"
42
+ assert File.exist?("#{@tmpdir2}/foo.eps.png"), 'EPS to PNG conversion failed'
48
43
  assert image_files.include?("#{@tmpdir1}/foo.eps.png")
49
44
  end
50
45
  end
51
46
 
52
47
  def test_copy_images_to_dir_with_exts
53
- types = %w{png gif jpg jpeg svg pdf eps}
54
- types4epub = %w{png gif jpg jpeg svg}
55
- types.each do |type|
56
- touch_file("#{@tmpdir1}/foo.#{type}")
57
- end
58
- image_files = MakerHelper.copy_images_to_dir(@tmpdir1, @tmpdir2, :exts=>types4epub)
48
+ types = %w[png gif jpg jpeg svg pdf eps]
49
+ types4epub = %w[png gif jpg jpeg svg]
50
+ types.each { |type| touch_file("#{@tmpdir1}/foo.#{type}") }
51
+ image_files = MakerHelper.copy_images_to_dir(@tmpdir1, @tmpdir2, exts: types4epub)
59
52
 
60
- types4epub.each do |type|
61
- assert image_files.include?("#{@tmpdir1}/foo.#{type}"), "foo.#{type} is not included"
62
- end
63
- (types - types4epub).each do |type|
64
- assert !image_files.include?("#{@tmpdir1}/foo.#{type}"), "foo.#{type} is included"
65
- end
53
+ types4epub.each { |type| assert image_files.include?("#{@tmpdir1}/foo.#{type}"), "foo.#{type} is not included" }
54
+ (types - types4epub).each { |type| assert !image_files.include?("#{@tmpdir1}/foo.#{type}"), "foo.#{type} is included" }
66
55
  end
67
-
68
56
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'test_helper'
4
2
  require 'review/compiler'
5
3
  require 'review/book'
@@ -10,12 +8,12 @@ class MARKDOWNBuilderTest < Test::Unit::TestCase
10
8
  include ReVIEW
11
9
 
12
10
  def setup
13
- @builder = MARKDOWNBuilder.new()
11
+ @builder = MARKDOWNBuilder.new
14
12
  @config = {
15
- "secnolevel" => 2, # for IDGXMLBuilder, HTMLBuilder
16
- "stylesheet" => nil, # for HTMLBuilder
13
+ 'secnolevel' => 2,
14
+ 'stylesheet' => nil
17
15
  }
18
- @book = Book::Base.new(".")
16
+ @book = Book::Base.new('.')
19
17
  @book.config = @config
20
18
  @compiler = ReVIEW::Compiler.new(@builder)
21
19
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
@@ -25,19 +23,19 @@ class MARKDOWNBuilderTest < Test::Unit::TestCase
25
23
 
26
24
  def test_quote
27
25
  actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
28
- assert_equal %Q|\n> foobar\n> \n> buz\n\n|, actual
26
+ assert_equal %Q(\n> foobar\n> \n> buz\n\n), actual
29
27
  end
30
28
 
31
29
  def test_inline_em
32
- assert_equal "test*foo*abc", compile_inline("test@<em>{foo}abc")
30
+ assert_equal 'test*foo*abc', compile_inline('test@<em>{foo}abc')
33
31
  end
34
32
 
35
33
  def test_inline_strong
36
- assert_equal "test**foo**abc", compile_inline("test@<strong>{foo}abc")
34
+ assert_equal 'test**foo**abc', compile_inline('test@<strong>{foo}abc')
37
35
  end
38
36
 
39
37
  def test_ul
40
- src =<<-EOS
38
+ src = <<-EOS
41
39
  * AAA
42
40
  * BBB
43
41
  EOS
@@ -47,18 +45,18 @@ EOS
47
45
  end
48
46
 
49
47
  def test_inline_comment
50
- actual = compile_inline("test @<comment>{コメント} test2")
51
- assert_equal %Q|test test2|, actual
48
+ actual = compile_inline('test @<comment>{コメント} test2')
49
+ assert_equal 'test test2', actual
52
50
  end
53
51
 
54
52
  def test_inline_comment_for_draft
55
- @config["draft"] = true
56
- actual = compile_inline("test @<comment>{コメント} test2")
57
- assert_equal %Q|test <span class="red">コメント</span> test2|, actual
53
+ @config['draft'] = true
54
+ actual = compile_inline('test @<comment>{コメント} test2')
55
+ assert_equal %Q(test <span class="red">コメント</span> test2), actual
58
56
  end
59
57
 
60
58
  def test_ul_nest1
61
- src =<<-EOS
59
+ src = <<-EOS
62
60
  * AAA
63
61
  ** AA
64
62
  *** A
@@ -75,29 +73,29 @@ EOS
75
73
 
76
74
  def test_dlist
77
75
  actual = compile_block(": foo\n foo.\n bar.\n")
78
- assert_equal %Q|<dl>\n<dt>foo</dt>\n<dd>foo.bar.</dd>\n</dl>\n|, actual
76
+ assert_equal %Q(<dl>\n<dt>foo</dt>\n<dd>foo.bar.</dd>\n</dl>\n), actual
79
77
  end
80
78
 
81
79
  def test_dlist_with_bracket
82
80
  actual = compile_block(": foo[bar]\n foo.\n bar.\n")
83
- assert_equal %Q|<dl>\n<dt>foo[bar]</dt>\n<dd>foo.bar.</dd>\n</dl>\n|, actual
81
+ assert_equal %Q(<dl>\n<dt>foo[bar]</dt>\n<dd>foo.bar.</dd>\n</dl>\n), actual
84
82
  end
85
83
 
86
84
  def test_dlist_with_comment
87
85
  source = ": title\n body\n\#@ comment\n\#@ comment\n: title2\n body2\n"
88
86
  actual = compile_block(source)
89
- assert_equal %Q|<dl>\n<dt>title</dt>\n<dd>body</dd>\n<dt>title2</dt>\n<dd>body2</dd>\n</dl>\n|, actual
87
+ assert_equal %Q(<dl>\n<dt>title</dt>\n<dd>body</dd>\n<dt>title2</dt>\n<dd>body2</dd>\n</dl>\n), actual
90
88
  end
91
89
 
92
90
  def test_comment
93
- actual = compile_block("//comment[コメント]")
94
- assert_equal %Q||, actual
91
+ actual = compile_block('//comment[コメント]')
92
+ assert_equal '', actual
95
93
  end
96
94
 
97
95
  def test_comment_for_draft
98
- @config["draft"] = true
99
- actual = compile_block("//comment[コメント]")
100
- assert_equal %Q|<div class="red">コメント</div>\n|, actual
96
+ @config['draft'] = true
97
+ actual = compile_block('//comment[コメント]')
98
+ assert_equal %Q(<div class="red">コメント</div>\n), actual
101
99
  end
102
100
 
103
101
  def test_list
@@ -162,8 +160,7 @@ BBB
162
160
  end
163
161
 
164
162
  def test_ruby
165
- actual = compile_block("@<ruby>{謳,うた}い文句")
163
+ actual = compile_block('@<ruby>{謳,うた}い文句')
166
164
  assert_equal "<ruby><rb>謳</rb><rp>(</rp><rt>うた</rt><rp>)</rp></ruby>い文句\n\n", actual
167
165
  end
168
-
169
166
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'test_helper'
4
2
  require 'review/compiler'
5
3
  require 'review/book'
@@ -10,22 +8,22 @@ class MD2INAOBuilderTest < Test::Unit::TestCase
10
8
  include ReVIEW
11
9
 
12
10
  def setup
13
- @builder = MD2INAOBuilder.new()
11
+ @builder = MD2INAOBuilder.new
14
12
  @config = {
15
- "secnolevel" => 2, # for IDGXMLBuilder, HTMLBuilder
16
- "stylesheet" => nil, # for HTMLBuilder
13
+ 'secnolevel' => 2,
14
+ 'stylesheet' => nil
17
15
  }
18
- @book = Book::Base.new(".")
16
+ @book = Book::Base.new('.')
19
17
  @book.config = @config
20
18
  @compiler = ReVIEW::Compiler.new(@builder)
21
19
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
22
20
  location = Location.new(nil, nil)
23
21
  @builder.bind(@compiler, @chapter, location)
24
- I18n.setup("ja")
22
+ I18n.setup('ja')
25
23
  end
26
24
 
27
25
  def test_paragraph
28
- actual = compile_block("Hello, world!")
26
+ actual = compile_block('Hello, world!')
29
27
  assert_equal " Hello, world!\n\n", actual
30
28
  end
31
29
 
@@ -58,13 +56,12 @@ BBB
58
56
  end
59
57
 
60
58
  def test_ruby_mono
61
- actual = compile_block("@<ruby>{謳,うた}い文句")
59
+ actual = compile_block('@<ruby>{謳,うた}い文句')
62
60
  assert_equal " <span class='monoruby'>謳(うた)</span>い文句\n\n", actual
63
61
  end
64
62
 
65
63
  def test_ruby_group
66
- actual = compile_block("@<ruby>{欠伸,あくび}が出る")
64
+ actual = compile_block('@<ruby>{欠伸,あくび}が出る')
67
65
  assert_equal " <span class='groupruby'>欠伸(あくび)</span>が出る\n\n", actual
68
66
  end
69
-
70
67
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'test_helper'
4
2
  require 'review/pdfmaker'
5
3
 
@@ -9,25 +7,25 @@ class PDFMakerTest < Test::Unit::TestCase
9
7
  def setup
10
8
  @maker = ReVIEW::PDFMaker.new
11
9
  @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
- "texcommand" => "uplatex",
20
- })
10
+ @config.merge!(
11
+ 'bookname' => 'sample',
12
+ 'title' => 'Sample Book',
13
+ 'version' => 2,
14
+ 'urnid' => 'http://example.jp/',
15
+ 'date' => '2011-01-01',
16
+ 'language' => 'ja',
17
+ 'texcommand' => 'uplatex'
18
+ )
21
19
  @maker.config = @config
22
- @maker.initialize_metachars(@config["texcommand"])
20
+ @maker.initialize_metachars(@config['texcommand'])
23
21
  @output = StringIO.new
24
- I18n.setup(@config["language"])
22
+ I18n.setup(@config['language'])
25
23
  end
26
24
 
27
25
  def test_check_book_existed
28
26
  Dir.mktmpdir do |dir|
29
27
  Dir.chdir(dir) do
30
- pdf_file = File.join(dir, "sample.pdf")
28
+ pdf_file = File.join(dir, 'sample.pdf')
31
29
  FileUtils.touch(pdf_file)
32
30
  @maker.basedir = Dir.pwd
33
31
  @maker.remove_old_file
@@ -37,7 +35,7 @@ class PDFMakerTest < Test::Unit::TestCase
37
35
  end
38
36
 
39
37
  def test_check_book_none
40
- Dir.mktmpdir do |dir|
38
+ Dir.mktmpdir do
41
39
  assert_nothing_raised do
42
40
  @maker.basedir = Dir.pwd
43
41
  @maker.remove_old_file
@@ -46,10 +44,10 @@ class PDFMakerTest < Test::Unit::TestCase
46
44
  end
47
45
 
48
46
  def test_buildpath_debug
49
- @maker.config["debug"] = true
47
+ @maker.config['debug'] = true
50
48
  path = @maker.build_path
51
49
  begin
52
- assert_equal(path, "sample-pdf")
50
+ assert_equal(path, 'sample-pdf')
53
51
  ensure
54
52
  FileUtils.remove_entry_secure path
55
53
  end
@@ -59,7 +57,7 @@ class PDFMakerTest < Test::Unit::TestCase
59
57
  io = StringIO.new
60
58
  $stdout = io
61
59
  assert_raises SystemExit do
62
- @maker.parse_opts(["-h"])
60
+ @maker.parse_opts(['-h'])
63
61
  end
64
62
  $stdout = STDOUT
65
63
  io.rewind
@@ -68,26 +66,28 @@ class PDFMakerTest < Test::Unit::TestCase
68
66
  end
69
67
 
70
68
  def test_parse_opts_ignore_errors
71
- conf, yml = @maker.parse_opts(["--ignore-errors", "hoge.yml"])
72
- assert_equal conf["ignore-errors"], true
73
- assert_equal yml, "hoge.yml"
69
+ conf, yml = @maker.parse_opts(['--ignore-errors', 'hoge.yml'])
70
+ assert_equal conf['ignore-errors'], true
71
+ assert_equal yml, 'hoge.yml'
74
72
  end
75
73
 
76
74
  def test_make_custom_page
77
75
  Dir.mktmpdir do |dir|
78
- coverfile = "cover.html"
79
- content = "<html><body>test</body></html>"
80
- File.open(File.join(dir, "cover.tex"),"w"){|f| f.write(content) }
76
+ coverfile = 'cover.html'
77
+ content = '<html><body>test</body></html>'
78
+ File.open(File.join(dir, 'cover.tex'), 'w') { |f| f.write(content) }
81
79
  page = @maker.make_custom_page(File.join(dir, coverfile))
82
80
  assert_equal(content, page)
83
81
  end
84
82
  end
85
83
 
86
84
  def test_make_authors
87
- @config.merge!({"aut"=>["テスト太郎","テスト次郎"],
88
- "csl"=>["監修三郎"],
89
- "trl"=>["翻訳四郎","翻訳五郎",]})
90
- Dir.mktmpdir do |dir|
85
+ @config.merge!(
86
+ 'aut' => ['テスト太郎', 'テスト次郎'],
87
+ 'csl' => ['監修三郎'],
88
+ 'trl' => ['翻訳四郎', '翻訳五郎']
89
+ )
90
+ Dir.mktmpdir do
91
91
  authors = @maker.make_authors
92
92
  assert_equal("テスト太郎、テスト次郎 著 \\\\\n監修三郎 監修 \\\\\n翻訳四郎、翻訳五郎 訳",
93
93
  authors)
@@ -95,26 +95,26 @@ class PDFMakerTest < Test::Unit::TestCase
95
95
  end
96
96
 
97
97
  def test_make_authors_only_aut
98
- @config.merge!({"aut"=>"テスト太郎"})
99
- Dir.mktmpdir do |dir|
98
+ @config['aut'] = 'テスト太郎'
99
+ Dir.mktmpdir do
100
100
  authors = @maker.make_authors
101
- assert_equal("テスト太郎 著", authors)
101
+ assert_equal('テスト太郎 著', authors)
102
102
  end
103
103
  end
104
104
 
105
105
  def test_make_okuduke
106
- @config.merge!({
107
- "aut"=>["テスト太郎","テスト次郎"],
108
- "csl"=>["監修三郎"],
109
- "trl"=>["翻訳四郎","翻訳五郎"],
110
- "dsr"=>["デザイン六郎"],
111
- "ill"=>["イラスト七郎","イラスト八郎"],
112
- "cov"=>["表紙九郎"],
113
- "edt"=>["編集十郎"],
114
- "pbl"=>"テスト出版",
115
- "prt"=>"テスト印刷",
116
- })
117
- Dir.mktmpdir do |dir|
106
+ @config.merge!(
107
+ 'aut' => ['テスト太郎', 'テスト次郎'],
108
+ 'csl' => ['監修三郎'],
109
+ 'trl' => ['翻訳四郎', '翻訳五郎'],
110
+ 'dsr' => ['デザイン六郎'],
111
+ 'ill' => ['イラスト七郎', 'イラスト八郎'],
112
+ 'cov' => ['表紙九郎'],
113
+ 'edt' => ['編集十郎'],
114
+ 'pbl' => 'テスト出版',
115
+ 'prt' => 'テスト印刷'
116
+ )
117
+ Dir.mktmpdir do
118
118
  okuduke = @maker.make_colophon
119
119
  assert_equal("著 者 & テスト太郎、テスト次郎 \\\\\n監 修 & 監修三郎 \\\\\n翻 訳 & 翻訳四郎、翻訳五郎 \\\\\nデザイン & デザイン六郎 \\\\\nイラスト & イラスト七郎、イラスト八郎 \\\\\n表 紙 & 表紙九郎 \\\\\n編 集 & 編集十郎 \\\\\n発行所 & テスト出版 \\\\\n印刷所 & テスト印刷 \\\\\n",
120
120
  okuduke)
@@ -122,133 +122,124 @@ class PDFMakerTest < Test::Unit::TestCase
122
122
  end
123
123
 
124
124
  def test_make_okuduke_dojin
125
- @config.merge!({
126
- "aut"=>["テスト太郎","テスト次郎"],
127
- "csl"=>["監修三郎"],
128
- "ill"=>["イラスト七郎","イラスト八郎"],
129
- "pbl"=>"テスト出版",
130
- "prt"=>"テスト印刷",
131
- "contact"=>"tarou@example.jp",
132
- })
133
- Dir.mktmpdir do |dir|
134
- I18n.update({"prt" => "印刷所"},"ja")
125
+ @config.merge!(
126
+ 'aut' => ['テスト太郎', 'テスト次郎'],
127
+ 'csl' => ['監修三郎'],
128
+ 'ill' => ['イラスト七郎', 'イラスト八郎'],
129
+ 'pbl' => 'テスト出版',
130
+ 'prt' => 'テスト印刷',
131
+ 'contact' => 'tarou@example.jp'
132
+ )
133
+ Dir.mktmpdir do
134
+ I18n.update({ 'prt' => '印刷所' }, 'ja')
135
135
  okuduke = @maker.make_colophon
136
136
  assert_equal("著 者 & テスト太郎、テスト次郎 \\\\\n監 修 & 監修三郎 \\\\\nイラスト & イラスト七郎、イラスト八郎 \\\\\n発行所 & テスト出版 \\\\\n連絡先 & tarou@example.jp \\\\\n印刷所 & テスト印刷 \\\\\n",
137
137
  okuduke)
138
138
  end
139
139
  end
140
140
 
141
- def test_gettemplate
142
- Dir.mktmpdir do |dir|
141
+ def test_template_content
142
+ Dir.mktmpdir do
143
143
  @maker.basedir = Dir.pwd
144
- tmpl = @maker.get_template
145
- expect = File.read(File.join(assets_dir,"test_template.tex"))
144
+ tmpl = @maker.template_content
145
+ expect = File.read(File.join(assets_dir, 'test_template.tex'))
146
146
  assert_equal(expect, tmpl)
147
147
  end
148
148
  end
149
149
 
150
150
  def test_gettemplate_with_backmatter
151
- @config.merge!({
152
- "backcover"=>"backcover.html",
153
- "profile"=>"profile.html",
154
- "advfile"=>"advfile.html",
155
- })
151
+ @config.merge!(
152
+ 'backcover' => 'backcover.html',
153
+ 'profile' => 'profile.html',
154
+ 'advfile' => 'advfile.html'
155
+ )
156
156
  Dir.mktmpdir do |dir|
157
157
  Dir.chdir(dir) do
158
158
  profile = "\\thispagestyle{empty}\\chapter*{Profile}\nsome profile\n"
159
- File.open(File.join(dir, "profile.tex"),"w"){|f| f.write(profile) }
159
+ File.open(File.join(dir, 'profile.tex'), 'w') { |f| f.write(profile) }
160
160
  advfile = "\\thispagestyle{empty}\\chapter*{Ad}\nsome ad content\n"
161
- File.open(File.join(dir, "advfile.tex"),"w"){|f| f.write(advfile) }
161
+ File.open(File.join(dir, 'advfile.tex'), 'w') { |f| f.write(advfile) }
162
162
  backcover = "\\clearpage\n\\thispagestyle{empty}\\AddToShipoutPictureBG{%\n\\AtPageLowerLeft{\\includegraphics[width=\\paperwidth,height=\\paperheight]{images/backcover.png}}\n}\n\\null"
163
- File.open(File.join(dir, "backcover.tex"),"w"){|f| f.write(backcover) }
163
+ File.open(File.join(dir, 'backcover.tex'), 'w') { |f| f.write(backcover) }
164
164
 
165
- expect = File.read(File.join(assets_dir,"test_template_backmatter.tex"))
165
+ expect = File.read(File.join(assets_dir, 'test_template_backmatter.tex'))
166
166
 
167
167
  @maker.basedir = Dir.pwd
168
- tmpl = @maker.get_template
169
- tmpl.gsub!(/\A.*%% backmatter begins\n/m,"")
168
+ tmpl = @maker.template_content
169
+ tmpl.gsub!(/\A.*%% backmatter begins\n/m, '')
170
170
  assert_equal(expect, tmpl)
171
171
  end
172
172
  end
173
173
  end
174
174
 
175
175
  def test_colophon_history
176
- @config["aut"] = ["Mr.Smith"]
177
- @config["pbl"] = ["BLUEPRINT"]
178
- @config["pht"] = ["Mrs.Smith"]
179
- @config.merge!({"language" => "ja"})
176
+ @config['aut'] = ['Mr.Smith']
177
+ @config['pbl'] = ['BLUEPRINT']
178
+ @config['pht'] = ['Mrs.Smith']
179
+ @config['language'] = 'ja'
180
180
  history = @maker.make_history_list
181
- expect = ["2011年1月1日 発行"]
181
+ expect = ['2011年1月1日 発行']
182
182
  assert_equal expect, history
183
183
  end
184
184
 
185
185
  def test_colophon_history_2
186
- @config["aut"] = ["Mr.Smith"]
187
- @config["pbl"] = ["BLUEPRINT"]
188
- @config["pht"] = ["Mrs.Smith"]
189
- @config.merge!({"language" => "ja",
190
- "history" => [[
191
- "2011-08-03 v1.0.0版発行",
192
- "2012-02-15 v1.1.0版発行",
193
- ]] })
186
+ @config['aut'] = ['Mr.Smith']
187
+ @config['pbl'] = ['BLUEPRINT']
188
+ @config['pht'] = ['Mrs.Smith']
189
+ @config['language'] = 'ja'
190
+ @config['history'] =
191
+ [['2011-08-03 v1.0.0版発行',
192
+ '2012-02-15 v1.1.0版発行']]
194
193
  history = @maker.make_history_list
195
- expect = ["2011年8月3日 v1.0.0版発行",
196
- "2012年2月15日 v1.1.0版発行"]
194
+ expect = ['2011年8月3日 v1.0.0版発行', '2012年2月15日 v1.1.0版発行']
197
195
  assert_equal expect, history
198
196
  end
199
197
 
200
198
  def test_colophon_history_date
201
- @config["aut"] = ["Mr.Smith"]
202
- @config["pbl"] = ["BLUEPRINT"]
203
- @config["pht"] = ["Mrs.Smith"]
204
- @config.merge!({"language" => "ja",
205
- "history" => [[
206
- "2011-08-03",
207
- "2012-02-15",
208
- ]] })
199
+ @config['aut'] = ['Mr.Smith']
200
+ @config['pbl'] = ['BLUEPRINT']
201
+ @config['pht'] = ['Mrs.Smith']
202
+ @config['language'] = 'ja'
203
+ @config['history'] =
204
+ [['2011-08-03',
205
+ '2012-02-15']]
209
206
  history = @maker.make_history_list
210
- expect = ["2011年8月3日 初版第1刷 発行",
211
- "2012年2月15日 初版第2刷 発行"]
207
+ expect = ['2011年8月3日 初版第1刷 発行',
208
+ '2012年2月15日 初版第2刷 発行']
212
209
  assert_equal expect, history
213
210
  end
214
211
 
215
212
  def test_colophon_history_date2
216
- @config["aut"] = ["Mr.Smith"]
217
- @config["pbl"] = ["BLUEPRINT"]
218
- @config["pht"] = ["Mrs.Smith"]
219
- @config.merge!({"language" => "ja",
220
- "history" => [[
221
- "2011-08-03",
222
- "2012-02-15",
223
- ],[
224
- "2012-10-01",
225
- ],[
226
- "2013-03-01",
227
- ]] })
213
+ @config['aut'] = ['Mr.Smith']
214
+ @config['pbl'] = ['BLUEPRINT']
215
+ @config['pht'] = ['Mrs.Smith']
216
+ @config['language'] = 'ja'
217
+ @config['history'] =
218
+ [['2011-08-03',
219
+ '2012-02-15'],
220
+ ['2012-10-01'],
221
+ ['2013-03-01']]
228
222
  history = @maker.make_history_list
229
- expect = ["2011年8月3日 初版第1刷 発行",
230
- "2012年2月15日 初版第2刷 発行",
231
- "2012年10月1日 第2版第1刷 発行",
232
- "2013年3月1日 第3版第1刷 発行"]
223
+ expect = ['2011年8月3日 初版第1刷 発行',
224
+ '2012年2月15日 初版第2刷 発行',
225
+ '2012年10月1日 第2版第1刷 発行',
226
+ '2013年3月1日 第3版第1刷 発行']
233
227
  assert_equal expect, history
234
228
  end
235
229
 
236
230
  def test_colophon_history_freeformat
237
- @config["aut"] = ["Mr.Smith"]
238
- @config["pbl"] = ["BLUEPRINT"]
239
- @config["pht"] = ["Mrs.Smith"]
240
- @config.merge!({"language" => "ja",
241
- "history" => [[
242
- "2011年8月3日 ver 1.1.0発行",
243
- ],[
244
- "20111012日 ver 1.2.0発行",
245
- ],[
246
- "2012年1月31日 ver 1.2.1発行",
247
- ]] })
231
+ @config['aut'] = ['Mr.Smith']
232
+ @config['pbl'] = ['BLUEPRINT']
233
+ @config['pht'] = ['Mrs.Smith']
234
+ @config['language'] = 'ja'
235
+ @config['history'] =
236
+ [['2011年8月3日 ver 1.1.0発行'],
237
+ ['2011年10月12日 ver 1.2.0発行'],
238
+ ['2012131日 ver 1.2.1発行']]
248
239
  history = @maker.make_history_list
249
- expect = ["2011年8月3日 ver 1.1.0発行",
250
- "2011年10月12日 ver 1.2.0発行",
251
- "2012年1月31日 ver 1.2.1発行"]
240
+ expect = ['2011年8月3日 ver 1.1.0発行',
241
+ '2011年10月12日 ver 1.2.0発行',
242
+ '2012年1月31日 ver 1.2.1発行']
252
243
  assert_equal expect, history
253
244
  end
254
245
  end