review 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +1 -0
- data/ChangeLog +87 -0
- data/bin/review-check +2 -2
- data/bin/review-compile +15 -30
- data/bin/review-index +1 -1
- data/bin/review-init +12 -7
- data/bin/review-vol +9 -1
- data/doc/catalog.ja.md +53 -0
- data/doc/catalog.md +52 -0
- data/doc/format.ja.md +734 -0
- data/doc/format.md +746 -0
- data/doc/format_idg.ja.md +203 -0
- data/doc/{quickstart.rdoc → quickstart.ja.md} +138 -104
- data/doc/quickstart.md +252 -0
- data/doc/sample.yml +216 -48
- data/lib/epubmaker.rb +0 -1
- data/lib/epubmaker/content.rb +2 -2
- data/lib/epubmaker/epubcommon.rb +440 -0
- data/lib/epubmaker/epubv2.rb +8 -418
- data/lib/epubmaker/epubv3.rb +67 -61
- data/lib/epubmaker/producer.rb +60 -19
- data/lib/review/book.rb +1 -3
- data/lib/review/book/base.rb +18 -11
- data/lib/review/book/chapter.rb +5 -24
- data/lib/review/book/compilable.rb +5 -1
- data/lib/review/book/index.rb +48 -17
- data/lib/review/book/page_metric.rb +17 -8
- data/lib/review/book/part.rb +12 -2
- data/lib/review/book/volume.rb +3 -2
- data/lib/review/builder.rb +30 -10
- data/lib/review/compiler.rb +6 -4
- data/lib/review/configure.rb +3 -3
- data/lib/review/epubmaker.rb +56 -26
- data/lib/review/htmlbuilder.rb +33 -42
- data/lib/review/htmlutils.rb +12 -7
- data/lib/review/i18n.rb +77 -17
- data/lib/review/i18n.yml +80 -4
- data/lib/review/idgxmlbuilder.rb +27 -57
- data/lib/review/inaobuilder.rb +3 -3
- data/lib/review/latexbuilder.rb +90 -67
- data/lib/review/layout.tex.erb +54 -7
- data/lib/review/markdownbuilder.rb +21 -3
- data/lib/review/pdfmaker.rb +67 -38
- data/lib/review/sec_counter.rb +1 -1
- data/lib/review/tocparser.rb +9 -5
- data/lib/review/topbuilder.rb +6 -6
- data/lib/review/version.rb +1 -1
- data/review.gemspec +3 -1
- data/test/book_test_helper.rb +1 -1
- data/test/sample-book/README.md +2 -0
- data/test/sample-book/src/Rakefile +31 -0
- data/test/sample-book/src/_cover.html +0 -0
- data/test/sample-book/src/catalog.yml +10 -0
- data/test/sample-book/src/ch01.re +0 -0
- data/test/sample-book/src/ch02.re +0 -0
- data/test/sample-book/src/config.yml +160 -32
- data/test/sample-book/src/images/ch01-imgsample.jpg +0 -0
- data/test/sample-book/src/images/cover.jpg +0 -0
- data/test/sample-book/src/preface.re +0 -0
- data/test/sample-book/src/sty/jumoline.sty +0 -0
- data/test/sample-book/src/sty/reviewmacro.sty +18 -0
- data/test/sample-book/src/style.css +0 -0
- data/test/test_book.rb +25 -27
- data/test/test_book_chapter.rb +4 -73
- data/test/test_book_part.rb +5 -4
- data/test/test_builder.rb +3 -3
- data/test/test_epub3maker.rb +527 -0
- data/test/test_epubmaker.rb +6 -6
- data/test/test_htmlbuilder.rb +143 -6
- data/test/test_i18n.rb +95 -10
- data/test/test_idgxmlbuilder.rb +28 -2
- data/test/test_index.rb +109 -1
- data/test/test_latexbuilder.rb +51 -0
- data/test/test_markdownbuilder.rb +54 -1
- data/test/test_pdfmaker.rb +7 -6
- data/test/test_review_ext.rb +31 -0
- data/test/test_topbuilder.rb +3 -1
- metadata +46 -13
- data/doc/catalog.rdoc +0 -49
- data/doc/format.rdoc +0 -618
- data/doc/format_idg.rdoc +0 -180
- data/doc/libepubmaker/config.yml +0 -207
- data/lib/epubmaker/resource.rb +0 -82
- data/test/sample-book/src/CHAPS +0 -2
- data/test/sample-book/src/PREDEF +0 -1
data/test/test_epubmaker.rb
CHANGED
@@ -11,7 +11,7 @@ class EPUBMakerTest < Test::Unit::TestCase
|
|
11
11
|
@producer.merge_params({
|
12
12
|
"bookname" => "sample",
|
13
13
|
"title" => "Sample Book",
|
14
|
-
"
|
14
|
+
"epubversion" => 2,
|
15
15
|
"urnid" => "http://example.jp/",
|
16
16
|
"date" => "2011-01-01",
|
17
17
|
"language" => "en",
|
@@ -420,7 +420,7 @@ EOT
|
|
420
420
|
end
|
421
421
|
|
422
422
|
def test_stage3_flat
|
423
|
-
@producer.merge_params({"flattoc" => true, "flattocindent" => false})
|
423
|
+
@producer.merge_params({"epubmaker" => {"flattoc" => true, "flattocindent" => false}})
|
424
424
|
stage3
|
425
425
|
@producer.mytoc(@output)
|
426
426
|
expect = <<EOT
|
@@ -497,7 +497,7 @@ EOT
|
|
497
497
|
|
498
498
|
def test_colophon_default
|
499
499
|
@producer.params["aut"] = ["Mr.Smith"]
|
500
|
-
@producer.params["
|
500
|
+
@producer.params["pbl"] = ["BLUEPRINT"]
|
501
501
|
@producer.colophon(@output)
|
502
502
|
expect = <<EOT
|
503
503
|
<?xml version="1.0" encoding="UTF-8"?>
|
@@ -513,7 +513,7 @@ EOT
|
|
513
513
|
<div class="colophon">
|
514
514
|
<p class="title">Sample Book</p>
|
515
515
|
<div class="pubhistory">
|
516
|
-
<p>2011
|
516
|
+
<p>published by Jan. 1, 2011</p>
|
517
517
|
</div>
|
518
518
|
<table class="colophon">
|
519
519
|
<tr><th>Author</th><td>Mr.Smith</td></tr>
|
@@ -528,7 +528,7 @@ EOT
|
|
528
528
|
|
529
529
|
def test_colophon_pht
|
530
530
|
@producer.params["aut"] = ["Mr.Smith"]
|
531
|
-
@producer.params["
|
531
|
+
@producer.params["pbl"] = ["BLUEPRINT"]
|
532
532
|
@producer.params["pht"] = ["Mrs.Smith"]
|
533
533
|
@producer.colophon(@output)
|
534
534
|
expect = <<EOT
|
@@ -545,7 +545,7 @@ EOT
|
|
545
545
|
<div class="colophon">
|
546
546
|
<p class="title">Sample Book</p>
|
547
547
|
<div class="pubhistory">
|
548
|
-
<p>2011
|
548
|
+
<p>published by Jan. 1, 2011</p>
|
549
549
|
</div>
|
550
550
|
<table class="colophon">
|
551
551
|
<tr><th>Author</th><td>Mr.Smith</td></tr>
|
data/test/test_htmlbuilder.rb
CHANGED
@@ -10,6 +10,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
10
10
|
include ReVIEW
|
11
11
|
|
12
12
|
def setup
|
13
|
+
ReVIEW::I18n.setup
|
13
14
|
@builder = HTMLBuilder.new()
|
14
15
|
@config = ReVIEW::Configure.values
|
15
16
|
@config.merge!({
|
@@ -24,6 +25,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
24
25
|
@chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
|
25
26
|
location = Location.new(nil, nil)
|
26
27
|
@builder.bind(@compiler, @chapter, location)
|
28
|
+
I18n.setup("ja")
|
27
29
|
end
|
28
30
|
|
29
31
|
def test_xmlns_ops_prefix_epub3
|
@@ -68,7 +70,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
68
70
|
end
|
69
71
|
end
|
70
72
|
actual = compile_block("={test} this is test.\n")
|
71
|
-
assert_equal %Q|<h1 id="test"><a id="
|
73
|
+
assert_equal %Q|<h1 id="test"><a id="hI"></a>付録I this is test.</h1>\n|, actual
|
72
74
|
end
|
73
75
|
|
74
76
|
def test_headline_level2_postdef_roman
|
@@ -79,7 +81,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
79
81
|
end
|
80
82
|
end
|
81
83
|
actual = compile_block("=={test} this is test.\n")
|
82
|
-
assert_equal %Q|\n<h2 id="test"><a id="
|
84
|
+
assert_equal %Q|\n<h2 id="test"><a id="hI-1"></a>I.1 this is test.</h2>\n|, actual
|
83
85
|
end
|
84
86
|
|
85
87
|
def test_headline_level1_postdef_alpha
|
@@ -90,7 +92,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
90
92
|
end
|
91
93
|
end
|
92
94
|
actual = compile_block("={test} this is test.\n")
|
93
|
-
assert_equal %Q|<h1 id="test"><a id="
|
95
|
+
assert_equal %Q|<h1 id="test"><a id="hA"></a>付録A this is test.</h1>\n|, actual
|
94
96
|
end
|
95
97
|
|
96
98
|
def test_headline_level2_postdef_alpha
|
@@ -101,7 +103,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
101
103
|
end
|
102
104
|
end
|
103
105
|
actual = compile_block("=={test} this is test.\n")
|
104
|
-
assert_equal %Q|\n<h2 id="test"><a id="
|
106
|
+
assert_equal %Q|\n<h2 id="test"><a id="hA-1"></a>A.1 this is test.</h2>\n|, actual
|
105
107
|
end
|
106
108
|
|
107
109
|
def test_headline_level1_without_secno
|
@@ -226,6 +228,38 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
226
228
|
assert_equal %Q|test 「1.1.1 te_st」 test2|, actual
|
227
229
|
end
|
228
230
|
|
231
|
+
def test_inline_hd_chap_postdef_roman
|
232
|
+
@chapter.book.config["appendix_format"] = "roman"
|
233
|
+
@chapter.instance_eval do
|
234
|
+
def on_APPENDIX?
|
235
|
+
true
|
236
|
+
end
|
237
|
+
end
|
238
|
+
def @chapter.headline_index
|
239
|
+
items = [Book::HeadlineIndex::Item.new("test", [1], "te_st")]
|
240
|
+
Book::HeadlineIndex.new(items, self)
|
241
|
+
end
|
242
|
+
|
243
|
+
actual = compile_inline("test @<hd>{test} test2")
|
244
|
+
assert_equal %Q|test 「I.1 te_st」 test2|, actual
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_inline_hd_chap_postdef_alpha
|
248
|
+
@chapter.book.config["appendix_format"] = "alpha"
|
249
|
+
@chapter.instance_eval do
|
250
|
+
def on_APPENDIX?
|
251
|
+
true
|
252
|
+
end
|
253
|
+
end
|
254
|
+
def @chapter.headline_index
|
255
|
+
items = [Book::HeadlineIndex::Item.new("test", [1], "te_st")]
|
256
|
+
Book::HeadlineIndex.new(items, self)
|
257
|
+
end
|
258
|
+
|
259
|
+
actual = compile_inline("test @<hd>{test} test2")
|
260
|
+
assert_equal %Q|test 「A.1 te_st」 test2|, actual
|
261
|
+
end
|
262
|
+
|
229
263
|
def test_inline_uchar
|
230
264
|
actual = compile_inline("test @<uchar>{2460} test2")
|
231
265
|
assert_equal %Q|test ① test2|, actual
|
@@ -259,6 +293,31 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
259
293
|
assert_equal "<span class=\"equation\"><math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mfrac><mrow><mo stretchy='false'>-</mo><mi>b</mi><mo stretchy='false'>±</mo><msqrt><mrow><msup><mi>b</mi><mn>2</mn></msup><mo stretchy='false'>-</mo><mn>4</mn><mi>a</mi><mi>c</mi></mrow></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac></math></span>", actual
|
260
294
|
end
|
261
295
|
|
296
|
+
def test_inline_imgref
|
297
|
+
def @chapter.image(id)
|
298
|
+
item = Book::ImageIndex::Item.new("sampleimg", 1, 'sample photo')
|
299
|
+
item.instance_eval{@path="./images/chap1-sampleimg.png"}
|
300
|
+
item
|
301
|
+
end
|
302
|
+
|
303
|
+
actual = compile_block "@<imgref>{sampleimg}\n"
|
304
|
+
expected = "<p>図1.1「sample photo」</p>\n"
|
305
|
+
assert_equal expected, actual
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_inline_imgref2
|
309
|
+
def @chapter.image(id)
|
310
|
+
item = Book::NumberlessImageIndex::Item.new("sampleimg", 1)
|
311
|
+
item.instance_eval{@path="./images/chap1-sampleimg.png"}
|
312
|
+
item
|
313
|
+
end
|
314
|
+
|
315
|
+
actual = compile_block "@<imgref>{sampleimg}\n"
|
316
|
+
expected = "<p>図1.1</p>\n"
|
317
|
+
assert_equal expected, actual
|
318
|
+
end
|
319
|
+
|
320
|
+
|
262
321
|
def test_quote
|
263
322
|
actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
|
264
323
|
assert_equal %Q|<blockquote><p>foobar</p>\n<p>buz</p></blockquote>\n|, actual
|
@@ -409,12 +468,67 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
409
468
|
begin
|
410
469
|
require 'pygments'
|
411
470
|
rescue LoadError
|
471
|
+
$stderr.puts "skip test_list_pygments_lang (cannot find pygments.rb)"
|
412
472
|
return true
|
413
473
|
end
|
414
474
|
@book.config["pygments"] = true
|
415
475
|
actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
|
416
476
|
|
417
|
-
assert_equal %Q|<div class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b><&>_</p>\n<pre class="list">test1\ntest1.5\n\ntest
|
477
|
+
assert_equal %Q|<div class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b><&>_</p>\n<pre class="list">test1\ntest1.5\n\ntest<i>2</i>\n</pre>\n</div>\n|, actual
|
478
|
+
end
|
479
|
+
|
480
|
+
def test_list_pygments_lang
|
481
|
+
def @chapter.list(id)
|
482
|
+
Book::ListIndex::Item.new("samplelist",1)
|
483
|
+
end
|
484
|
+
begin
|
485
|
+
require 'pygments'
|
486
|
+
rescue LoadError
|
487
|
+
$stderr.puts "skip test_list_pygments_lang (cannot find pygments.rb)"
|
488
|
+
return true
|
489
|
+
end
|
490
|
+
@book.config["pygments"] = true
|
491
|
+
actual = compile_block("//list[samplelist][this is @<b>{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
|
492
|
+
|
493
|
+
assert_equal %Q|<div class=\"caption-code\">\n<p class=\"caption\">リスト1.1: this is <b>test</b><&>_</p>\n| +
|
494
|
+
%Q|<pre class=\"list\"><span style=\"color: #008000; font-weight: bold\">def</span> <span style=\"color: #0000FF\">foo</span>(a1, a2<span style=\"color: #666666\">=</span><span style=\"color: #19177C\">:test</span>)\n| +
|
495
|
+
%Q| (<span style=\"color: #666666\">1.</span>.<span style=\"color: #666666\">3</span>)<span style=\"color: #666666\">.</span>times{<span style=\"color: #666666\">\|</span>i<span style=\"color: #666666\">\|</span> a<span style=\"color: #666666\">.</span>include?(<span style=\"color: #19177C\">:foo</span>)}\n| +
|
496
|
+
%Q| <span style=\"color: #008000; font-weight: bold\">return</span> <span style=\"color: #008000\">true</span>\n| +
|
497
|
+
%Q|<span style=\"color: #008000; font-weight: bold\">end</span>\n| +
|
498
|
+
%Q|</pre>\n| +
|
499
|
+
%Q|</div>\n|, actual
|
500
|
+
end
|
501
|
+
|
502
|
+
def test_list_pygments_nulllang
|
503
|
+
def @chapter.list(id)
|
504
|
+
Book::ListIndex::Item.new("samplelist",1)
|
505
|
+
end
|
506
|
+
begin
|
507
|
+
require 'pygments'
|
508
|
+
rescue LoadError
|
509
|
+
$stderr.puts "skip test_list_pygments_nulllang (cannot find pygments.rb)"
|
510
|
+
return true
|
511
|
+
end
|
512
|
+
@book.config["pygments"] = true
|
513
|
+
actual = compile_block("//list[samplelist][this is @<b>{test}<&>_][]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
|
514
|
+
|
515
|
+
assert_equal "<div class=\"caption-code\">\n<p class=\"caption\">リスト1.1: this is <b>test</b><&>_</p>\n<pre class=\"list\">def foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n</pre>\n</div>\n", actual
|
516
|
+
end
|
517
|
+
|
518
|
+
def test_listnum_pygments_lang
|
519
|
+
def @chapter.list(id)
|
520
|
+
Book::ListIndex::Item.new("samplelist",1)
|
521
|
+
end
|
522
|
+
begin
|
523
|
+
require 'pygments'
|
524
|
+
rescue LoadError
|
525
|
+
$stderr.puts "skip test_listnum_pygments_lang (cannot find pygments.rb)"
|
526
|
+
return true
|
527
|
+
end
|
528
|
+
@book.config["pygments"] = true
|
529
|
+
actual = compile_block("//listnum[samplelist][this is @<b>{test}<&>_][ruby]{\ndef foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n//}\n")
|
530
|
+
|
531
|
+
assert_equal "<div class=\"code\">\n<p class=\"caption\">リスト1.1: this is <b>test</b><&>_</p>\n<div class=\"highlight\" style=\"background: #f8f8f8\"><pre style=\"line-height: 125%\"><span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">1</span> <span style=\"color: #008000; font-weight: bold\">def</span> <span style=\"color: #0000FF\">foo</span>(a1, a2<span style=\"color: #666666\">=</span><span style=\"color: #19177C\">:test</span>)\n<span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">2</span> (<span style=\"color: #666666\">1.</span>.<span style=\"color: #666666\">3</span>)<span style=\"color: #666666\">.</span>times{<span style=\"color: #666666\">|</span>i<span style=\"color: #666666\">|</span> a<span style=\"color: #666666\">.</span>include?(<span style=\"color: #19177C\">:foo</span>)}\n<span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">3</span> <span style=\"color: #008000; font-weight: bold\">return</span> <span style=\"color: #008000\">true</span>\n<span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">4</span> <span style=\"color: #008000; font-weight: bold\">end</span>\n</pre></div>\n</div>\n", actual
|
418
532
|
end
|
419
533
|
|
420
534
|
def test_emlist
|
@@ -422,6 +536,18 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
422
536
|
assert_equal %Q|<div class="emlist-code">\n<pre class="emlist">lineA\nlineB\n</pre>\n</div>\n|, actual
|
423
537
|
end
|
424
538
|
|
539
|
+
def test_emlist_pygments_lang
|
540
|
+
begin
|
541
|
+
require 'pygments'
|
542
|
+
rescue LoadError
|
543
|
+
$stderr.puts "skip test_emlist_pygments_lang (cannot find pygments.rb)"
|
544
|
+
return true
|
545
|
+
end
|
546
|
+
@book.config["pygments"] = true
|
547
|
+
actual = compile_block("//emlist[][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
|
548
|
+
assert_equal "<div class=\"emlist-code\">\n<pre class=\"emlist\"><span style=\"color: #008000; font-weight: bold\">SELECT</span> <span style=\"color: #008000; font-weight: bold\">COUNT</span>(<span style=\"color: #666666\">*</span>) <span style=\"color: #008000; font-weight: bold\">FROM</span> tests <span style=\"color: #008000; font-weight: bold\">WHERE</span> tests.<span style=\"color: #008000; font-weight: bold\">no</span> <span style=\"color: #666666\">></span> <span style=\"color: #666666\">10</span> <span style=\"color: #008000; font-weight: bold\">AND</span> test.name <span style=\"color: #008000; font-weight: bold\">LIKE</span> <span style=\"color: #BA2121\">'ABC%'</span>\n</pre>\n</div>\n", actual
|
549
|
+
end
|
550
|
+
|
425
551
|
def test_emlist_caption
|
426
552
|
actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n")
|
427
553
|
assert_equal %Q|<div class="emlist-code">\n<p class="caption">cap1</p>\n<pre class="emlist">lineA\nlineB\n</pre>\n</div>\n|, actual
|
@@ -443,6 +569,17 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
443
569
|
assert_equal %Q|<div class="cmd-code">\n<pre class="cmd">lineA\nlineB\n</pre>\n</div>\n|, actual
|
444
570
|
end
|
445
571
|
|
572
|
+
def test_cmd_pygments
|
573
|
+
begin
|
574
|
+
require 'pygments'
|
575
|
+
rescue LoadError
|
576
|
+
return true
|
577
|
+
end
|
578
|
+
@book.config["pygments"] = true
|
579
|
+
actual = compile_block("//cmd{\nlineA\nlineB\n//}\n")
|
580
|
+
assert_equal "<div class=\"cmd-code\">\n<pre class=\"cmd\"><span style=\"color: #888888\">lineA</span>\n<span style=\"color: #888888\">lineB</span>\n</pre>\n</div>\n", actual
|
581
|
+
end
|
582
|
+
|
446
583
|
def test_cmd_caption
|
447
584
|
actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n")
|
448
585
|
assert_equal %Q|<div class="cmd-code">\n<p class="caption">cap1</p>\n<pre class="cmd">lineA\nlineB\n</pre>\n</div>\n|, actual
|
@@ -574,7 +711,7 @@ EOS
|
|
574
711
|
</div>
|
575
712
|
|
576
713
|
<h3><a id="h1-0-1"></a>next level</h3>
|
577
|
-
<p>this is test
|
714
|
+
<p>this is コラム「test」.</p>
|
578
715
|
EOS
|
579
716
|
|
580
717
|
assert_equal expected, column_helper(review)
|
data/test/test_i18n.rb
CHANGED
@@ -32,10 +32,69 @@ class I18nTest < Test::Unit::TestCase
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
def test_load_foo_yaml
|
37
|
+
Dir.mktmpdir do |dir|
|
38
|
+
Dir.chdir(dir) do
|
39
|
+
file = File.join(dir, "foo.yml")
|
40
|
+
File.open(file, "w"){|f| f.write("locale: ja\nfoo: \"bar\"\n")}
|
41
|
+
I18n.setup("ja","foo.yml")
|
42
|
+
assert_equal "bar", I18n.t("foo")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_update_foo_yaml
|
48
|
+
Dir.mktmpdir do |dir|
|
49
|
+
Dir.chdir(dir) do
|
50
|
+
file = File.join(dir, "foo.yml")
|
51
|
+
File.open(file, "w"){|f| f.write("locale: ja\nfoo: \"bar\"\n")}
|
52
|
+
i18n = ReVIEW::I18n.new("ja")
|
53
|
+
i18n.update_localefile(File.join(Dir.pwd, "foo.yml"))
|
54
|
+
assert_equal "bar", i18n.t("foo")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_update_foo_yaml_i18nclass
|
60
|
+
Dir.mktmpdir do |dir|
|
61
|
+
Dir.chdir(dir) do
|
62
|
+
file = File.join(dir, "foo.yml")
|
63
|
+
File.open(file, "w"){|f| f.write("locale: ja\nfoo: \"bar\"\n")}
|
64
|
+
I18n.setup("ja", "foo.yml")
|
65
|
+
assert_equal "bar", I18n.t("foo")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_load_locale_yml_i18n
|
71
|
+
Dir.mktmpdir do |dir|
|
72
|
+
Dir.chdir(dir) do
|
73
|
+
file = File.join(dir, "locale.yml")
|
74
|
+
File.open(file, "w"){|f| f.write("ja:\n foo: \"bar\"\nen:\n foo: \"buz\"\n")}
|
75
|
+
I18n.setup
|
76
|
+
assert_equal "bar", I18n.t("foo")
|
77
|
+
I18n.setup("en")
|
78
|
+
assert_equal "buz", I18n.t("foo")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_load_locale_invalid_yml
|
84
|
+
Dir.mktmpdir do |dir|
|
85
|
+
Dir.chdir(dir) do
|
86
|
+
file = File.join(dir, "locale.yml")
|
87
|
+
File.open(file, "w"){|f| f.write("local: ja\nfoo: \"bar\"\n")}
|
88
|
+
assert_raises(ReVIEW::KeyError) do
|
89
|
+
I18n.setup
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
35
94
|
end
|
36
95
|
|
37
96
|
def test_ja
|
38
|
-
I18n.
|
97
|
+
I18n.setup("ja")
|
39
98
|
assert_equal "図", I18n.t("image")
|
40
99
|
assert_equal "表", I18n.t("table")
|
41
100
|
assert_equal "第1章", I18n.t("chapter", 1)
|
@@ -43,15 +102,16 @@ class I18nTest < Test::Unit::TestCase
|
|
43
102
|
end
|
44
103
|
|
45
104
|
def test_ja_with_user_i18n
|
46
|
-
I18n.
|
47
|
-
|
48
|
-
assert_equal "
|
49
|
-
assert_equal "
|
50
|
-
assert_equal "
|
105
|
+
i18n = I18n.new("ja")
|
106
|
+
i18n.update({"image" => "ず"}, "ja")
|
107
|
+
assert_equal "ず", i18n.t("image")
|
108
|
+
assert_equal "表", i18n.t("table")
|
109
|
+
assert_equal "第1章", i18n.t("chapter", 1)
|
110
|
+
assert_equal "etc", i18n.t("etc")
|
51
111
|
end
|
52
112
|
|
53
113
|
def test_en
|
54
|
-
I18n.
|
114
|
+
I18n.setup "en"
|
55
115
|
assert_equal "Figure ", I18n.t("image")
|
56
116
|
assert_equal "Table ", I18n.t("table")
|
57
117
|
assert_equal "Chapter 1", I18n.t("chapter", 1)
|
@@ -59,7 +119,7 @@ class I18nTest < Test::Unit::TestCase
|
|
59
119
|
end
|
60
120
|
|
61
121
|
def test_nil
|
62
|
-
I18n.
|
122
|
+
I18n.setup "nil"
|
63
123
|
assert_equal "image", I18n.t("image")
|
64
124
|
assert_equal "table", I18n.t("table")
|
65
125
|
assert_equal "etc", I18n.t("etc")
|
@@ -72,7 +132,7 @@ class I18nTest < Test::Unit::TestCase
|
|
72
132
|
end
|
73
133
|
|
74
134
|
def _setup_htmlbuilder
|
75
|
-
I18n.
|
135
|
+
I18n.setup "en"
|
76
136
|
@builder = HTMLBuilder.new()
|
77
137
|
@config = {
|
78
138
|
"secnolevel" => 2, # for IDGXMLBuilder, HTMLBuilder
|
@@ -89,7 +149,32 @@ class I18nTest < Test::Unit::TestCase
|
|
89
149
|
@builder.bind(@compiler, @chapter, location)
|
90
150
|
end
|
91
151
|
|
152
|
+
def test_update
|
153
|
+
i18n = ReVIEW::I18n.new("ja")
|
154
|
+
hash = {"foo"=>"bar"}
|
155
|
+
i18n.update(hash)
|
156
|
+
assert_equal "bar", i18n.t("foo")
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_update_newlocale
|
160
|
+
i18n = ReVIEW::I18n.new("ja")
|
161
|
+
hash = {"foo"=>"bar"}
|
162
|
+
i18n.update(hash, "abc")
|
163
|
+
i18n.locale = "abc"
|
164
|
+
assert_equal "bar", i18n.t("foo")
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_i18n_error
|
168
|
+
I18n.setup
|
169
|
+
assert_raises NotImplementedError do
|
170
|
+
I18n.i18n("ja")
|
171
|
+
end
|
172
|
+
assert_raises NotImplementedError do
|
173
|
+
I18n.i18n("ja",{})
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
92
177
|
def teardown
|
93
|
-
I18n.
|
178
|
+
I18n.setup "ja"
|
94
179
|
end
|
95
180
|
end
|
data/test/test_idgxmlbuilder.rb
CHANGED
@@ -25,6 +25,7 @@ class IDGXMLBuidlerTest < Test::Unit::TestCase
|
|
25
25
|
@chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
|
26
26
|
location = Location.new(nil, nil)
|
27
27
|
@builder.bind(@compiler, @chapter, location)
|
28
|
+
I18n.setup("ja")
|
28
29
|
end
|
29
30
|
|
30
31
|
def test_headline_level1
|
@@ -136,12 +137,12 @@ class IDGXMLBuidlerTest < Test::Unit::TestCase
|
|
136
137
|
|
137
138
|
def test_inline_ttb
|
138
139
|
actual = compile_inline("@<ttb>{test * <>\"}")
|
139
|
-
assert_equal %Q|<tt style='bold'>test * <>"</tt
|
140
|
+
assert_equal %Q|<tt style='bold'>test * <>"</tt>|, actual
|
140
141
|
end
|
141
142
|
|
142
143
|
def test_inline_ttbold
|
143
144
|
actual = compile_inline("@<ttbold>{test * <>\"}")
|
144
|
-
assert_equal %Q|<tt style='bold'>test * <>"</tt
|
145
|
+
assert_equal %Q|<tt style='bold'>test * <>"</tt>|, actual
|
145
146
|
end
|
146
147
|
|
147
148
|
def test_inline_balloon
|
@@ -550,6 +551,31 @@ EOS
|
|
550
551
|
assert_equal "nor\nmal", compile_inline("@<raw>{|idgxml|nor\\nmal}")
|
551
552
|
end
|
552
553
|
|
554
|
+
def test_inline_imgref
|
555
|
+
def @chapter.image(id)
|
556
|
+
item = Book::ImageIndex::Item.new("sampleimg", 1, 'sample photo')
|
557
|
+
item.instance_eval{@path="./images/chap1-sampleimg.png"}
|
558
|
+
item
|
559
|
+
end
|
560
|
+
|
561
|
+
actual = compile_block "@<imgref>{sampleimg}\n"
|
562
|
+
expected = "<p><span type='image'>図1.1「sample photo」</span></p>"
|
563
|
+
assert_equal expected, actual
|
564
|
+
end
|
565
|
+
|
566
|
+
def test_inline_imgref2
|
567
|
+
def @chapter.image(id)
|
568
|
+
item = Book::NumberlessImageIndex::Item.new("sampleimg", 1)
|
569
|
+
item.instance_eval{@path="./images/chap1-sampleimg.png"}
|
570
|
+
item
|
571
|
+
end
|
572
|
+
|
573
|
+
actual = compile_block "@<imgref>{sampleimg}\n"
|
574
|
+
expected = "<p><span type='image'>図1.1</span></p>"
|
575
|
+
assert_equal expected, actual
|
576
|
+
end
|
577
|
+
|
578
|
+
|
553
579
|
def test_block_raw0
|
554
580
|
actual = compile_block("//raw[<>!\"\\n& ]\n")
|
555
581
|
expected = %Q(<>!\"\n& )
|