review 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
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 'review/htmltoc'
5
3
 
@@ -13,21 +11,19 @@ class HTMLTocTest < Test::Unit::TestCase
13
11
  end
14
12
 
15
13
  def test_tocfilename
16
- toc = HTMLToc.new("/var/tmp")
17
- assert_equal "/var/tmp/toc-html.txt", toc.tocfilename
14
+ toc = HTMLToc.new('/var/tmp')
15
+ assert_equal '/var/tmp/toc-html.txt', toc.tocfilename
18
16
  end
19
17
 
20
18
  def test_encode_args
21
- toc = HTMLToc.new("/var/tmp")
22
- assert_equal "chaptype=pre", toc.encode_args({:chaptype => "pre"})
23
- assert_equal "force_include=true,chaptype=body,properties=foo", toc.encode_args({:force_include => true, :chaptype => "body", "properties"=>"foo"})
19
+ toc = HTMLToc.new('/var/tmp')
20
+ assert_equal 'chaptype=pre', toc.encode_args(chaptype: 'pre')
21
+ assert_equal 'force_include=true,chaptype=body,properties=foo', toc.encode_args({ force_include: true, chaptype: 'body', 'properties' => 'foo' })
24
22
  end
25
23
 
26
24
  def test_decode_args
27
- toc = HTMLToc.new("/var/tmp")
28
- assert_equal({:chaptype => "pre"}, toc.decode_args("chaptype=pre"))
29
- assert_equal({:force_include => "true", :chaptype => "body",:properties=>"foo"}, toc.decode_args("force_include=true,chaptype=body,properties=foo"))
25
+ toc = HTMLToc.new('/var/tmp')
26
+ assert_equal({ chaptype: 'pre' }, toc.decode_args('chaptype=pre'))
27
+ assert_equal({ force_include: 'true', chaptype: 'body', properties: 'foo' }, toc.decode_args('force_include=true,chaptype=body,properties=foo'))
30
28
  end
31
-
32
29
  end
33
-
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  require 'test_helper'
3
2
  require 'review/htmlutils'
4
3
 
@@ -46,5 +45,4 @@ class HTMLUtilsTest < Test::Unit::TestCase
46
45
  assert_equal 'id__E3_81_82', normalize_id('あ')
47
46
  assert_equal 'id_-___3B', normalize_id(' _;')
48
47
  end
49
-
50
48
  end
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  require 'test_helper'
3
2
  require 'review'
4
3
  require 'tmpdir'
@@ -9,10 +8,10 @@ class I18nTest < Test::Unit::TestCase
9
8
  def test_load_locale_yml
10
9
  Dir.mktmpdir do |dir|
11
10
  Dir.chdir(dir) do
12
- file = File.join(dir, "locale.yml")
13
- File.open(file, "w"){|f| f.write("locale: ja\nfoo: \"bar\"\n")}
11
+ file = File.join(dir, 'locale.yml')
12
+ File.open(file, 'w') { |f| f.write(%Q(locale: ja\nfoo: "bar"\n)) }
14
13
  I18n.setup
15
- assert_equal "bar", I18n.t("foo")
14
+ assert_equal 'bar', I18n.t('foo')
16
15
  end
17
16
  end
18
17
  end
@@ -20,8 +19,8 @@ class I18nTest < Test::Unit::TestCase
20
19
  def test_load_locale_yaml
21
20
  Dir.mktmpdir do |dir|
22
21
  Dir.chdir(dir) do
23
- file = File.join(dir, "locale.yaml")
24
- File.open(file, "w"){|f| f.write("locale: ja\nfoo: \"bar\"\n")}
22
+ file = File.join(dir, 'locale.yaml')
23
+ File.open(file, 'w') { |f| f.write(%Q(locale: ja\nfoo: "bar"\n)) }
25
24
  assert_raise ReVIEW::ConfigError do
26
25
  I18n.setup
27
26
  end
@@ -32,10 +31,10 @@ class I18nTest < Test::Unit::TestCase
32
31
  def test_load_foo_yaml
33
32
  Dir.mktmpdir do |dir|
34
33
  Dir.chdir(dir) do
35
- file = File.join(dir, "foo.yml")
36
- File.open(file, "w"){|f| f.write("locale: ja\nfoo: \"bar\"\n")}
37
- I18n.setup("ja","foo.yml")
38
- assert_equal "bar", I18n.t("foo")
34
+ file = File.join(dir, 'foo.yml')
35
+ File.open(file, 'w') { |f| f.write(%Q(locale: ja\nfoo: "bar"\n)) }
36
+ I18n.setup('ja', 'foo.yml')
37
+ assert_equal 'bar', I18n.t('foo')
39
38
  end
40
39
  end
41
40
  end
@@ -43,11 +42,11 @@ class I18nTest < Test::Unit::TestCase
43
42
  def test_update_foo_yaml
44
43
  Dir.mktmpdir do |dir|
45
44
  Dir.chdir(dir) do
46
- file = File.join(dir, "foo.yml")
47
- File.open(file, "w"){|f| f.write("locale: ja\nfoo: \"bar\"\n")}
48
- i18n = ReVIEW::I18n.new("ja")
49
- i18n.update_localefile(File.join(Dir.pwd, "foo.yml"))
50
- assert_equal "bar", i18n.t("foo")
45
+ file = File.join(dir, 'foo.yml')
46
+ File.open(file, 'w') { |f| f.write(%Q(locale: ja\nfoo: "bar"\n)) }
47
+ i18n = ReVIEW::I18n.new('ja')
48
+ i18n.update_localefile(File.join(Dir.pwd, 'foo.yml'))
49
+ assert_equal 'bar', i18n.t('foo')
51
50
  end
52
51
  end
53
52
  end
@@ -55,10 +54,10 @@ class I18nTest < Test::Unit::TestCase
55
54
  def test_update_foo_yaml_i18nclass
56
55
  Dir.mktmpdir do |dir|
57
56
  Dir.chdir(dir) do
58
- file = File.join(dir, "foo.yml")
59
- File.open(file, "w"){|f| f.write("locale: ja\nfoo: \"bar\"\n")}
60
- I18n.setup("ja", "foo.yml")
61
- assert_equal "bar", I18n.t("foo")
57
+ file = File.join(dir, 'foo.yml')
58
+ File.open(file, 'w') { |f| f.write(%Q(locale: ja\nfoo: "bar"\n)) }
59
+ I18n.setup('ja', 'foo.yml')
60
+ assert_equal 'bar', I18n.t('foo')
62
61
  end
63
62
  end
64
63
  end
@@ -66,14 +65,14 @@ class I18nTest < Test::Unit::TestCase
66
65
  def test_load_locale_yml_i18n
67
66
  Dir.mktmpdir do |dir|
68
67
  Dir.chdir(dir) do
69
- file = File.join(dir, "locale.yml")
70
- File.open(file, "w"){|f| f.write("ja:\n foo: \"bar\"\nen:\n foo: \"buz\"\n")}
68
+ file = File.join(dir, 'locale.yml')
69
+ File.open(file, 'w') { |f| f.write(%Q(ja:\n foo: "bar"\nen:\n foo: "buz"\n)) }
71
70
  I18n.setup
72
- assert_equal "bar", I18n.t("foo")
73
- assert_equal "", I18n.t("image")
74
- I18n.setup("en")
75
- assert_equal "buz", I18n.t("foo")
76
- assert_equal "Figure ", I18n.t("image")
71
+ assert_equal 'bar', I18n.t('foo')
72
+ assert_equal '', I18n.t('image')
73
+ I18n.setup('en')
74
+ assert_equal 'buz', I18n.t('foo')
75
+ assert_equal 'Figure ', I18n.t('image')
77
76
  end
78
77
  end
79
78
  end
@@ -81,8 +80,8 @@ class I18nTest < Test::Unit::TestCase
81
80
  def test_load_locale_invalid_yml
82
81
  Dir.mktmpdir do |dir|
83
82
  Dir.chdir(dir) do
84
- file = File.join(dir, "locale.yml")
85
- File.open(file, "w"){|f| f.write("local: ja\nfoo: \"bar\"\n")}
83
+ file = File.join(dir, 'locale.yml')
84
+ File.open(file, 'w') { |f| f.write(%Q(local: ja\nfoo: "bar"\n)) }
86
85
  assert_raises(ReVIEW::KeyError) do
87
86
  I18n.setup
88
87
  end
@@ -93,62 +92,62 @@ class I18nTest < Test::Unit::TestCase
93
92
  def test_custom_format
94
93
  Dir.mktmpdir do |dir|
95
94
  Dir.chdir(dir) do
96
- file = File.join(dir, "locale.yml")
97
- File.open(file, "w"){|f| f.write("locale: ja\nchapter: 第%pa章")}
98
- I18n.setup("ja")
99
- assert_equal "第a章", I18n.t("chapter", 1)
100
-
101
- File.open(file, "w"){|f| f.write("locale: ja\nchapter: 第%pA章")}
102
- I18n.setup("ja")
103
- assert_equal "第B章", I18n.t("chapter", 2)
104
-
105
- File.open(file, "w"){|f| f.write("locale: ja\nchapter: 第%pAW章")}
106
- I18n.setup("ja")
107
- assert_equal "第B章", I18n.t("chapter", 2)
108
-
109
- File.open(file, "w"){|f| f.write("locale: ja\nchapter: 第%paW章")}
110
- I18n.setup("ja")
111
- assert_equal "第b章", I18n.t("chapter", 2)
112
-
113
- File.open(file, "w"){|f| f.write("locale: ja\nchapter: 第%pR章")}
114
- I18n.setup("ja")
115
- assert_equal "第I章", I18n.t("chapter", 1)
116
-
117
- File.open(file, "w"){|f| f.write("locale: ja\nchapter: 第%pr章")}
118
- I18n.setup("ja")
119
- assert_equal "第ii章", I18n.t("chapter", 2)
120
-
121
- File.open(file, "w"){|f| f.write("locale: ja\nchapter: 第%pRW章")}
122
- I18n.setup("ja")
123
- assert_equal "第Ⅻ章", I18n.t("chapter", 12)
124
-
125
- File.open(file, "w"){|f| f.write("locale: ja\nchapter: 第%pJ章")}
126
- I18n.setup("ja")
127
- assert_equal "第二十七章", I18n.t("chapter", 27)
128
-
129
- File.open(file, "w"){|f| f.write("locale: ja\nchapter: 第%pdW章")}
130
- I18n.setup("ja")
131
- assert_equal "第1章", I18n.t("chapter", 1)
132
-
133
- File.open(file, "w"){|f| f.write("locale: ja\nchapter: 第%pdW章")}
134
- I18n.setup("ja")
135
- assert_equal "第27章", I18n.t("chapter", 27)
136
-
137
- File.open(file, "w"){|f| f.write("locale: ja\nchapter: 第%pDW章")}
138
- I18n.setup("ja")
139
- assert_equal "第1章", I18n.t("chapter", 1)
140
-
141
- File.open(file, "w"){|f| f.write("locale: ja\nchapter: 第%pDW章")}
142
- I18n.setup("ja")
143
- assert_equal "第27章", I18n.t("chapter", 27)
144
-
145
- File.open(file, "w"){|f| f.write("locale: ja\npart: Part %pRW")}
146
- I18n.setup("ja")
147
- assert_equal "Part 0", I18n.t("part", 0)
148
-
149
- File.open(file, "w"){|f| f.write("locale: ja\npart: 第%pJ部")}
150
- I18n.setup("ja")
151
- assert_equal "第一部", I18n.t("part", 1)
95
+ file = File.join(dir, 'locale.yml')
96
+ File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pa章") }
97
+ I18n.setup('ja')
98
+ assert_equal '第a章', I18n.t('chapter', 1)
99
+
100
+ File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pA章") }
101
+ I18n.setup('ja')
102
+ assert_equal '第B章', I18n.t('chapter', 2)
103
+
104
+ File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pAW章") }
105
+ I18n.setup('ja')
106
+ assert_equal '第B章', I18n.t('chapter', 2)
107
+
108
+ File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%paW章") }
109
+ I18n.setup('ja')
110
+ assert_equal '第b章', I18n.t('chapter', 2)
111
+
112
+ File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pR章") }
113
+ I18n.setup('ja')
114
+ assert_equal '第I章', I18n.t('chapter', 1)
115
+
116
+ File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pr章") }
117
+ I18n.setup('ja')
118
+ assert_equal '第ii章', I18n.t('chapter', 2)
119
+
120
+ File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pRW章") }
121
+ I18n.setup('ja')
122
+ assert_equal '第Ⅻ章', I18n.t('chapter', 12)
123
+
124
+ File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pJ章") }
125
+ I18n.setup('ja')
126
+ assert_equal '第二十七章', I18n.t('chapter', 27)
127
+
128
+ File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pdW章") }
129
+ I18n.setup('ja')
130
+ assert_equal '第1章', I18n.t('chapter', 1)
131
+
132
+ File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pdW章") }
133
+ I18n.setup('ja')
134
+ assert_equal '第27章', I18n.t('chapter', 27)
135
+
136
+ File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pDW章") }
137
+ I18n.setup('ja')
138
+ assert_equal '第1章', I18n.t('chapter', 1)
139
+
140
+ File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pDW章") }
141
+ I18n.setup('ja')
142
+ assert_equal '第27章', I18n.t('chapter', 27)
143
+
144
+ File.open(file, 'w') { |f| f.write("locale: ja\npart: Part %pRW") }
145
+ I18n.setup('ja')
146
+ assert_equal 'Part 0', I18n.t('part', 0)
147
+
148
+ File.open(file, 'w') { |f| f.write("locale: ja\npart: 第%pJ部") }
149
+ I18n.setup('ja')
150
+ assert_equal '第一部', I18n.t('part', 1)
152
151
  end
153
152
  end
154
153
  end
@@ -156,27 +155,27 @@ class I18nTest < Test::Unit::TestCase
156
155
  def test_custom_format_numbers
157
156
  Dir.mktmpdir do |dir|
158
157
  Dir.chdir(dir) do
159
- file = File.join(dir, "locale.yml")
158
+ file = File.join(dir, 'locale.yml')
160
159
 
161
- File.open(file, "w"){|f| f.write %Q|locale: ja\nformat_number_header: "%s-%pA:"| }
162
- I18n.setup("ja")
163
- assert_equal "1-B:", I18n.t("format_number_header", [1, 2])
160
+ File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%s-%pA:") }
161
+ I18n.setup('ja')
162
+ assert_equal '1-B:', I18n.t('format_number_header', [1, 2])
164
163
 
165
- File.open(file, "w"){|f| f.write %Q|locale: ja\nformat_number_header: "%s.%pa:"| }
166
- I18n.setup("ja")
167
- assert_equal "2.c:", I18n.t("format_number_header", [2, 3])
164
+ File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%s.%pa:") }
165
+ I18n.setup('ja')
166
+ assert_equal '2.c:', I18n.t('format_number_header', [2, 3])
168
167
 
169
- File.open(file, "w"){|f| f.write %Q|locale: ja\nformat_number_header: "%pA,%pAW:"| }
170
- I18n.setup("ja")
171
- assert_equal "C,D:", I18n.t("format_number_header", [3, 4])
168
+ File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%pA,%pAW:") }
169
+ I18n.setup('ja')
170
+ assert_equal 'C,D:', I18n.t('format_number_header', [3, 4])
172
171
 
173
- File.open(file, "w"){|f| f.write %Q|locale: ja\nformat_number_header: "%pJ・%pJ:"| }
174
- I18n.setup("ja")
175
- assert_equal "十二・二十六:", I18n.t("format_number_header", [12, 26])
172
+ File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%pJ・%pJ:") }
173
+ I18n.setup('ja')
174
+ assert_equal '十二・二十六:', I18n.t('format_number_header', [12, 26])
176
175
 
177
- File.open(file, "w"){|f| f.write %Q|locale: ja\nformat_number_header: "%pdW―%pdW:"| }
178
- I18n.setup("ja")
179
- assert_equal "3―12:", I18n.t("format_number_header", [3, 12])
176
+ File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%pdW―%pdW:") }
177
+ I18n.setup('ja')
178
+ assert_equal '3―12:', I18n.t('format_number_header', [3, 12])
180
179
  end
181
180
  end
182
181
  end
@@ -184,67 +183,67 @@ class I18nTest < Test::Unit::TestCase
184
183
  def test_format_with_mismatched_number_of_arguments
185
184
  Dir.mktmpdir do |dir|
186
185
  Dir.chdir(dir) do
187
- file = File.join(dir, "locale.yml")
186
+ file = File.join(dir, 'locale.yml')
188
187
 
189
- File.open(file, "w"){|f| f.write %Q|locale: ja\nformat_number_header: "%2$d"| }
190
- I18n.setup("ja")
191
- assert_equal "10", I18n.t("format_number_header", [1, 10])
188
+ File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%2$d") }
189
+ I18n.setup('ja')
190
+ assert_equal '10', I18n.t('format_number_header', [1, 10])
192
191
 
193
- File.open(file, "w"){|f| f.write %Q|locale: ja\nformat_number_header: "%2$d-%1$d"| }
194
- I18n.setup("ja")
192
+ File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%2$d-%1$d") }
193
+ I18n.setup('ja')
195
194
  # ERROR: returns raw format
196
- assert_equal "%2$d-%1$d", I18n.t("format_number_header", [1])
195
+ assert_equal '%2$d-%1$d', I18n.t('format_number_header', [1])
197
196
  end
198
197
  end
199
198
  end
200
199
 
201
200
  def test_ja
202
- I18n.setup("ja")
203
- assert_equal "", I18n.t("image")
204
- assert_equal "", I18n.t("table")
205
- assert_equal "第1章", I18n.t("chapter", 1)
206
- assert_equal "etc", I18n.t("etc")
201
+ I18n.setup('ja')
202
+ assert_equal '', I18n.t('image')
203
+ assert_equal '', I18n.t('table')
204
+ assert_equal '第1章', I18n.t('chapter', 1)
205
+ assert_equal 'etc', I18n.t('etc')
207
206
  end
208
207
 
209
208
  def test_ja_with_user_i18n
210
- i18n = I18n.new("ja")
211
- i18n.update({"image" => ""}, "ja")
212
- assert_equal "", i18n.t("image")
213
- assert_equal "", i18n.t("table")
214
- assert_equal "第1章", i18n.t("chapter", 1)
215
- assert_equal "etc", i18n.t("etc")
209
+ i18n = I18n.new('ja')
210
+ i18n.update({ 'image' => '' }, 'ja')
211
+ assert_equal '', i18n.t('image')
212
+ assert_equal '', i18n.t('table')
213
+ assert_equal '第1章', i18n.t('chapter', 1)
214
+ assert_equal 'etc', i18n.t('etc')
216
215
  end
217
216
 
218
217
  def test_en
219
- I18n.setup "en"
220
- assert_equal "Figure ", I18n.t("image")
221
- assert_equal "Table ", I18n.t("table")
222
- assert_equal "Chapter 1", I18n.t("chapter", 1)
223
- assert_equal "etc", I18n.t("etc")
218
+ I18n.setup 'en'
219
+ assert_equal 'Figure ', I18n.t('image')
220
+ assert_equal 'Table ', I18n.t('table')
221
+ assert_equal 'Chapter 1', I18n.t('chapter', 1)
222
+ assert_equal 'etc', I18n.t('etc')
224
223
  end
225
224
 
226
225
  def test_nil
227
- I18n.setup "nil"
228
- assert_equal "image", I18n.t("image")
229
- assert_equal "table", I18n.t("table")
230
- assert_equal "etc", I18n.t("etc")
226
+ I18n.setup 'nil'
227
+ assert_equal 'image', I18n.t('image')
228
+ assert_equal 'table', I18n.t('table')
229
+ assert_equal 'etc', I18n.t('etc')
231
230
  end
232
231
 
233
232
  def test_htmlbuilder
234
233
  _setup_htmlbuilder
235
234
  actual = compile_block("={test} this is test.\n")
236
- assert_equal %Q|<h1 id="test"><a id="h1"></a><span class="secno">Chapter 1. </span>this is test.</h1>\n|, actual
235
+ assert_equal %Q(<h1 id="test"><a id="h1"></a><span class="secno">Chapter 1. </span>this is test.</h1>\n), actual
237
236
  end
238
237
 
239
238
  def _setup_htmlbuilder
240
- I18n.setup "en"
241
- @builder = HTMLBuilder.new()
239
+ I18n.setup 'en'
240
+ @builder = HTMLBuilder.new
242
241
  @config = ReVIEW::Configure[
243
- "secnolevel" => 2, # for IDGXMLBuilder, HTMLBuilder
244
- "stylesheet" => nil, # for HTMLBuilder
245
- "ext" => ".re"
242
+ 'secnolevel' => 2, # for IDGXMLBuilder, HTMLBuilder
243
+ 'stylesheet' => nil, # for HTMLBuilder
244
+ 'ext' => '.re'
246
245
  ]
247
- @book = Book::Base.new(".")
246
+ @book = Book::Base.new('.')
248
247
  @book.config = @config
249
248
  @compiler = ReVIEW::Compiler.new(@builder)
250
249
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
@@ -253,39 +252,49 @@ class I18nTest < Test::Unit::TestCase
253
252
  end
254
253
 
255
254
  def test_update
256
- i18n = ReVIEW::I18n.new("ja")
257
- hash = {"foo"=>"bar"}
255
+ i18n = ReVIEW::I18n.new('ja')
256
+ hash = { 'foo' => 'bar' }
258
257
  i18n.update(hash)
259
- assert_equal "bar", i18n.t("foo")
258
+ assert_equal 'bar', i18n.t('foo')
260
259
  end
261
260
 
262
261
  def test_update_newlocale
263
- i18n = ReVIEW::I18n.new("ja")
264
- hash = {"foo"=>"bar"}
265
- i18n.update(hash, "abc")
266
- i18n.locale = "abc"
267
- assert_equal "bar", i18n.t("foo")
262
+ i18n = ReVIEW::I18n.new('ja')
263
+ hash = { 'foo' => 'bar' }
264
+ i18n.update(hash, 'abc')
265
+ i18n.locale = 'abc'
266
+ assert_equal 'bar', i18n.t('foo')
268
267
  end
269
268
 
270
269
  def test_ja_appendix_alphabet
271
- i18n = I18n.new("ja")
272
- i18n.update({"appendix" => "付録%pA"}, "ja")
273
- assert_equal "付録A", i18n.t("appendix", 1)
274
- assert_equal "付録B", i18n.t("appendix", 2)
275
- assert_equal "付録C", i18n.t("appendix", 3)
270
+ i18n = I18n.new('ja')
271
+ i18n.update({ 'appendix' => '付録%pA' }, 'ja')
272
+ assert_equal '付録A', i18n.t('appendix', 1)
273
+ assert_equal '付録B', i18n.t('appendix', 2)
274
+ assert_equal '付録C', i18n.t('appendix', 3)
275
+ end
276
+
277
+ def test_ja_part
278
+ i18n = I18n.new('ja')
279
+ assert_equal '第III部', i18n.t('part', 3)
280
+ assert_equal 'III', i18n.t('part_short', 3)
281
+ i18n.update({ 'part' => '第%pRW部' }, 'ja')
282
+ i18n.update({ 'part_short' => '%pRW' }, 'ja')
283
+ assert_equal '第Ⅲ部', i18n.t('part', 3)
284
+ assert_equal 'Ⅲ', i18n.t('part_short', 3)
276
285
  end
277
286
 
278
287
  def test_i18n_error
279
288
  I18n.setup
280
289
  assert_raises NotImplementedError do
281
- I18n.i18n("ja")
290
+ I18n.i18n('ja')
282
291
  end
283
292
  assert_raises NotImplementedError do
284
- I18n.i18n("ja",{})
293
+ I18n.i18n('ja', {})
285
294
  end
286
295
  end
287
296
 
288
297
  def teardown
289
- I18n.setup "ja"
298
+ I18n.setup 'ja'
290
299
  end
291
300
  end