review 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/.rubocop.yml +293 -6
- data/.rubocop_todo.yml +3 -608
- data/.travis.yml +6 -13
- data/README.md +5 -3
- data/Rakefile +6 -6
- data/bin/review-catalog-converter +2 -2
- data/bin/review-check +1 -1
- data/bin/review-compile +1 -2
- data/bin/review-init +6 -3
- data/bin/review-validate +3 -3
- data/bin/review-vol +2 -1
- data/doc/NEWS.ja.md +138 -25
- data/doc/NEWS.md +137 -25
- data/doc/config.yml.sample +2 -2
- data/doc/config.yml.sample-simple +1 -1
- data/doc/format.ja.md +86 -5
- data/doc/format.md +67 -2
- data/doc/makeindex.ja.md +95 -0
- data/doc/makeindex.md +97 -0
- data/doc/sample.css +214 -0
- data/lib/epubmaker.rb +6 -6
- data/lib/epubmaker/epubcommon.rb +19 -47
- data/lib/epubmaker/epubv2.rb +3 -1
- data/lib/epubmaker/epubv3.rb +4 -26
- data/lib/epubmaker/producer.rb +46 -46
- data/lib/epubmaker/zip_exporter.rb +86 -0
- data/lib/review/book/base.rb +13 -15
- data/lib/review/book/chapter.rb +2 -1
- data/lib/review/book/compilable.rb +9 -9
- data/lib/review/book/image_finder.rb +13 -13
- data/lib/review/book/index.rb +2 -2
- data/lib/review/book/volume.rb +2 -2
- data/lib/review/builder.rb +57 -1
- data/lib/review/catalog.rb +2 -2
- data/lib/review/compiler.rb +15 -7
- data/lib/review/configure.rb +11 -0
- data/lib/review/epubmaker.rb +403 -401
- data/lib/review/ewbbuilder.rb +16 -16
- data/lib/review/htmlbuilder.rb +42 -58
- data/lib/review/htmltoc.rb +1 -1
- data/lib/review/htmlutils.rb +50 -4
- data/lib/review/i18n.rb +2 -2
- data/lib/review/idgxmlbuilder.rb +30 -47
- data/lib/review/latexbuilder.rb +86 -41
- data/lib/review/latexutils.rb +19 -19
- data/lib/review/markdownbuilder.rb +16 -4
- data/lib/review/md2inaobuilder.rb +0 -9
- data/lib/review/pdfmaker.rb +91 -48
- data/lib/review/preprocessor.rb +1 -1
- data/lib/review/rstbuilder.rb +763 -0
- data/lib/review/sec_counter.rb +7 -9
- data/lib/review/tocparser.rb +3 -3
- data/lib/review/tocprinter.rb +5 -5
- data/lib/review/topbuilder.rb +48 -56
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +6 -7
- data/review.gemspec +1 -0
- data/templates/latex/layout.tex.erb +27 -2
- data/test/assets/test_template.tex +10 -1
- data/test/book_test_helper.rb +1 -2
- data/test/run_test.rb +10 -0
- data/test/sample-book/src/style.css +215 -0
- data/test/sample-book/src/vendor/jumoline/lppl.txt +416 -0
- data/test/test_book.rb +0 -1
- data/test/test_catalog.rb +1 -0
- data/test/test_converter.rb +1 -1
- data/test/test_epub3maker.rb +44 -51
- data/test/test_epubmaker.rb +82 -38
- data/test/test_epubmaker_cmd.rb +1 -1
- data/test/test_extentions_hash.rb +8 -1
- data/test/test_htmlbuilder.rb +411 -18
- data/test/test_i18n.rb +17 -0
- data/test/test_idgxmlbuilder.rb +88 -3
- data/test/test_image_finder.rb +18 -0
- data/test/test_index.rb +2 -0
- data/test/test_latexbuilder.rb +96 -8
- data/test/test_makerhelper.rb +2 -2
- data/test/test_markdownbuilder.rb +22 -1
- data/test/test_md2inaobuilder.rb +0 -5
- data/test/test_pdfmaker.rb +54 -36
- data/test/test_pdfmaker_cmd.rb +1 -1
- data/test/test_rstbuilder.rb +356 -0
- data/test/test_textutils.rb +14 -4
- data/test/test_topbuilder.rb +23 -4
- data/test/test_zip_exporter.rb +113 -0
- metadata +28 -2
data/test/test_book.rb
CHANGED
data/test/test_catalog.rb
CHANGED
data/test/test_converter.rb
CHANGED
data/test/test_epub3maker.rb
CHANGED
@@ -10,14 +10,14 @@ class EPUB3MakerTest < Test::Unit::TestCase
|
|
10
10
|
def setup
|
11
11
|
@producer = Producer.new
|
12
12
|
@producer.merge_params({
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
"bookname" => "sample",
|
14
|
+
"title" => "Sample Book",
|
15
|
+
"epubversion" => 3,
|
16
|
+
"urnid" => "http://example.jp/",
|
17
|
+
"date" => "2011-01-01",
|
18
|
+
"language" => "en",
|
19
|
+
"modified" => "2014-12-13T14:15:16Z"
|
20
|
+
})
|
21
21
|
@output = StringIO.new
|
22
22
|
end
|
23
23
|
|
@@ -157,7 +157,7 @@ EOT
|
|
157
157
|
|
158
158
|
def test_stage1_ncx
|
159
159
|
@producer.ncx(@output)
|
160
|
-
|
160
|
+
expect = <<EOT
|
161
161
|
<?xml version="1.0" encoding="UTF-8"?>
|
162
162
|
<!DOCTYPE html>
|
163
163
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
|
@@ -226,7 +226,7 @@ EOT
|
|
226
226
|
def test_stage2_ncx
|
227
227
|
stage2
|
228
228
|
@producer.ncx(@output)
|
229
|
-
|
229
|
+
expect = <<EOT
|
230
230
|
<?xml version="1.0" encoding="UTF-8"?>
|
231
231
|
<!DOCTYPE html>
|
232
232
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
|
@@ -273,26 +273,26 @@ EOT
|
|
273
273
|
def test_stage3_add_various_items
|
274
274
|
stage3
|
275
275
|
expect = [
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
276
|
+
Content.new("ch01.html", "ch01-html", "application/xhtml+xml", "CH01<>&\"", 1),
|
277
|
+
Content.new("ch02.html", "ch02-html", "application/xhtml+xml", "CH02", 1),
|
278
|
+
Content.new("ch02.html#S1", "ch02-html#S1","html#s1","CH02.1", 2),
|
279
|
+
Content.new("ch02.html#S1.1", "ch02-html#S1-1", "1", "CH02.1.1", 3),
|
280
|
+
Content.new("ch02.html#S1.1.1", "ch02-html#S1-1-1","1", "CH02.1.1.1", 4),
|
281
|
+
Content.new("ch02.html#S1.1.1.1", "ch02-html#S1-1-1-1", "1","CH02.1.1.1.1", 5),
|
282
|
+
Content.new("ch02.html#S1.1.2", "ch02-html#S1-1-2", "2", "CH02.1.1.2", 4),
|
283
|
+
Content.new("ch02.html#S2", "ch02-html#S2", "html#s2", "CH02.2", 2),
|
284
|
+
Content.new("ch02.html#S2.1", "ch02-html#S2-1", "1", "CH02.2.1", 3),
|
285
|
+
Content.new("ch03.html", "ch03-html", "application/xhtml+xml", "CH03", 1, nil, ["mathml"]),
|
286
|
+
Content.new("ch03.html#S1", "ch03-html#S1", "html#s1", "CH03.1", 2),
|
287
|
+
Content.new("ch03.html#S1.1", "ch03-html#S1-1", "1", "CH03.1.1", 3),
|
288
|
+
Content.new("ch04.html", "ch04-html", "application/xhtml+xml", "CH04", 1),
|
289
|
+
Content.new("sample.png", "sample-png", "image/png"),
|
290
|
+
Content.new("sample.jpg", "sample-jpg", "image/jpeg"),
|
291
|
+
Content.new("sample.JPEG", "sample-JPEG", "image/jpeg"),
|
292
|
+
Content.new("sample.SvG", "sample-SvG", "image/svg+xml"),
|
293
|
+
Content.new("sample.GIF", "sample-GIF", "image/gif"),
|
294
|
+
Content.new("sample.css", "sample-css", "text/css")
|
295
|
+
]
|
296
296
|
|
297
297
|
assert_equal expect, @producer.contents
|
298
298
|
end
|
@@ -343,7 +343,7 @@ EOT
|
|
343
343
|
def test_stage3_ncx
|
344
344
|
stage3
|
345
345
|
@producer.ncx(@output)
|
346
|
-
|
346
|
+
expect = <<EOT
|
347
347
|
<?xml version="1.0" encoding="UTF-8"?>
|
348
348
|
<!DOCTYPE html>
|
349
349
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
|
@@ -557,9 +557,9 @@ EOT
|
|
557
557
|
@producer.params["pht"] = ["Mrs.Smith"]
|
558
558
|
@producer.merge_params({"language" => "ja",
|
559
559
|
"history" => [[
|
560
|
-
|
561
|
-
|
562
|
-
|
560
|
+
"2011-08-03 v1.0.0版発行",
|
561
|
+
"2012-02-15 v1.1.0版発行",
|
562
|
+
]] })
|
563
563
|
history = @producer.instance_eval{ @epub.colophon_history }
|
564
564
|
expect = <<EOT
|
565
565
|
<div class="pubhistory">
|
@@ -576,9 +576,9 @@ EOT
|
|
576
576
|
@producer.params["pht"] = ["Mrs.Smith"]
|
577
577
|
@producer.merge_params({"language" => "ja",
|
578
578
|
"history" => [[
|
579
|
-
|
580
|
-
|
581
|
-
|
579
|
+
"2011-08-03",
|
580
|
+
"2012-02-15",
|
581
|
+
]] })
|
582
582
|
history = @producer.instance_eval{ @epub.colophon_history }
|
583
583
|
expect = <<EOT
|
584
584
|
<div class="pubhistory">
|
@@ -595,13 +595,13 @@ EOT
|
|
595
595
|
@producer.params["pht"] = ["Mrs.Smith"]
|
596
596
|
@producer.merge_params({"language" => "ja",
|
597
597
|
"history" => [[
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
598
|
+
"2011-08-03",
|
599
|
+
"2012-02-15",
|
600
|
+
],[
|
601
|
+
"2012-10-01",
|
602
|
+
],[
|
603
|
+
"2013-03-01",
|
604
|
+
]] })
|
605
605
|
history = @producer.instance_eval{ @epub.colophon_history }
|
606
606
|
expect = <<EOT
|
607
607
|
<div class="pubhistory">
|
@@ -615,13 +615,6 @@ EOT
|
|
615
615
|
end
|
616
616
|
|
617
617
|
|
618
|
-
# def test_duplicate_id
|
619
|
-
# stage3
|
620
|
-
# assert_raise(Error) do
|
621
|
-
# @producer.contents << Content.new({"file" => "ch02.html#S1", "title" => "CH02.1", "level" => 2})
|
622
|
-
# end
|
623
|
-
# end
|
624
|
-
|
625
618
|
def test_detect_mathml
|
626
619
|
Dir.mktmpdir do |dir|
|
627
620
|
epubmaker = ReVIEW::EPUBMaker.new
|
data/test/test_epubmaker.rb
CHANGED
@@ -9,13 +9,13 @@ class EPUBMakerTest < Test::Unit::TestCase
|
|
9
9
|
def setup
|
10
10
|
@producer = Producer.new
|
11
11
|
@producer.merge_params({
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
"bookname" => "sample",
|
13
|
+
"title" => "Sample Book",
|
14
|
+
"epubversion" => 2,
|
15
|
+
"urnid" => "http://example.jp/",
|
16
|
+
"date" => "2011-01-01",
|
17
|
+
"language" => "en",
|
18
|
+
})
|
19
19
|
@output = StringIO.new
|
20
20
|
end
|
21
21
|
|
@@ -106,7 +106,7 @@ EOT
|
|
106
106
|
|
107
107
|
def test_stage1_ncx
|
108
108
|
@producer.ncx(@output)
|
109
|
-
|
109
|
+
expect = <<EOT
|
110
110
|
<?xml version="1.0" encoding="UTF-8"?>
|
111
111
|
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
|
112
112
|
<head>
|
@@ -137,7 +137,7 @@ EOT
|
|
137
137
|
def test_stage1_ncx_escape
|
138
138
|
@producer.params["title"] = "Sample<>Book"
|
139
139
|
@producer.ncx(@output)
|
140
|
-
|
140
|
+
expect = <<EOT
|
141
141
|
<?xml version="1.0" encoding="UTF-8"?>
|
142
142
|
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
|
143
143
|
<head>
|
@@ -212,7 +212,7 @@ EOT
|
|
212
212
|
def test_stage2_ncx
|
213
213
|
stage2
|
214
214
|
@producer.ncx(@output)
|
215
|
-
|
215
|
+
expect = <<EOT
|
216
216
|
<?xml version="1.0" encoding="UTF-8"?>
|
217
217
|
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
|
218
218
|
<head>
|
@@ -272,26 +272,26 @@ EOT
|
|
272
272
|
def test_stage3_add_various_items
|
273
273
|
stage3
|
274
274
|
expect = [
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
275
|
+
Content.new("ch01.html", "ch01-html", "application/xhtml+xml", "CH01<>&\"", 1),
|
276
|
+
Content.new("ch02.html", "ch02-html", "application/xhtml+xml", "CH02", 1),
|
277
|
+
Content.new("ch02.html#S1", "ch02-html#S1","html#s1","CH02.1", 2),
|
278
|
+
Content.new("ch02.html#S1.1", "ch02-html#S1-1", "1", "CH02.1.1", 3),
|
279
|
+
Content.new("ch02.html#S1.1.1", "ch02-html#S1-1-1","1", "CH02.1.1.1", 4),
|
280
|
+
Content.new("ch02.html#S1.1.1.1", "ch02-html#S1-1-1-1", "1","CH02.1.1.1.1", 5),
|
281
|
+
Content.new("ch02.html#S1.1.2", "ch02-html#S1-1-2", "2", "CH02.1.1.2", 4),
|
282
|
+
Content.new("ch02.html#S2", "ch02-html#S2", "html#s2", "CH02.2", 2),
|
283
|
+
Content.new("ch02.html#S2.1", "ch02-html#S2-1", "1", "CH02.2.1", 3),
|
284
|
+
Content.new("ch03.html", "ch03-html", "application/xhtml+xml", "CH03", 1),
|
285
|
+
Content.new("ch03.html#S1", "ch03-html#S1", "html#s1", "CH03.1", 2),
|
286
|
+
Content.new("ch03.html#S1.1", "ch03-html#S1-1", "1", "CH03.1.1", 3),
|
287
|
+
Content.new("ch04.html", "ch04-html", "application/xhtml+xml", "CH04", 1),
|
288
|
+
Content.new("sample.png", "sample-png", "image/png"),
|
289
|
+
Content.new("sample.jpg", "sample-jpg", "image/jpeg"),
|
290
|
+
Content.new("sample.JPEG", "sample-JPEG", "image/jpeg"),
|
291
|
+
Content.new("sample.SvG", "sample-SvG", "image/svg+xml"),
|
292
|
+
Content.new("sample.GIF", "sample-GIF", "image/gif"),
|
293
|
+
Content.new("sample.css", "sample-css", "text/css")
|
294
|
+
]
|
295
295
|
|
296
296
|
assert_equal expect, @producer.contents
|
297
297
|
end
|
@@ -340,7 +340,7 @@ EOT
|
|
340
340
|
def test_stage3_ncx
|
341
341
|
stage3
|
342
342
|
@producer.ncx(@output)
|
343
|
-
|
343
|
+
expect = <<EOT
|
344
344
|
<?xml version="1.0" encoding="UTF-8"?>
|
345
345
|
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
|
346
346
|
<head>
|
@@ -662,6 +662,57 @@ EOT
|
|
662
662
|
assert_equal expect, @output.string
|
663
663
|
end
|
664
664
|
|
665
|
+
def test_colophon_history
|
666
|
+
@producer.params["aut"] = ["Mr.Smith"]
|
667
|
+
@producer.params["pbl"] = ["BLUEPRINT"]
|
668
|
+
@producer.params["pht"] = ["Mrs.Smith"]
|
669
|
+
@producer.merge_params({"language" => "ja"})
|
670
|
+
@producer.params["history"] = [[
|
671
|
+
"2011-08-03",
|
672
|
+
"2012-02-15",
|
673
|
+
],[
|
674
|
+
"2012-10-01",
|
675
|
+
],[
|
676
|
+
"2013-03-01",
|
677
|
+
]]
|
678
|
+
epub = @producer.instance_eval{@epub}
|
679
|
+
result = epub.colophon_history
|
680
|
+
expect = <<-EOT
|
681
|
+
<div class=\"pubhistory\">
|
682
|
+
<p>2011年8月3日 初版第1刷 発行</p>
|
683
|
+
<p>2012年2月15日 初版第2刷 発行</p>
|
684
|
+
<p>2012年10月1日 第2版第1刷 発行</p>
|
685
|
+
<p>2013年3月1日 第3版第1刷 発行</p>
|
686
|
+
</div>
|
687
|
+
EOT
|
688
|
+
assert_equal expect, result
|
689
|
+
end
|
690
|
+
|
691
|
+
def test_colophon_history_freeformat
|
692
|
+
@producer.params["aut"] = ["Mr.Smith"]
|
693
|
+
@producer.params["pbl"] = ["BLUEPRINT"]
|
694
|
+
@producer.params["pht"] = ["Mrs.Smith"]
|
695
|
+
@producer.merge_params({"language" => "ja"})
|
696
|
+
@producer.params["history"] = [[
|
697
|
+
"2011年8月3日 ver 1.1.0発行",
|
698
|
+
],[
|
699
|
+
"2011年10月12日 ver 1.2.0発行",
|
700
|
+
],[
|
701
|
+
"2012年1月31日 ver 1.2.1発行",
|
702
|
+
]]
|
703
|
+
|
704
|
+
epub = @producer.instance_eval{@epub}
|
705
|
+
result = epub.colophon_history
|
706
|
+
expect = <<-EOT
|
707
|
+
<div class=\"pubhistory\">
|
708
|
+
<p>2011年8月3日 ver 1.1.0発行</p>
|
709
|
+
<p>2011年10月12日 ver 1.2.0発行</p>
|
710
|
+
<p>2012年1月31日 ver 1.2.1発行</p>
|
711
|
+
</div>
|
712
|
+
EOT
|
713
|
+
assert_equal expect, result
|
714
|
+
end
|
715
|
+
|
665
716
|
def test_colophon_pht
|
666
717
|
@producer.params["aut"] = ["Mr.Smith"]
|
667
718
|
@producer.params["pbl"] = ["BLUEPRINT"]
|
@@ -709,13 +760,6 @@ EOT
|
|
709
760
|
assert_equal nil, @producer.isbn_hyphen
|
710
761
|
end
|
711
762
|
|
712
|
-
# def test_duplicate_id
|
713
|
-
# stage3
|
714
|
-
# assert_raise(Error) do
|
715
|
-
# @producer.contents << Content.new({"file" => "ch02.html#S1", "title" => "CH02.1", "level" => 2})
|
716
|
-
# end
|
717
|
-
# end
|
718
|
-
|
719
763
|
def test_title
|
720
764
|
@producer.params["aut"] = ["Mr.Smith"]
|
721
765
|
@producer.params["pbl"] = ["BLUEPRINT"]
|
data/test/test_epubmaker_cmd.rb
CHANGED
@@ -27,7 +27,7 @@ class EPUBMakerCmdTest < Test::Unit::TestCase
|
|
27
27
|
if /mswin|mingw|cygwin/ !~ RUBY_PLATFORM
|
28
28
|
config = prepare_samplebook(@tmpdir1)
|
29
29
|
builddir = @tmpdir1 + "/" + config['bookname'] + '-epub'
|
30
|
-
assert !
|
30
|
+
assert !File.exist?(builddir)
|
31
31
|
|
32
32
|
ruby_cmd = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) + RbConfig::CONFIG["EXEEXT"]
|
33
33
|
Dir.chdir(@tmpdir1) do
|
@@ -6,22 +6,26 @@ class TestExtentionsHash < Test::Unit::TestCase
|
|
6
6
|
assert_equal({:a => 1, :b => 3, :c => 4},
|
7
7
|
{:a => 1, :b => 2}.deep_merge({:b => 3, :c => 4}))
|
8
8
|
end
|
9
|
+
|
9
10
|
def test_deep_empty_r
|
10
11
|
assert_equal({:b => 3, :c => 4},
|
11
12
|
{}.deep_merge({:b => 3, :c => 4}))
|
12
13
|
end
|
14
|
+
|
13
15
|
def test_deep_empty_l
|
14
16
|
assert_equal({:a => 1, :b => 2},
|
15
17
|
{:a => 1, :b => 2}.deep_merge({}))
|
16
18
|
end
|
19
|
+
|
17
20
|
def test_deep_merge_nested
|
18
21
|
assert_equal({:a => {:aa => 1, :ab => 2},
|
19
22
|
:b => {:ba => 5, :bb => 4, :bc => 6},
|
20
23
|
:c => {:ca => 1}},
|
21
24
|
{:a => {:aa => 1, :ab => 2},
|
22
25
|
:b => {:ba => 3, :bb => 4}}.deep_merge({:b => {:ba => 5, :bc => 6},
|
23
|
-
|
26
|
+
:c => {:ca => 1}}))
|
24
27
|
end
|
28
|
+
|
25
29
|
def test_deep_merge_with_array
|
26
30
|
assert_equal({:a => "string", :b => ["BA"],
|
27
31
|
:c => {:ca => [:cab => "CAB"], :cb => 3}},
|
@@ -37,16 +41,19 @@ class TestExtentionsHash < Test::Unit::TestCase
|
|
37
41
|
a.deep_merge!({:b => 3, :c => 4})
|
38
42
|
assert_equal({:a => 1, :b => 3, :c => 4}, a)
|
39
43
|
end
|
44
|
+
|
40
45
|
def test_deep_b_empty_r
|
41
46
|
a = {}
|
42
47
|
a.deep_merge!({:b => 3, :c => 4})
|
43
48
|
assert_equal({:b => 3, :c => 4}, a)
|
44
49
|
end
|
50
|
+
|
45
51
|
def test_deep_b_empty_l
|
46
52
|
a = {:a => 1, :b => 2}
|
47
53
|
a.deep_merge!({})
|
48
54
|
assert_equal({:a => 1, :b => 2}, a)
|
49
55
|
end
|
56
|
+
|
50
57
|
def test_deep_merge_b_nested
|
51
58
|
a = {:a => {:aa => 1, :ab => 2},
|
52
59
|
:b => {:ba => 3, :bb => 4}}
|
data/test/test_htmlbuilder.rb
CHANGED
@@ -11,10 +11,10 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
11
11
|
@builder = HTMLBuilder.new()
|
12
12
|
@config = ReVIEW::Configure.values
|
13
13
|
@config.merge!({
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
"secnolevel" => 2, # for IDGXMLBuilder, HTMLBuilder
|
15
|
+
"stylesheet" => nil, # for HTMLBuilder
|
16
|
+
"htmlext" => "html",
|
17
|
+
})
|
18
18
|
@book = Book::Base.new(".")
|
19
19
|
@book.config = @config
|
20
20
|
@compiler = ReVIEW::Compiler.new(@builder)
|
@@ -75,7 +75,6 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
75
75
|
|
76
76
|
actual = compile_block("=={test} this is test.\n")
|
77
77
|
assert_equal %Q|\n<h2 id="test"><a id="hI-1"></a><span class="secno">I.1 </span>this is test.</h2>\n|, actual
|
78
|
-
|
79
78
|
end
|
80
79
|
end
|
81
80
|
end
|
@@ -330,6 +329,18 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
330
329
|
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
|
331
330
|
end
|
332
331
|
|
332
|
+
def test_inline_img
|
333
|
+
def @chapter.image(id)
|
334
|
+
item = Book::ImageIndex::Item.new("sampleimg", 1, 'sample photo')
|
335
|
+
item.instance_eval{@path="./images/chap1-sampleimg.png"}
|
336
|
+
item
|
337
|
+
end
|
338
|
+
|
339
|
+
actual = compile_block "@<img>{sampleimg}\n"
|
340
|
+
expected = %Q|<p><span class="imgref">図1.1</span></p>\n|
|
341
|
+
assert_equal expected, actual
|
342
|
+
end
|
343
|
+
|
333
344
|
def test_inline_imgref
|
334
345
|
def @chapter.image(id)
|
335
346
|
item = Book::ImageIndex::Item.new("sampleimg", 1, 'sample photo')
|
@@ -338,7 +349,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
338
349
|
end
|
339
350
|
|
340
351
|
actual = compile_block "@<imgref>{sampleimg}\n"
|
341
|
-
expected = "
|
352
|
+
expected = %Q|<p><span class="imgref">図1.1</span>「sample photo」</p>\n|
|
342
353
|
assert_equal expected, actual
|
343
354
|
end
|
344
355
|
|
@@ -350,7 +361,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
350
361
|
end
|
351
362
|
|
352
363
|
actual = compile_block "@<imgref>{sampleimg}\n"
|
353
|
-
expected = "
|
364
|
+
expected = %Q|<p><span class="imgref">図1.1</span></p>\n|
|
354
365
|
assert_equal expected, actual
|
355
366
|
end
|
356
367
|
|
@@ -501,7 +512,31 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
501
512
|
Book::ListIndex::Item.new("samplelist",1)
|
502
513
|
end
|
503
514
|
actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
|
504
|
-
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
|
515
|
+
assert_equal %Q|<div id="samplelist" 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
|
516
|
+
end
|
517
|
+
|
518
|
+
def test_inline_list
|
519
|
+
def @chapter.list(id)
|
520
|
+
Book::ListIndex::Item.new("samplelist",1)
|
521
|
+
end
|
522
|
+
actual = compile_block("@<list>{sampletest}\n")
|
523
|
+
assert_equal %Q|<p><span class="listref">リスト1.1</span></p>\n|, actual
|
524
|
+
end
|
525
|
+
|
526
|
+
def test_inline_list_href
|
527
|
+
book = ReVIEW::Book::Base.load
|
528
|
+
book.config["chapterlink"] = true
|
529
|
+
book.catalog = ReVIEW::Catalog.new({"CHAPS"=>%w(ch1.re ch2.re)})
|
530
|
+
io1 = StringIO.new("//list[sampletest]{\nfoo\n//}\n")
|
531
|
+
io2 = StringIO.new("= BAR\n")
|
532
|
+
chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
|
533
|
+
chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2)
|
534
|
+
book.parts = [ReVIEW::Book::Part.new(self, nil, [chap1, chap2])]
|
535
|
+
builder = ReVIEW::HTMLBuilder.new
|
536
|
+
comp = ReVIEW::Compiler.new(builder)
|
537
|
+
builder.bind(comp, chap2, nil)
|
538
|
+
actual = builder.inline_list("ch1|sampletest")
|
539
|
+
assert_equal %Q|<span class="listref"><a href="./ch1.html#sampletest">リスト1.1</a></span>|, actual
|
505
540
|
end
|
506
541
|
|
507
542
|
def test_list_pygments
|
@@ -518,7 +553,17 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
518
553
|
@book.config["highlight"]["html"] = "pygments"
|
519
554
|
actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
|
520
555
|
|
521
|
-
|
556
|
+
expected = <<-EOS
|
557
|
+
<div id="samplelist" class="caption-code">
|
558
|
+
<p class="caption">リスト1.1: this is <b>test</b><&>_</p>
|
559
|
+
<pre class="list highlight">test1
|
560
|
+
test1.5
|
561
|
+
|
562
|
+
test<i>2</i>
|
563
|
+
</pre>
|
564
|
+
</div>
|
565
|
+
EOS
|
566
|
+
assert_equal expected, actual
|
522
567
|
end
|
523
568
|
|
524
569
|
def test_list_pygments_lang
|
@@ -535,9 +580,10 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
535
580
|
@book.config["highlight"]["html"] = "pygments"
|
536
581
|
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")
|
537
582
|
|
538
|
-
assert_equal %Q|<div
|
539
|
-
%Q|<
|
540
|
-
%Q
|
583
|
+
assert_equal %Q|<div id="samplelist" class=\"caption-code\">\n| +
|
584
|
+
%Q|<p class=\"caption\">リスト1.1: this is <b>test</b><&>_</p>\n| +
|
585
|
+
%Q|<pre class=\"list language-ruby highlight\"><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| +
|
586
|
+
%Q| (<span style=\"color: #666666\">1..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| +
|
541
587
|
%Q| <span style=\"color: #008000; font-weight: bold\">return</span> <span style=\"color: #008000\">true</span>\n| +
|
542
588
|
%Q|<span style=\"color: #008000; font-weight: bold\">end</span>\n| +
|
543
589
|
%Q|</pre>\n| +
|
@@ -558,7 +604,78 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
558
604
|
@book.config["highlight"]["html"] = "pygments"
|
559
605
|
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")
|
560
606
|
|
561
|
-
|
607
|
+
expected = <<-EOS
|
608
|
+
<div id="samplelist" class=\"caption-code\">
|
609
|
+
<p class=\"caption\">リスト1.1: this is <b>test</b><&>_</p>
|
610
|
+
<pre class=\"list highlight\">def foo(a1, a2=:test)
|
611
|
+
(1..3).times{|i| a.include?(:foo)}
|
612
|
+
return true
|
613
|
+
end
|
614
|
+
</pre>
|
615
|
+
</div>
|
616
|
+
EOS
|
617
|
+
assert_equal expected, actual
|
618
|
+
end
|
619
|
+
|
620
|
+
def test_list_rouge
|
621
|
+
begin
|
622
|
+
require 'rouge'
|
623
|
+
rescue LoadError
|
624
|
+
$stderr.puts "skip test_list_rouge (cannot find Rouge)"
|
625
|
+
return true
|
626
|
+
end
|
627
|
+
def @chapter.list(id)
|
628
|
+
Book::ListIndex::Item.new("samplelist",1)
|
629
|
+
end
|
630
|
+
@book.config["highlight"] = {}
|
631
|
+
@book.config["highlight"]["html"] = "rouge"
|
632
|
+
actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
|
633
|
+
|
634
|
+
assert_equal %Q|<div id="samplelist" class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b><&>_</p>\n<pre class="list highlight">test1\ntest1.5\n\ntest<i>2</i>\n</pre>\n</div>\n|, actual
|
635
|
+
end
|
636
|
+
|
637
|
+
def test_list_rouge_lang
|
638
|
+
begin
|
639
|
+
require 'rouge'
|
640
|
+
rescue LoadError
|
641
|
+
$stderr.puts "skip test_list_rouge_lang (cannot find Rouge)"
|
642
|
+
return true
|
643
|
+
end
|
644
|
+
def @chapter.list(id)
|
645
|
+
Book::ListIndex::Item.new("samplelist",1)
|
646
|
+
end
|
647
|
+
@book.config["highlight"] = {}
|
648
|
+
@book.config["highlight"]["html"] = "rouge"
|
649
|
+
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")
|
650
|
+
|
651
|
+
expected = "<div id=\"samplelist\" class=\"caption-code\">\n" +
|
652
|
+
"<p class=\"caption\">リスト1.1: this is <b>test</b><&>_</p>\n" +
|
653
|
+
"<pre class=\"list language-ruby highlight\"><span class=\"k\">def</span> <span class=\"nf\">foo</span><span class=\"p\">(</span><span class=\"n\">a1</span><span class=\"p\">,</span> <span class=\"n\">a2</span><span class=\"o\">=</span><span class=\"ss\">:test</span><span class=\"p\">)</span>\n" +
|
654
|
+
" <span class=\"p\">(</span><span class=\"mi\">1</span><span class=\"p\">.</span><span class=\"nf\">.</span><span class=\"mi\">3</span><span class=\"p\">).</span><span class=\"nf\">times</span><span class=\"p\">{</span><span class=\"o\">|</span><span class=\"n\">i</span><span class=\"o\">|</span> <span class=\"n\">a</span><span class=\"p\">.</span><span class=\"nf\">include?</span><span class=\"p\">(</span><span class=\"ss\">:foo</span><span class=\"p\">)}</span>\n" +
|
655
|
+
" <span class=\"k\">return</span> <span class=\"kp\">true</span>\n" +
|
656
|
+
"<span class=\"k\">end</span>\n" +
|
657
|
+
"\n" +
|
658
|
+
"</pre>\n" +
|
659
|
+
"</div>\n"
|
660
|
+
|
661
|
+
assert_equal expected, actual
|
662
|
+
end
|
663
|
+
|
664
|
+
def test_list_rouge_nulllang
|
665
|
+
begin
|
666
|
+
require 'rouge'
|
667
|
+
rescue LoadError
|
668
|
+
$stderr.puts "skip test_list_rouge_nulllang (cannot find Rouge)"
|
669
|
+
return true
|
670
|
+
end
|
671
|
+
def @chapter.list(id)
|
672
|
+
Book::ListIndex::Item.new("samplelist",1)
|
673
|
+
end
|
674
|
+
@book.config["highlight"] = {}
|
675
|
+
@book.config["highlight"]["html"] = "rouge"
|
676
|
+
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")
|
677
|
+
|
678
|
+
assert_equal "<div id=\"samplelist\" class=\"caption-code\">\n<p class=\"caption\">リスト1.1: this is <b>test</b><&>_</p>\n<pre class=\"list highlight\">def foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n</pre>\n</div>\n", actual
|
562
679
|
end
|
563
680
|
|
564
681
|
def test_list_ext
|
@@ -566,7 +683,7 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
566
683
|
Book::ListIndex::Item.new("samplelist.rb",1)
|
567
684
|
end
|
568
685
|
actual = compile_block("//list[samplelist.rb][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
|
569
|
-
assert_equal %Q|<div class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b><&>_</p>\n<pre class="list language-rb">test1\ntest1.5\n\ntest<i>2</i>\n</pre>\n</div>\n|, actual
|
686
|
+
assert_equal %Q|<div id="samplelist.rb" class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b><&>_</p>\n<pre class="list language-rb">test1\ntest1.5\n\ntest<i>2</i>\n</pre>\n</div>\n|, actual
|
570
687
|
end
|
571
688
|
|
572
689
|
def test_listnum
|
@@ -585,7 +702,7 @@ end
|
|
585
702
|
EOS
|
586
703
|
|
587
704
|
expected =<<-EOS
|
588
|
-
<div class="code">
|
705
|
+
<div id="samplelist" class="code">
|
589
706
|
<p class="caption">リスト1.1: this is <b>test</b><&>_</p>
|
590
707
|
<pre class="list language-ruby"> 1: def foo(a1, a2=:test)
|
591
708
|
2: (1..3).times{|i| a.include?(:foo)}
|
@@ -598,6 +715,36 @@ EOS
|
|
598
715
|
assert_equal expected, actual
|
599
716
|
end
|
600
717
|
|
718
|
+
def test_listnum_linenum
|
719
|
+
def @chapter.list(id)
|
720
|
+
Book::ListIndex::Item.new("samplelist",1)
|
721
|
+
end
|
722
|
+
|
723
|
+
@book.config["highlight"] = false
|
724
|
+
actual = compile_block(<<-EOS)
|
725
|
+
//firstlinenum[100]
|
726
|
+
//listnum[samplelist][this is @<b>{test}<&>_][ruby]{
|
727
|
+
def foo(a1, a2=:test)
|
728
|
+
(1..3).times{|i| a.include?(:foo)}
|
729
|
+
return true
|
730
|
+
end
|
731
|
+
//}
|
732
|
+
EOS
|
733
|
+
|
734
|
+
expected =<<-EOS
|
735
|
+
<div id="samplelist" class="code">
|
736
|
+
<p class="caption">リスト1.1: this is <b>test</b><&>_</p>
|
737
|
+
<pre class="list language-ruby">100: def foo(a1, a2=:test)
|
738
|
+
101: (1..3).times{|i| a.include?(:foo)}
|
739
|
+
102: return true
|
740
|
+
103: end
|
741
|
+
</pre>
|
742
|
+
</div>
|
743
|
+
EOS
|
744
|
+
|
745
|
+
assert_equal expected, actual
|
746
|
+
end
|
747
|
+
|
601
748
|
def test_listnum_pygments_lang
|
602
749
|
def @chapter.list(id)
|
603
750
|
Book::ListIndex::Item.new("samplelist",1)
|
@@ -612,7 +759,45 @@ EOS
|
|
612
759
|
@book.config["highlight"]["html"] = "pygments"
|
613
760
|
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")
|
614
761
|
|
615
|
-
|
762
|
+
expected = <<-EOS
|
763
|
+
<div id="samplelist" class="code">
|
764
|
+
<p class="caption">リスト1.1: this is <b>test</b><&>_</p>
|
765
|
+
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><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>)
|
766
|
+
<span style="background-color: #f0f0f0; padding: 0 5px 0 5px">2 </span> (<span style="color: #666666">1..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>)}
|
767
|
+
<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>
|
768
|
+
<span style="background-color: #f0f0f0; padding: 0 5px 0 5px">4 </span><span style="color: #008000; font-weight: bold">end</span>
|
769
|
+
</pre></div>
|
770
|
+
</div>
|
771
|
+
EOS
|
772
|
+
assert_equal expected, actual
|
773
|
+
end
|
774
|
+
|
775
|
+
def test_listnum_pygments_lang_linenum
|
776
|
+
def @chapter.list(id)
|
777
|
+
Book::ListIndex::Item.new("samplelist",1)
|
778
|
+
end
|
779
|
+
begin
|
780
|
+
require 'pygments'
|
781
|
+
rescue LoadError
|
782
|
+
$stderr.puts "skip test_listnum_pygments_lang (cannot find pygments.rb)"
|
783
|
+
return true
|
784
|
+
end
|
785
|
+
@book.config["highlight"] = {}
|
786
|
+
@book.config["highlight"]["html"] = "pygments"
|
787
|
+
actual = compile_block("//firstlinenum[100]\n//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")
|
788
|
+
|
789
|
+
expected = <<-EOB
|
790
|
+
<div id=\"samplelist\" class=\"code\">
|
791
|
+
<p class=\"caption\">リスト1.1: this is <b>test</b><&>_</p>
|
792
|
+
<div class=\"highlight\" style=\"background: #f8f8f8\"><pre style=\"line-height: 125%\"><span></span><span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">100 </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>)
|
793
|
+
<span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">101 </span> (<span style=\"color: #666666\">1..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>)}
|
794
|
+
<span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">102 </span> <span style=\"color: #008000; font-weight: bold\">return</span> <span style=\"color: #008000\">true</span>
|
795
|
+
<span style=\"background-color: #f0f0f0; padding: 0 5px 0 5px\">103 </span><span style=\"color: #008000; font-weight: bold\">end</span>
|
796
|
+
</pre></div>
|
797
|
+
</div>
|
798
|
+
EOB
|
799
|
+
|
800
|
+
assert_equal expected, actual
|
616
801
|
end
|
617
802
|
|
618
803
|
def test_listnum_pygments_lang_without_lang
|
@@ -630,9 +815,69 @@ EOS
|
|
630
815
|
@book.config["highlight"]["lang"] = "ruby"
|
631
816
|
actual = compile_block("//listnum[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")
|
632
817
|
|
633
|
-
|
818
|
+
expected = <<-EOS
|
819
|
+
<div id="samplelist" class="code">
|
820
|
+
<p class="caption">リスト1.1: this is <b>test</b><&>_</p>
|
821
|
+
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><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>)
|
822
|
+
<span style="background-color: #f0f0f0; padding: 0 5px 0 5px">2 </span> (<span style="color: #666666">1..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>)}
|
823
|
+
<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>
|
824
|
+
<span style="background-color: #f0f0f0; padding: 0 5px 0 5px">4 </span><span style="color: #008000; font-weight: bold">end</span>
|
825
|
+
</pre></div>
|
826
|
+
</div>
|
827
|
+
EOS
|
828
|
+
assert_equal expected, actual
|
634
829
|
end
|
635
830
|
|
831
|
+
def test_listnum_rouge_lang
|
832
|
+
begin
|
833
|
+
require 'rouge'
|
834
|
+
rescue LoadError
|
835
|
+
$stderr.puts "skip test_listnum_rouge_lang (cannot find Rouge)"
|
836
|
+
return true
|
837
|
+
end
|
838
|
+
def @chapter.list(id)
|
839
|
+
Book::ListIndex::Item.new("samplelist",1)
|
840
|
+
end
|
841
|
+
@book.config["highlight"] = {}
|
842
|
+
@book.config["highlight"]["html"] = "rouge"
|
843
|
+
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")
|
844
|
+
|
845
|
+
assert_equal "<div id=\"samplelist\" class=\"code\">\n<p class=\"caption\">リスト1.1: this is <b>test</b><&>_</p>\n<table class=\"highlight rouge-table\"><tbody><tr><td class=\"rouge-gutter gl\"><pre class=\"lineno\">1\n2\n3\n4\n5\n</pre></td><td class=\"rouge-code\"><pre><span class=\"k\">def</span> <span class=\"nf\">foo</span><span class=\"p\">(</span><span class=\"n\">a1</span><span class=\"p\">,</span> <span class=\"n\">a2</span><span class=\"o\">=</span><span class=\"ss\">:test</span><span class=\"p\">)</span>\n <span class=\"p\">(</span><span class=\"mi\">1</span><span class=\"p\">.</span><span class=\"nf\">.</span><span class=\"mi\">3</span><span class=\"p\">).</span><span class=\"nf\">times</span><span class=\"p\">{</span><span class=\"o\">|</span><span class=\"n\">i</span><span class=\"o\">|</span> <span class=\"n\">a</span><span class=\"p\">.</span><span class=\"nf\">include?</span><span class=\"p\">(</span><span class=\"ss\">:foo</span><span class=\"p\">)}</span>\n <span class=\"k\">return</span> <span class=\"kp\">true</span>\n<span class=\"k\">end</span>\n\n</pre></td></tr></tbody></table>\n</div>\n", actual
|
846
|
+
end
|
847
|
+
|
848
|
+
def test_listnum_rouge_lang_linenum
|
849
|
+
begin
|
850
|
+
require 'rouge'
|
851
|
+
rescue LoadError
|
852
|
+
$stderr.puts "skip test_listnum_rouge_lang_linenum (cannot find Rouge)"
|
853
|
+
return true
|
854
|
+
end
|
855
|
+
def @chapter.list(id)
|
856
|
+
Book::ListIndex::Item.new("samplelist",1)
|
857
|
+
end
|
858
|
+
@book.config["highlight"] = {}
|
859
|
+
@book.config["highlight"]["html"] = "rouge"
|
860
|
+
actual = compile_block("//firstlinenum[100]\n//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")
|
861
|
+
|
862
|
+
expected = <<-EOB
|
863
|
+
<div id="samplelist" class="code">
|
864
|
+
<p class="caption">リスト1.1: this is <b>test</b><&>_</p>
|
865
|
+
<table class="highlight rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">100
|
866
|
+
101
|
867
|
+
102
|
868
|
+
103
|
869
|
+
104
|
870
|
+
</pre></td><td class="rouge-code"><pre><span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="o">=</span><span class="ss">:test</span><span class="p">)</span>
|
871
|
+
<span class="p">(</span><span class="mi">1</span><span class="p">.</span><span class="nf">.</span><span class="mi">3</span><span class="p">).</span><span class="nf">times</span><span class="p">{</span><span class="o">|</span><span class="n">i</span><span class="o">|</span> <span class="n">a</span><span class="p">.</span><span class="nf">include?</span><span class="p">(</span><span class="ss">:foo</span><span class="p">)}</span>
|
872
|
+
<span class="k">return</span> <span class="kp">true</span>
|
873
|
+
<span class="k">end</span>
|
874
|
+
|
875
|
+
</pre></td></tr></tbody></table>
|
876
|
+
</div>
|
877
|
+
EOB
|
878
|
+
|
879
|
+
assert_equal expected, actual
|
880
|
+
end
|
636
881
|
|
637
882
|
def test_emlist
|
638
883
|
actual = compile_block("//emlist{\nlineA\nlineB\n//}\n")
|
@@ -649,7 +894,13 @@ EOS
|
|
649
894
|
@book.config["highlight"] = {}
|
650
895
|
@book.config["highlight"]["html"] = "pygments"
|
651
896
|
actual = compile_block("//emlist[][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
|
652
|
-
|
897
|
+
expected = <<-EOS
|
898
|
+
<div class="emlist-code">
|
899
|
+
<pre class="emlist language-sql highlight"><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>
|
900
|
+
</pre>
|
901
|
+
</div>
|
902
|
+
EOS
|
903
|
+
assert_equal expected, actual
|
653
904
|
end
|
654
905
|
|
655
906
|
def test_emlist_caption
|
@@ -689,6 +940,20 @@ EOS
|
|
689
940
|
assert_equal expected, actual
|
690
941
|
end
|
691
942
|
|
943
|
+
def test_emlistnum_lang_linenum
|
944
|
+
@book.config["highlight"] = false
|
945
|
+
actual = compile_block("//firstlinenum[1000]\n//emlistnum[cap][text]{\nlineA\nlineB\n//}\n")
|
946
|
+
expected =<<-EOS
|
947
|
+
<div class="emlistnum-code">
|
948
|
+
<p class="caption">cap</p>
|
949
|
+
<pre class="emlist language-text">1000: lineA
|
950
|
+
1001: lineB
|
951
|
+
</pre>
|
952
|
+
</div>
|
953
|
+
EOS
|
954
|
+
assert_equal expected, actual
|
955
|
+
end
|
956
|
+
|
692
957
|
def test_emlist_with_4tab
|
693
958
|
@config["tabwidth"] = 4
|
694
959
|
actual = compile_block("//emlist{\n\tlineA\n\t\tlineB\n\tlineC\n//}\n")
|
@@ -1057,6 +1322,63 @@ EOS
|
|
1057
1322
|
assert_equal "nor\nmal", compile_inline("@<raw>{|html|nor\\nmal}")
|
1058
1323
|
end
|
1059
1324
|
|
1325
|
+
def test_inline_embed0
|
1326
|
+
assert_equal "normal", compile_inline("@<embed>{normal}")
|
1327
|
+
end
|
1328
|
+
|
1329
|
+
def test_inline_embed1
|
1330
|
+
assert_equal "body", compile_inline("@<embed>{|html|body}")
|
1331
|
+
end
|
1332
|
+
|
1333
|
+
def test_inline_embed3
|
1334
|
+
assert_equal "", compile_inline("@<embed>{|idgxml, latex|body}")
|
1335
|
+
end
|
1336
|
+
|
1337
|
+
def test_inline_embed5
|
1338
|
+
assert_equal 'nor\\nmal', compile_inline("@<embed>{|html|nor\\nmal}")
|
1339
|
+
end
|
1340
|
+
|
1341
|
+
def test_inline_embed_math1
|
1342
|
+
assert_equal '\[ \frac{\partial f}{\partial x} =x^2+xy \]', compile_inline('@<embed>{\[ \frac{\partial f\}{\partial x\} =x^2+xy \]}')
|
1343
|
+
end
|
1344
|
+
|
1345
|
+
def test_inline_embed_math1a
|
1346
|
+
assert_equal '\[ \frac{\partial f}{\partial x} =x^2+xy \]', compile_inline('@<embed>{\\[ \\frac{\\partial f\}{\\partial x\} =x^2+xy \\]}')
|
1347
|
+
end
|
1348
|
+
|
1349
|
+
def test_inline_embed_math1b
|
1350
|
+
assert_equal '\[ \frac{\partial f}{\partial x} =x^2+xy \]', compile_inline('@<embed>{\\\\[ \\\\frac{\\\\partial f\}{\\\\partial x\} =x^2+xy \\\\]}')
|
1351
|
+
end
|
1352
|
+
|
1353
|
+
def test_inline_embed_math1c
|
1354
|
+
assert_equal '\\[ \\frac{}{} \\]',
|
1355
|
+
compile_inline('@<embed>{\[ \\frac{\}{\} \\]}')
|
1356
|
+
end
|
1357
|
+
|
1358
|
+
def test_inline_embed_n1
|
1359
|
+
assert_equal '\\n', compile_inline('@<embed>{\\n}')
|
1360
|
+
end
|
1361
|
+
|
1362
|
+
def test_inline_embed_n2
|
1363
|
+
assert_equal '\\n', compile_inline('@<embed>{\\\\n}')
|
1364
|
+
end
|
1365
|
+
|
1366
|
+
def test_inline_embed_brace_right0
|
1367
|
+
assert_equal '}', compile_inline('@<embed>{\\}}')
|
1368
|
+
end
|
1369
|
+
|
1370
|
+
def test_inline_embed_brace_right1
|
1371
|
+
assert_equal '\\}', compile_inline('@<embed>{\\\\}}')
|
1372
|
+
end
|
1373
|
+
|
1374
|
+
def test_inline_embed_brace_right2
|
1375
|
+
assert_equal '\\}', compile_inline('@<embed>{\\\\\\}}')
|
1376
|
+
end
|
1377
|
+
|
1378
|
+
def test_inline_embed_brace_right3
|
1379
|
+
assert_equal '\\\\}', compile_inline('@<embed>{\\\\\\\\}}')
|
1380
|
+
end
|
1381
|
+
|
1060
1382
|
def test_block_raw0
|
1061
1383
|
actual = compile_block("//raw[<>!\"\\n& ]\n")
|
1062
1384
|
expected = %Q(<>!\"\n& )
|
@@ -1087,6 +1409,48 @@ EOS
|
|
1087
1409
|
assert_equal expected, actual
|
1088
1410
|
end
|
1089
1411
|
|
1412
|
+
def test_embed0
|
1413
|
+
lines = '//embed{' + "\n" +
|
1414
|
+
' <>!\\"\\\\n& ' + "\n" +
|
1415
|
+
'//}' + "\n"
|
1416
|
+
actual = compile_block(lines)
|
1417
|
+
expected = ' <>!\\"\\\\n& ' + "\n"
|
1418
|
+
assert_equal expected, actual
|
1419
|
+
end
|
1420
|
+
|
1421
|
+
def test_embed1
|
1422
|
+
actual = compile_block("//embed[|html|]{\n" +
|
1423
|
+
"<>!\\\"\\\\n& \n" +
|
1424
|
+
"//}\n")
|
1425
|
+
expected = %Q(<>!\\\"\\\\n& \n)
|
1426
|
+
assert_equal expected, actual
|
1427
|
+
end
|
1428
|
+
|
1429
|
+
def test_embed2
|
1430
|
+
actual = compile_block("//embed[html, latex]{\n" +
|
1431
|
+
"<>!\\\"\\\\n& \n" +
|
1432
|
+
"//}\n")
|
1433
|
+
expected = %Q(<>!\\\"\\\\n& \n)
|
1434
|
+
assert_equal expected, actual
|
1435
|
+
end
|
1436
|
+
|
1437
|
+
def test_embed2a
|
1438
|
+
actual = compile_block("//embed[|html, latex|]{\n" +
|
1439
|
+
"<>!\\\"\\\\n& \n" +
|
1440
|
+
"//}\n")
|
1441
|
+
expected = %Q(<>!\\\"\\\\n& \n)
|
1442
|
+
assert_equal expected, actual
|
1443
|
+
end
|
1444
|
+
|
1445
|
+
def test_embed2b
|
1446
|
+
actual = compile_block("//embed[html, latex]{\n" +
|
1447
|
+
'#@# comments are not ignored in //embed block' + "\n" +
|
1448
|
+
"<>!\\\"\\\\n& \n" +
|
1449
|
+
"//}\n")
|
1450
|
+
expected = '#@# comments are not ignored in //embed block' + "\n" + %Q(<>!\\\"\\\\n& \n)
|
1451
|
+
assert_equal expected, actual
|
1452
|
+
end
|
1453
|
+
|
1090
1454
|
def test_inline_fn
|
1091
1455
|
fn = Book::FootnoteIndex.parse(['//footnote[foo][bar\\a\\$buz]'])
|
1092
1456
|
@chapter.instance_eval{@footnote_index=fn}
|
@@ -1144,6 +1508,14 @@ EOS
|
|
1144
1508
|
actual
|
1145
1509
|
end
|
1146
1510
|
|
1511
|
+
def test_inline_table
|
1512
|
+
def @chapter.table(id)
|
1513
|
+
Book::TableIndex::Item.new("sampletable",1)
|
1514
|
+
end
|
1515
|
+
actual = compile_block("@<table>{sampletest}\n")
|
1516
|
+
assert_equal %Q|<p><span class="tableref">表1.1</span></p>\n|, actual
|
1517
|
+
end
|
1518
|
+
|
1147
1519
|
def test_imgtable
|
1148
1520
|
def @chapter.image(id)
|
1149
1521
|
item = Book::ImageIndex::Item.new("sampleimg",1, 'sample img')
|
@@ -1190,4 +1562,25 @@ EOS
|
|
1190
1562
|
assert_equal expected, actual
|
1191
1563
|
end
|
1192
1564
|
|
1565
|
+
def test_comment
|
1566
|
+
actual = compile_block("//comment[コメント]")
|
1567
|
+
assert_equal %Q||, actual
|
1568
|
+
end
|
1569
|
+
|
1570
|
+
def test_comment_for_draft
|
1571
|
+
@config["draft"] = true
|
1572
|
+
actual = compile_block("//comment[コメント]")
|
1573
|
+
assert_equal %Q|<div class="draft-comment">コメント</div>\n|, actual
|
1574
|
+
end
|
1575
|
+
|
1576
|
+
def test_inline_comment
|
1577
|
+
actual = compile_inline("test @<comment>{コメント} test2")
|
1578
|
+
assert_equal %Q|test test2|, actual
|
1579
|
+
end
|
1580
|
+
|
1581
|
+
def test_inline_comment_for_draft
|
1582
|
+
@config["draft"] = true
|
1583
|
+
actual = compile_inline("test @<comment>{コメント} test2")
|
1584
|
+
assert_equal %Q|test <span class="draft-comment">コメント</span> test2|, actual
|
1585
|
+
end
|
1193
1586
|
end
|