review 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +90 -66
- data/.travis.yml +1 -1
- data/Gemfile +0 -1
- data/NEWS.ja.md +82 -0
- data/NEWS.md +83 -0
- data/README.md +5 -3
- data/Rakefile +8 -8
- data/bin/review +1 -5
- data/bin/review-catalog-converter +22 -27
- data/bin/review-check +36 -43
- data/bin/review-checkdep +10 -15
- data/bin/review-compile +37 -55
- data/bin/review-epubmaker +4 -5
- data/bin/review-index +21 -29
- data/bin/review-init +26 -37
- data/bin/review-pdfmaker +0 -2
- data/bin/review-preproc +25 -45
- data/bin/review-validate +19 -18
- data/bin/review-vol +15 -27
- data/doc/config.yml.sample +5 -2
- data/doc/format.ja.md +20 -1
- data/doc/format.md +21 -5
- data/doc/images/review-generate.png +0 -0
- data/lib/epubmaker.rb +1 -3
- data/lib/epubmaker/content.rb +24 -27
- data/lib/epubmaker/epubcommon.rb +135 -148
- data/lib/epubmaker/epubv2.rb +39 -46
- data/lib/epubmaker/epubv3.rb +93 -103
- data/lib/epubmaker/producer.rb +138 -151
- data/lib/epubmaker/zip_exporter.rb +21 -26
- data/lib/review/book.rb +3 -6
- data/lib/review/book/base.rb +78 -103
- data/lib/review/book/chapter.rb +36 -40
- data/lib/review/book/compilable.rb +28 -31
- data/lib/review/book/image_finder.rb +6 -13
- data/lib/review/book/index.rb +100 -121
- data/lib/review/book/page_metric.rb +2 -7
- data/lib/review/book/part.rb +18 -20
- data/lib/review/book/volume.rb +9 -13
- data/lib/review/builder.rb +81 -116
- data/lib/review/catalog.rb +15 -19
- data/lib/review/compiler.rb +64 -83
- data/lib/review/configure.rb +87 -97
- data/lib/review/converter.rb +2 -7
- data/lib/review/epubbuilder.rb +1 -3
- data/lib/review/epubmaker.rb +213 -205
- data/lib/review/exception.rb +2 -4
- data/lib/review/extentions.rb +0 -1
- data/lib/review/extentions/hash.rb +2 -2
- data/lib/review/extentions/string.rb +5 -30
- data/lib/review/htmlbuilder.rb +320 -375
- data/lib/review/htmltoc.rb +4 -7
- data/lib/review/htmlutils.rb +29 -32
- data/lib/review/i18n.rb +33 -44
- data/lib/review/i18n.yml +3 -3
- data/lib/review/idgxmlbuilder.rb +309 -345
- data/lib/review/latexbuilder.rb +175 -212
- data/lib/review/latexindex.rb +2 -8
- data/lib/review/latexutils.rb +33 -43
- data/lib/review/lineinput.rb +1 -1
- data/lib/review/logger.rb +21 -0
- data/lib/review/makerhelper.rb +1 -4
- data/lib/review/markdownbuilder.rb +44 -53
- data/lib/review/md2inaobuilder.rb +6 -12
- data/lib/review/pdfmaker.rb +143 -173
- data/lib/review/preprocessor.rb +64 -101
- data/lib/review/rstbuilder.rb +126 -158
- data/lib/review/sec_counter.rb +18 -34
- data/lib/review/template.rb +4 -5
- data/lib/review/textbuilder.rb +2 -3
- data/lib/review/textutils.rb +7 -13
- data/lib/review/tocparser.rb +31 -56
- data/lib/review/tocprinter.rb +26 -52
- data/lib/review/topbuilder.rb +219 -247
- data/lib/review/unfold.rb +15 -24
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +75 -99
- data/lib/review/webtocprinter.rb +15 -20
- data/lib/review/yamlloader.rb +13 -15
- data/review.gemspec +20 -22
- data/templates/latex/layout.tex.erb +2 -2
- data/templates/opf/epubv2.opf.erb +7 -7
- data/templates/opf/epubv3.opf.erb +7 -7
- data/templates/web/html/layout-html5.html.erb +2 -2
- data/test/assets/black.eps +280 -0
- data/test/assets/fit.png +0 -0
- data/test/assets/large.gif +0 -0
- data/test/assets/large.jpg +0 -0
- data/test/assets/large.png +0 -0
- data/test/assets/large.svg +65 -0
- data/test/assets/test_template.tex +1 -1
- data/test/book_test_helper.rb +2 -2
- data/test/run_test.rb +4 -4
- data/test/sample-book/src/Rakefile +21 -22
- data/test/syntax-book/Gemfile +4 -0
- data/test/syntax-book/Rakefile +72 -0
- data/test/syntax-book/appA.re +22 -0
- data/test/syntax-book/bib.re +6 -0
- data/test/syntax-book/catalog.yml +15 -0
- data/test/syntax-book/ch01.re +136 -0
- data/test/syntax-book/ch02.re +351 -0
- data/test/syntax-book/ch03.re +82 -0
- data/test/syntax-book/config.yml +35 -0
- data/test/syntax-book/images/ball.png +0 -0
- data/test/syntax-book/images/cover.jpg +0 -0
- data/test/syntax-book/images/fractal.png +0 -0
- data/test/syntax-book/images/img3-1.png +0 -0
- data/test/syntax-book/images/inlineicon.jpg +0 -0
- data/test/syntax-book/images/logic.png +0 -0
- data/test/syntax-book/images/logic2.png +0 -0
- data/test/syntax-book/images/puzzle.jpg +0 -0
- data/test/syntax-book/images/table.jpg +0 -0
- data/test/syntax-book/part2.re +6 -0
- data/test/syntax-book/pre01.re +26 -0
- data/test/syntax-book/review-ext.rb +14 -0
- data/test/syntax-book/sty/jumoline.sty +310 -0
- data/test/syntax-book/sty/reviewmacro.sty +39 -0
- data/test/syntax-book/style.css +494 -0
- data/test/syntax-book/syntax.dic +2 -0
- data/test/test_book.rb +106 -111
- data/test/test_book_chapter.rb +21 -22
- data/test/test_book_part.rb +3 -5
- data/test/test_builder.rb +11 -22
- data/test/test_catalog.rb +17 -18
- data/test/test_catalog_converter_cmd.rb +5 -5
- data/test/test_compiler.rb +18 -16
- data/test/test_configure.rb +35 -38
- data/test/test_converter.rb +3 -4
- data/test/test_epub3maker.rb +136 -117
- data/test/test_epubmaker.rb +107 -114
- data/test/test_epubmaker_cmd.rb +2 -4
- data/test/test_extentions_hash.rb +32 -33
- data/test/test_helper.rb +9 -11
- data/test/test_htmlbuilder.rb +454 -420
- data/test/test_htmltoc.rb +8 -12
- data/test/test_htmlutils.rb +0 -2
- data/test/test_i18n.rb +159 -150
- data/test/test_idgxmlbuilder.rb +190 -197
- data/test/test_image_finder.rb +21 -22
- data/test/test_index.rb +24 -29
- data/test/test_latexbuilder.rb +274 -264
- data/test/test_lineinput.rb +7 -10
- data/test/test_location.rb +7 -7
- data/test/test_makerhelper.rb +13 -25
- data/test/test_markdownbuilder.rb +23 -26
- data/test/test_md2inaobuilder.rb +8 -11
- data/test/test_pdfmaker.rb +114 -123
- data/test/test_pdfmaker_cmd.rb +1 -3
- data/test/test_review_ext.rb +3 -5
- data/test/test_rstbuilder.rb +92 -97
- data/test/test_template.rb +3 -7
- data/test/test_textutils.rb +27 -27
- data/test/test_tocparser.rb +2 -2
- data/test/test_topbuilder.rb +98 -103
- data/test/test_webtocprinter.rb +5 -6
- data/test/test_yamlloader.rb +42 -42
- data/test/test_zip_exporter.rb +12 -18
- metadata +86 -9
- data/lib/review/ewbbuilder.rb +0 -382
data/test/test_epubmaker_cmd.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'test_helper'
|
4
2
|
require 'tmpdir'
|
5
3
|
require 'fileutils'
|
@@ -26,10 +24,10 @@ class EPUBMakerCmdTest < Test::Unit::TestCase
|
|
26
24
|
def test_epubmaker_cmd
|
27
25
|
if /mswin|mingw|cygwin/ !~ RUBY_PLATFORM
|
28
26
|
config = prepare_samplebook(@tmpdir1)
|
29
|
-
builddir = @tmpdir1 +
|
27
|
+
builddir = @tmpdir1 + '/' + config['bookname'] + '-epub'
|
30
28
|
assert !File.exist?(builddir)
|
31
29
|
|
32
|
-
ruby_cmd = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) + RbConfig::CONFIG[
|
30
|
+
ruby_cmd = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) + RbConfig::CONFIG['EXEEXT']
|
33
31
|
Dir.chdir(@tmpdir1) do
|
34
32
|
system("#{ruby_cmd} -S #{REVIEW_EPUBMAKER} config.yml 1>/dev/null 2>/dev/null")
|
35
33
|
end
|
@@ -3,65 +3,64 @@ require 'review/extentions/hash'
|
|
3
3
|
|
4
4
|
class TestExtentionsHash < Test::Unit::TestCase
|
5
5
|
def test_deep_merge_simple
|
6
|
-
assert_equal({:
|
7
|
-
{:
|
6
|
+
assert_equal({ a: 1, b: 3, c: 4 },
|
7
|
+
{ a: 1, b: 2 }.deep_merge(b: 3, c: 4))
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_deep_empty_r
|
11
|
-
assert_equal({:
|
12
|
-
{}.deep_merge(
|
11
|
+
assert_equal({ b: 3, c: 4 },
|
12
|
+
{}.deep_merge(b: 3, c: 4))
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_deep_empty_l
|
16
|
-
assert_equal({:
|
17
|
-
{:
|
16
|
+
assert_equal({ a: 1, b: 2 },
|
17
|
+
{ a: 1, b: 2 }.deep_merge({}))
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_deep_merge_nested
|
21
|
-
assert_equal({:
|
22
|
-
|
23
|
-
|
24
|
-
{:
|
25
|
-
|
26
|
-
|
21
|
+
assert_equal({ a: { aa: 1, ab: 2 },
|
22
|
+
b: { ba: 5, bb: 4, bc: 6 },
|
23
|
+
c: { ca: 1 } },
|
24
|
+
{ a: { aa: 1, ab: 2 },
|
25
|
+
b: { ba: 3, bb: 4 } }.deep_merge(b: { ba: 5, bc: 6 },
|
26
|
+
c: { ca: 1 }))
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_deep_merge_with_array
|
30
|
-
assert_equal({:
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
:c => {:ca => [:cab => "CAB"]}}))
|
30
|
+
assert_equal({ a: 'string', b: ['BA'],
|
31
|
+
c: { ca: [cab: 'CAB'], cb: 3 } },
|
32
|
+
{ a: 1, b: ['shouldoverriden'],
|
33
|
+
c: { ca: [caa: 'shouldoverriden'], cb: 3 } }.
|
34
|
+
deep_merge(a: 'string', b: ['BA'],
|
35
|
+
c: { ca: [cab: 'CAB'] }))
|
37
36
|
end
|
38
37
|
|
39
38
|
def test_deep_merge_b_simple
|
40
|
-
a = {:
|
41
|
-
a.deep_merge!(
|
42
|
-
assert_equal({:
|
39
|
+
a = { a: 1, b: 2 }
|
40
|
+
a.deep_merge!(b: 3, c: 4)
|
41
|
+
assert_equal({ a: 1, b: 3, c: 4 }, a)
|
43
42
|
end
|
44
43
|
|
45
44
|
def test_deep_b_empty_r
|
46
45
|
a = {}
|
47
|
-
a.deep_merge!(
|
48
|
-
assert_equal({:
|
46
|
+
a.deep_merge!(b: 3, c: 4)
|
47
|
+
assert_equal({ b: 3, c: 4 }, a)
|
49
48
|
end
|
50
49
|
|
51
50
|
def test_deep_b_empty_l
|
52
|
-
a = {:
|
51
|
+
a = { a: 1, b: 2 }
|
53
52
|
a.deep_merge!({})
|
54
|
-
assert_equal({:
|
53
|
+
assert_equal({ a: 1, b: 2 }, a)
|
55
54
|
end
|
56
55
|
|
57
56
|
def test_deep_merge_b_nested
|
58
|
-
a = {:
|
59
|
-
|
60
|
-
a.deep_merge!(
|
61
|
-
|
62
|
-
assert_equal({:
|
63
|
-
|
64
|
-
|
57
|
+
a = { a: { aa: 1, ab: 2 },
|
58
|
+
b: { ba: 3, bb: 4 } }
|
59
|
+
a.deep_merge!(b: { ba: 5, bc: 6 },
|
60
|
+
c: { ca: 1 })
|
61
|
+
assert_equal({ a: { aa: 1, ab: 2 },
|
62
|
+
b: { ba: 5, bb: 4, bc: 6 },
|
63
|
+
c: { ca: 1 } },
|
65
64
|
a)
|
66
65
|
end
|
67
66
|
end
|
data/test/test_helper.rb
CHANGED
@@ -2,18 +2,18 @@ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib/')
|
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
4
|
def touch_file(path)
|
5
|
-
File.open(path,
|
5
|
+
File.open(path, 'w').close
|
6
6
|
path
|
7
7
|
end
|
8
8
|
|
9
9
|
def assets_dir
|
10
|
-
File.join(File.dirname(__FILE__),
|
10
|
+
File.join(File.dirname(__FILE__), 'assets')
|
11
11
|
end
|
12
12
|
|
13
13
|
def prepare_samplebook(srcdir)
|
14
|
-
samplebook_dir = File.expand_path(
|
15
|
-
FileUtils.cp_r(Dir.glob(samplebook_dir +
|
16
|
-
YAML.load(File.open(srcdir +
|
14
|
+
samplebook_dir = File.expand_path('sample-book/src/', File.dirname(__FILE__))
|
15
|
+
FileUtils.cp_r(Dir.glob(samplebook_dir + '/*'), srcdir)
|
16
|
+
YAML.load(File.open(srcdir + '/config.yml'))
|
17
17
|
end
|
18
18
|
|
19
19
|
def compile_inline(text)
|
@@ -22,9 +22,7 @@ end
|
|
22
22
|
|
23
23
|
def compile_block(text)
|
24
24
|
method_name = "compile_block_#{@builder.target_name}"
|
25
|
-
|
26
|
-
method_name = "compile_block_default"
|
27
|
-
end
|
25
|
+
method_name = 'compile_block_default' unless self.respond_to?(method_name, true)
|
28
26
|
self.__send__(method_name, text)
|
29
27
|
end
|
30
28
|
|
@@ -35,15 +33,15 @@ end
|
|
35
33
|
|
36
34
|
def compile_block_html(text)
|
37
35
|
@chapter.content = text
|
38
|
-
matched = @compiler.compile(@chapter).match(
|
36
|
+
matched = @compiler.compile(@chapter).match(Regexp.new(%Q(<body>\n(.+)</body>), Regexp::MULTILINE))
|
39
37
|
if matched && matched.size > 1
|
40
38
|
matched[1]
|
41
39
|
else
|
42
|
-
|
40
|
+
''
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
44
|
def compile_block_idgxml(text)
|
47
45
|
@chapter.content = text
|
48
|
-
@compiler.compile(@chapter).gsub(
|
46
|
+
@compiler.compile(@chapter).gsub(Regexp.new(%Q(.*<doc xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">), Regexp::MULTILINE), '').gsub("</doc>\n", '')
|
49
47
|
end
|
data/test/test_htmlbuilder.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'test_helper'
|
4
2
|
require 'review'
|
5
3
|
|
@@ -8,73 +6,71 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
8
6
|
|
9
7
|
def setup
|
10
8
|
ReVIEW::I18n.setup
|
11
|
-
@builder = HTMLBuilder.new
|
9
|
+
@builder = HTMLBuilder.new
|
12
10
|
@config = ReVIEW::Configure.values
|
13
|
-
@config
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
})
|
18
|
-
@book = Book::Base.new(".")
|
11
|
+
@config['secnolevel'] = 2
|
12
|
+
@config['stylesheet'] = nil
|
13
|
+
@config['htmlext'] = 'html'
|
14
|
+
@book = Book::Base.new('.')
|
19
15
|
@book.config = @config
|
20
16
|
@compiler = ReVIEW::Compiler.new(@builder)
|
21
17
|
@chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
|
22
18
|
location = Location.new(nil, nil)
|
23
19
|
@builder.bind(@compiler, @chapter, location)
|
24
|
-
I18n.setup(
|
20
|
+
I18n.setup('ja')
|
25
21
|
end
|
26
22
|
|
27
23
|
def test_xmlns_ops_prefix_epub3
|
28
|
-
assert_equal
|
24
|
+
assert_equal 'epub', @builder.xmlns_ops_prefix
|
29
25
|
end
|
30
26
|
|
31
27
|
def test_xmlns_ops_prefix_epub2
|
32
|
-
@book.config[
|
33
|
-
assert_equal
|
28
|
+
@book.config['epubversion'] = 2
|
29
|
+
assert_equal 'ops', @builder.xmlns_ops_prefix
|
34
30
|
end
|
35
31
|
|
36
32
|
def test_headline_level1
|
37
33
|
actual = compile_block("={test} this is test.\n")
|
38
|
-
assert_equal %Q
|
34
|
+
assert_equal %Q(<h1 id="test"><a id="h1"></a><span class="secno">第1章 </span>this is test.</h1>\n), actual
|
39
35
|
end
|
40
36
|
|
41
37
|
def test_headline_level1_postdef
|
42
38
|
@chapter.instance_eval do
|
43
|
-
def
|
39
|
+
def on_appendix?
|
44
40
|
true
|
45
41
|
end
|
46
42
|
end
|
47
43
|
actual = compile_block("={test} this is test.\n")
|
48
|
-
assert_equal %Q
|
44
|
+
assert_equal %Q(<h1 id="test"><a id="hA"></a><span class="secno">付録A </span>this is test.</h1>\n), actual
|
49
45
|
end
|
50
46
|
|
51
47
|
def test_headline_level2_postdef
|
52
48
|
@chapter.instance_eval do
|
53
|
-
def
|
49
|
+
def on_appendix?
|
54
50
|
true
|
55
51
|
end
|
56
52
|
end
|
57
53
|
actual = compile_block("=={test} this is test.\n")
|
58
|
-
assert_equal %Q
|
54
|
+
assert_equal %Q(\n<h2 id="test"><a id="hA-1"></a><span class="secno">A.1 </span>this is test.</h2>\n), actual
|
59
55
|
end
|
60
56
|
|
61
57
|
def test_headline_postdef_roman
|
62
58
|
Dir.mktmpdir do |dir|
|
63
59
|
Dir.chdir(dir) do
|
64
|
-
file = File.join(dir,
|
65
|
-
File.open(file,
|
66
|
-
I18n.setup(
|
60
|
+
file = File.join(dir, 'locale.yml')
|
61
|
+
File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pR") }
|
62
|
+
I18n.setup('ja')
|
67
63
|
@chapter.instance_eval do
|
68
|
-
def
|
64
|
+
def on_appendix?
|
69
65
|
true
|
70
66
|
end
|
71
67
|
end
|
72
68
|
|
73
69
|
actual = compile_block("={test} this is test.\n")
|
74
|
-
assert_equal %Q
|
70
|
+
assert_equal %Q(<h1 id="test"><a id="hI"></a><span class="secno">付録I </span>this is test.</h1>\n), actual
|
75
71
|
|
76
72
|
actual = compile_block("=={test} this is test.\n")
|
77
|
-
assert_equal %Q
|
73
|
+
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
74
|
end
|
79
75
|
end
|
80
76
|
end
|
@@ -82,193 +78,193 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
82
78
|
def test_headline_postdef_alpha
|
83
79
|
Dir.mktmpdir do |dir|
|
84
80
|
Dir.chdir(dir) do
|
85
|
-
file = File.join(dir,
|
86
|
-
File.open(file,
|
87
|
-
I18n.setup(
|
81
|
+
file = File.join(dir, 'locale.yml')
|
82
|
+
File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pA") }
|
83
|
+
I18n.setup('ja')
|
88
84
|
@chapter.instance_eval do
|
89
|
-
def
|
85
|
+
def on_appendix?
|
90
86
|
true
|
91
87
|
end
|
92
88
|
end
|
93
89
|
|
94
90
|
actual = compile_block("={test} this is test.\n")
|
95
|
-
assert_equal %Q
|
91
|
+
assert_equal %Q(<h1 id="test"><a id="hA"></a><span class="secno">付録A </span>this is test.</h1>\n), actual
|
96
92
|
|
97
93
|
actual = compile_block("=={test} this is test.\n")
|
98
|
-
assert_equal %Q
|
94
|
+
assert_equal %Q(\n<h2 id="test"><a id="hA-1"></a><span class="secno">A.1 </span>this is test.</h2>\n), actual
|
99
95
|
end
|
100
96
|
end
|
101
97
|
end
|
102
98
|
|
103
99
|
def test_headline_level1_without_secno
|
104
|
-
@book.config[
|
100
|
+
@book.config['secnolevel'] = 0
|
105
101
|
actual = compile_block("={test} this is test.\n")
|
106
|
-
assert_equal %Q
|
102
|
+
assert_equal %Q(<h1 id="test"><a id="h1"></a>this is test.</h1>\n), actual
|
107
103
|
end
|
108
104
|
|
109
105
|
def test_headline_level1_with_tricky_id
|
110
106
|
actual = compile_block("={123 あ_;} this is test.\n")
|
111
|
-
assert_equal %Q
|
107
|
+
assert_equal %Q(<h1 id="id_123-_E3_81_82___3B"><a id="h1"></a><span class="secno">第1章 </span>this is test.</h1>\n), actual
|
112
108
|
end
|
113
109
|
|
114
110
|
def test_headline_level1_with_inlinetag
|
115
|
-
actual = compile_block(
|
116
|
-
assert_equal %Q
|
111
|
+
actual = compile_block(%Q(={test} this @<b>{is} test.<&">\n))
|
112
|
+
assert_equal %Q(<h1 id="test"><a id="h1"></a><span class="secno">第1章 </span>this <b>is</b> test.<&"></h1>\n), actual
|
117
113
|
end
|
118
114
|
|
119
115
|
def test_headline_level2
|
120
116
|
actual = compile_block("=={test} this is test.\n")
|
121
|
-
assert_equal %Q
|
117
|
+
assert_equal %Q(\n<h2 id="test"><a id="h1-1"></a><span class="secno">1.1 </span>this is test.</h2>\n), actual
|
122
118
|
end
|
123
119
|
|
124
120
|
def test_headline_level3
|
125
121
|
actual = compile_block("==={test} this is test.\n")
|
126
|
-
assert_equal %Q
|
122
|
+
assert_equal %Q(\n<h3 id="test"><a id="h1-0-1"></a>this is test.</h3>\n), actual
|
127
123
|
end
|
128
124
|
|
129
125
|
def test_headline_level3_with_secno
|
130
|
-
@book.config[
|
126
|
+
@book.config['secnolevel'] = 3
|
131
127
|
actual = compile_block("==={test} this is test.\n")
|
132
|
-
assert_equal %Q
|
128
|
+
assert_equal %Q(\n<h3 id="test"><a id="h1-0-1"></a><span class="secno">1.0.1 </span>this is test.</h3>\n), actual
|
133
129
|
end
|
134
130
|
|
135
131
|
def test_label
|
136
132
|
actual = compile_block("//label[label_test]\n")
|
137
|
-
assert_equal %Q
|
133
|
+
assert_equal %Q(<a id="label_test"></a>\n), actual
|
138
134
|
end
|
139
135
|
|
140
136
|
def test_label_with_tricky_id
|
141
137
|
actual = compile_block("//label[123 あ_;]\n")
|
142
|
-
assert_equal %Q
|
138
|
+
assert_equal %Q(<a id="id_123-_E3_81_82___3B"></a>\n), actual
|
143
139
|
end
|
144
140
|
|
145
141
|
def test_href
|
146
|
-
actual = compile_inline(
|
147
|
-
assert_equal %Q
|
142
|
+
actual = compile_inline('@<href>{http://github.com,GitHub}')
|
143
|
+
assert_equal %Q(<a href="http://github.com" class="link">GitHub</a>), actual
|
148
144
|
end
|
149
145
|
|
150
146
|
def test_href_without_label
|
151
|
-
actual = compile_inline(
|
152
|
-
assert_equal %Q
|
147
|
+
actual = compile_inline('@<href>{http://github.com}')
|
148
|
+
assert_equal %Q(<a href="http://github.com" class="link">http://github.com</a>), actual
|
153
149
|
end
|
154
150
|
|
155
151
|
def test_inline_href
|
156
|
-
actual = compile_inline(
|
157
|
-
assert_equal %Q
|
152
|
+
actual = compile_inline('@<href>{http://github.com,Git\\,Hub}')
|
153
|
+
assert_equal %Q(<a href="http://github.com" class="link">Git,Hub</a>), actual
|
158
154
|
|
159
|
-
@book.config[
|
160
|
-
@book.config[
|
161
|
-
actual = compile_inline(
|
162
|
-
assert_equal %Q
|
155
|
+
@book.config['epubmaker'] ||= {}
|
156
|
+
@book.config['epubmaker']['externallink'] = false
|
157
|
+
actual = compile_inline('@<href>{http://github.com&q=1,Git\\,Hub}')
|
158
|
+
assert_equal %Q(<a href="http://github.com&q=1" class="link">Git,Hub</a>), actual
|
163
159
|
|
164
|
-
actual = compile_inline(
|
165
|
-
assert_equal %Q
|
160
|
+
actual = compile_inline('@<href>{http://github.com&q=1}')
|
161
|
+
assert_equal %Q(<a href="http://github.com&q=1" class="link">http://github.com&q=1</a>), actual
|
166
162
|
end
|
167
163
|
|
168
164
|
def test_inline_href_epubmaker
|
169
|
-
@book.config.maker =
|
170
|
-
actual = compile_inline(
|
171
|
-
assert_equal %Q
|
165
|
+
@book.config.maker = 'epubmaker'
|
166
|
+
actual = compile_inline('@<href>{http://github.com,Git\\,Hub}')
|
167
|
+
assert_equal %Q(<a href="http://github.com" class="link">Git,Hub</a>), actual
|
172
168
|
|
173
|
-
@book.config[
|
174
|
-
@book.config[
|
175
|
-
actual = compile_inline(
|
176
|
-
assert_equal
|
169
|
+
@book.config['epubmaker'] ||= {}
|
170
|
+
@book.config['epubmaker']['externallink'] = false
|
171
|
+
actual = compile_inline('@<href>{http://github.com&q=1,Git\\,Hub}')
|
172
|
+
assert_equal 'Git,Hub(http://github.com&q=1)', actual
|
177
173
|
|
178
|
-
actual = compile_inline(
|
179
|
-
assert_equal
|
174
|
+
actual = compile_inline('@<href>{http://github.com&q=1}')
|
175
|
+
assert_equal 'http://github.com&q=1', actual
|
180
176
|
|
181
|
-
@book.config[
|
182
|
-
actual = compile_inline(
|
183
|
-
assert_equal %Q
|
184
|
-
actual = compile_inline(
|
185
|
-
assert_equal %Q
|
177
|
+
@book.config['epubmaker']['externallink'] = true
|
178
|
+
actual = compile_inline('@<href>{http://github.com&q=1,Git\\,Hub}')
|
179
|
+
assert_equal %Q(<a href="http://github.com&q=1" class="link">Git,Hub</a>), actual
|
180
|
+
actual = compile_inline('@<href>{http://github.com&q=1}')
|
181
|
+
assert_equal %Q(<a href="http://github.com&q=1" class="link">http://github.com&q=1</a>), actual
|
186
182
|
end
|
187
183
|
|
188
184
|
def test_inline_raw
|
189
|
-
actual = compile_inline(
|
190
|
-
assert_equal
|
185
|
+
actual = compile_inline('@<raw>{@<tt>{inline\\}}')
|
186
|
+
assert_equal '@<tt>{inline}', actual
|
191
187
|
end
|
192
188
|
|
193
189
|
def test_inline_in_table
|
194
190
|
actual = compile_block("//table{\n@<b>{1}\t@<i>{2}\n------------\n@<b>{3}\t@<i>{4}<>&\n//}\n")
|
195
|
-
assert_equal %Q
|
191
|
+
assert_equal %Q(<div class="table">\n<table>\n<tr><th><b>1</b></th><th><i>2</i></th></tr>\n<tr><td><b>3</b></td><td><i>4</i><>&</td></tr>\n</table>\n</div>\n), actual
|
196
192
|
end
|
197
193
|
|
198
194
|
def test_inline_br
|
199
|
-
actual = compile_inline(
|
200
|
-
assert_equal
|
195
|
+
actual = compile_inline('@<br>{}')
|
196
|
+
assert_equal '<br />', actual
|
201
197
|
end
|
202
198
|
|
203
199
|
def test_inline_i
|
204
|
-
actual = compile_inline(
|
205
|
-
assert_equal
|
200
|
+
actual = compile_inline('test @<i>{inline test} test2')
|
201
|
+
assert_equal 'test <i>inline test</i> test2', actual
|
206
202
|
end
|
207
203
|
|
208
204
|
def test_inline_i_and_escape
|
209
|
-
actual = compile_inline(
|
210
|
-
assert_equal
|
205
|
+
actual = compile_inline('test @<i>{inline<&;\\ test} test2')
|
206
|
+
assert_equal 'test <i>inline<&;\\ test</i> test2', actual
|
211
207
|
end
|
212
208
|
|
213
209
|
def test_inline_b
|
214
|
-
actual = compile_inline(
|
215
|
-
assert_equal
|
210
|
+
actual = compile_inline('test @<b>{inline test} test2')
|
211
|
+
assert_equal 'test <b>inline test</b> test2', actual
|
216
212
|
end
|
217
213
|
|
218
214
|
def test_inline_b_and_escape
|
219
|
-
actual = compile_inline(
|
220
|
-
assert_equal
|
215
|
+
actual = compile_inline('test @<b>{inline<&;\\ test} test2')
|
216
|
+
assert_equal 'test <b>inline<&;\\ test</b> test2', actual
|
221
217
|
end
|
222
218
|
|
223
219
|
def test_inline_tt
|
224
|
-
actual = compile_inline(
|
225
|
-
assert_equal %Q
|
220
|
+
actual = compile_inline('test @<tt>{inline test} test2')
|
221
|
+
assert_equal %Q(test <code class="tt">inline test</code> test2), actual
|
226
222
|
end
|
227
223
|
|
228
224
|
def test_inline_tti
|
229
|
-
actual = compile_inline(
|
230
|
-
assert_equal %Q
|
225
|
+
actual = compile_inline('test @<tti>{inline test} test2')
|
226
|
+
assert_equal %Q(test <code class="tt"><i>inline test</i></code> test2), actual
|
231
227
|
end
|
232
228
|
|
233
229
|
def test_inline_ttb
|
234
|
-
actual = compile_inline(
|
235
|
-
assert_equal %Q
|
230
|
+
actual = compile_inline('test @<ttb>{inline test} test2')
|
231
|
+
assert_equal %Q(test <code class="tt"><b>inline test</b></code> test2), actual
|
236
232
|
end
|
237
233
|
|
238
234
|
def test_inline_hd_chap
|
239
235
|
def @chapter.headline_index
|
240
|
-
items = [Book::HeadlineIndex::Item.new(
|
236
|
+
items = [Book::HeadlineIndex::Item.new('chap1|test', [1, 1], 'te_st')]
|
241
237
|
Book::HeadlineIndex.new(items, self)
|
242
238
|
end
|
243
239
|
|
244
|
-
@config[
|
245
|
-
actual = compile_inline(
|
246
|
-
assert_equal
|
240
|
+
@config['secnolevel'] = 2
|
241
|
+
actual = compile_inline('test @<hd>{chap1|test} test2')
|
242
|
+
assert_equal 'test 「te_st」 test2', actual
|
247
243
|
|
248
|
-
@config[
|
249
|
-
actual = compile_inline(
|
250
|
-
assert_equal
|
244
|
+
@config['secnolevel'] = 3
|
245
|
+
actual = compile_inline('test @<hd>{chap1|test} test2')
|
246
|
+
assert_equal 'test 「1.1.1 te_st」 test2', actual
|
251
247
|
end
|
252
248
|
|
253
249
|
def test_inline_hd_chap_postdef_roman
|
254
250
|
Dir.mktmpdir do |dir|
|
255
251
|
Dir.chdir(dir) do
|
256
|
-
file = File.join(dir,
|
257
|
-
File.open(file,
|
258
|
-
I18n.setup(
|
252
|
+
file = File.join(dir, 'locale.yml')
|
253
|
+
File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pR") }
|
254
|
+
I18n.setup('ja')
|
259
255
|
@chapter.instance_eval do
|
260
|
-
def
|
256
|
+
def on_appendix?
|
261
257
|
true
|
262
258
|
end
|
263
259
|
end
|
264
260
|
|
265
261
|
def @chapter.headline_index
|
266
|
-
items = [Book::HeadlineIndex::Item.new(
|
262
|
+
items = [Book::HeadlineIndex::Item.new('test', [1], 'te_st')]
|
267
263
|
Book::HeadlineIndex.new(items, self)
|
268
264
|
end
|
269
265
|
|
270
|
-
actual = compile_inline(
|
271
|
-
assert_equal
|
266
|
+
actual = compile_inline('test @<hd>{test} test2')
|
267
|
+
assert_equal 'test 「I.1 te_st」 test2', actual
|
272
268
|
end
|
273
269
|
end
|
274
270
|
end
|
@@ -276,109 +272,109 @@ class HTMLBuidlerTest < Test::Unit::TestCase
|
|
276
272
|
def test_inline_hd_chap_postdef_alpha
|
277
273
|
Dir.mktmpdir do |dir|
|
278
274
|
Dir.chdir(dir) do
|
279
|
-
file = File.join(dir,
|
280
|
-
File.open(file,
|
281
|
-
I18n.setup(
|
275
|
+
file = File.join(dir, 'locale.yml')
|
276
|
+
File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pA") }
|
277
|
+
I18n.setup('ja')
|
282
278
|
@chapter.instance_eval do
|
283
|
-
def
|
279
|
+
def on_appendix?
|
284
280
|
true
|
285
281
|
end
|
286
282
|
end
|
287
283
|
|
288
284
|
def @chapter.headline_index
|
289
|
-
items = [Book::HeadlineIndex::Item.new(
|
285
|
+
items = [Book::HeadlineIndex::Item.new('test', [1], 'te_st')]
|
290
286
|
Book::HeadlineIndex.new(items, self)
|
291
287
|
end
|
292
288
|
|
293
|
-
actual = compile_inline(
|
294
|
-
assert_equal
|
289
|
+
actual = compile_inline('test @<hd>{test} test2')
|
290
|
+
assert_equal 'test 「A.1 te_st」 test2', actual
|
295
291
|
end
|
296
292
|
end
|
297
293
|
end
|
298
294
|
|
299
295
|
def test_inline_uchar
|
300
|
-
actual = compile_inline(
|
301
|
-
assert_equal
|
296
|
+
actual = compile_inline('test @<uchar>{2460} test2')
|
297
|
+
assert_equal 'test ① test2', actual
|
302
298
|
end
|
303
299
|
|
304
300
|
def test_inline_ruby
|
305
|
-
actual = compile_inline(
|
306
|
-
assert_equal
|
301
|
+
actual = compile_inline('@<ruby>{粗雑,クルード}と思われているなら@<ruby>{繊細,テクニカル}にやり、繊細と思われているなら粗雑にやる。')
|
302
|
+
assert_equal '<ruby>粗雑<rp>(</rp><rt>クルード</rt><rp>)</rp></ruby>と思われているなら<ruby>繊細<rp>(</rp><rt>テクニカル</rt><rp>)</rp></ruby>にやり、繊細と思われているなら粗雑にやる。', actual
|
307
303
|
end
|
308
304
|
|
309
305
|
def test_inline_ruby_comma
|
310
|
-
actual = compile_inline(
|
311
|
-
assert_equal
|
306
|
+
actual = compile_inline('@<ruby>{foo\\, bar\\, buz,フー・バー・バズ}')
|
307
|
+
assert_equal '<ruby>foo, bar, buz<rp>(</rp><rt>フー・バー・バズ</rt><rp>)</rp></ruby>', actual
|
312
308
|
end
|
313
309
|
|
314
310
|
def test_inline_ref
|
315
|
-
actual = compile_inline(
|
316
|
-
assert_equal %Q
|
311
|
+
actual = compile_inline('@<ref>{外部参照<>&}')
|
312
|
+
assert_equal %Q(<a target='外部参照<>&'>「●● 外部参照<>&」</a>), actual
|
317
313
|
end
|
318
314
|
|
319
315
|
def test_inline_mathml
|
320
316
|
begin
|
321
317
|
require 'math_ml'
|
322
|
-
require
|
318
|
+
require 'math_ml/symbol/character_reference'
|
323
319
|
rescue LoadError
|
324
320
|
return true
|
325
321
|
end
|
326
|
-
@config[
|
327
|
-
actual = compile_inline(
|
328
|
-
@config[
|
329
|
-
assert_equal
|
322
|
+
@config['mathml'] = true
|
323
|
+
actual = compile_inline('@<m>{\\frac{-b \\pm \\sqrt{b^2 - 4ac\\}\\}{2a\\}}')
|
324
|
+
@config['mathml'] = nil
|
325
|
+
assert_equal %Q(<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
|
330
326
|
end
|
331
327
|
|
332
328
|
def test_inline_img
|
333
|
-
def @chapter.image(
|
334
|
-
item = Book::ImageIndex::Item.new(
|
335
|
-
item.instance_eval{@path=
|
329
|
+
def @chapter.image(_id)
|
330
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1, 'sample photo')
|
331
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
336
332
|
item
|
337
333
|
end
|
338
334
|
|
339
335
|
actual = compile_block "@<img>{sampleimg}\n"
|
340
|
-
expected = %Q
|
336
|
+
expected = %Q(<p><span class="imgref">図1.1</span></p>\n)
|
341
337
|
assert_equal expected, actual
|
342
338
|
end
|
343
339
|
|
344
340
|
def test_inline_imgref
|
345
|
-
def @chapter.image(
|
346
|
-
item = Book::ImageIndex::Item.new(
|
347
|
-
item.instance_eval{@path=
|
341
|
+
def @chapter.image(_id)
|
342
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1, 'sample photo')
|
343
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
348
344
|
item
|
349
345
|
end
|
350
346
|
|
351
347
|
actual = compile_block "@<imgref>{sampleimg}\n"
|
352
|
-
expected = %Q
|
348
|
+
expected = %Q(<p><span class="imgref">図1.1</span>「sample photo」</p>\n)
|
353
349
|
assert_equal expected, actual
|
354
350
|
end
|
355
351
|
|
356
352
|
def test_inline_imgref2
|
357
|
-
def @chapter.image(
|
358
|
-
item = Book::NumberlessImageIndex::Item.new(
|
359
|
-
item.instance_eval{@path=
|
353
|
+
def @chapter.image(_id)
|
354
|
+
item = Book::NumberlessImageIndex::Item.new('sampleimg', 1)
|
355
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
360
356
|
item
|
361
357
|
end
|
362
358
|
|
363
359
|
actual = compile_block "@<imgref>{sampleimg}\n"
|
364
|
-
expected = %Q
|
360
|
+
expected = %Q(<p><span class="imgref">図1.1</span></p>\n)
|
365
361
|
assert_equal expected, actual
|
366
362
|
end
|
367
363
|
|
368
364
|
def test_inline_imgref3
|
369
365
|
Dir.mktmpdir do |dir|
|
370
366
|
Dir.chdir(dir) do
|
371
|
-
file1 = File.join(dir,
|
372
|
-
filet1 = File.join(dir,
|
373
|
-
file2 = File.join(dir,
|
374
|
-
re1 = File.join(dir,
|
375
|
-
cat = File.join(dir,
|
376
|
-
FileUtils.mkdir_p(File.join(dir,
|
377
|
-
File.open(file1,
|
378
|
-
File.open(filet1,
|
379
|
-
File.open(file2,
|
380
|
-
File.open(cat,
|
381
|
-
File.open(re1,
|
367
|
+
file1 = File.join(dir, 'images', 'img1.png')
|
368
|
+
filet1 = File.join(dir, 'images', 'tbl1.png')
|
369
|
+
file2 = File.join(dir, 'images', 'img2.png')
|
370
|
+
re1 = File.join(dir, 'sample1.re')
|
371
|
+
cat = File.join(dir, 'catalog.yml')
|
372
|
+
FileUtils.mkdir_p(File.join(dir, 'images'))
|
373
|
+
File.open(file1, 'w') { |f| f.write('') }
|
374
|
+
File.open(filet1, 'w') { |f| f.write('') }
|
375
|
+
File.open(file2, 'w') { |f| f.write('') }
|
376
|
+
File.open(cat, 'w') { |f| f.write("CHAPS:\n - sample1.re\n") }
|
377
|
+
File.open(re1, 'w') { |f| f.write(<<EOF) }
|
382
378
|
= test
|
383
379
|
|
384
380
|
tbl1 is @<table>{tbl1}.
|
@@ -397,7 +393,7 @@ EOF
|
|
397
393
|
content = File.read(re1)
|
398
394
|
actual = compile_block(content)
|
399
395
|
|
400
|
-
expected
|
396
|
+
expected = <<-EOS
|
401
397
|
<h1><a id="h1"></a><span class="secno">第1章 </span>test</h1>
|
402
398
|
<p>tbl1 is <span class="tableref">表1.1</span>.</p>
|
403
399
|
<p>img2 is <span class="imgref">図1.2</span>.</p>
|
@@ -426,170 +422,170 @@ EOS
|
|
426
422
|
|
427
423
|
def test_quote
|
428
424
|
actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
|
429
|
-
assert_equal %Q
|
425
|
+
assert_equal %Q(<blockquote><p>foobar</p>\n<p>buz</p></blockquote>\n), actual
|
430
426
|
end
|
431
427
|
|
432
428
|
def test_memo
|
433
429
|
actual = compile_block("//memo[this is @<b>{test}<&>_]{\ntest1\n\ntest@<i>{2}\n//}\n")
|
434
|
-
assert_equal %Q
|
430
|
+
assert_equal %Q(<div class="memo">\n<p class="caption">this is <b>test</b><&>_</p>\n<p>test1</p>\n<p>test<i>2</i></p>\n</div>\n), actual
|
435
431
|
end
|
436
432
|
|
437
433
|
def test_noindent
|
438
434
|
@builder.noindent
|
439
435
|
actual = compile_block("foo\nbar\n\nfoo2\nbar2\n")
|
440
|
-
assert_equal %Q
|
436
|
+
assert_equal %Q(<p class="noindent">foobar</p>\n<p>foo2bar2</p>\n), actual
|
441
437
|
end
|
442
438
|
|
443
439
|
def test_flushright
|
444
440
|
actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
|
445
|
-
assert_equal %Q
|
441
|
+
assert_equal %Q(<p class="flushright">foobar</p>\n<p class="flushright">buz</p>\n), actual
|
446
442
|
end
|
447
443
|
|
448
444
|
def test_centering
|
449
445
|
actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
|
450
|
-
assert_equal %Q
|
446
|
+
assert_equal %Q(<p class="center">foobar</p>\n<p class="center">buz</p>\n), actual
|
451
447
|
end
|
452
448
|
|
453
449
|
def test_image
|
454
|
-
def @chapter.image(
|
455
|
-
item = Book::ImageIndex::Item.new(
|
456
|
-
item.instance_eval{@path=
|
450
|
+
def @chapter.image(_id)
|
451
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
452
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
457
453
|
item
|
458
454
|
end
|
459
455
|
|
460
456
|
actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
|
461
|
-
assert_equal %Q
|
457
|
+
assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n), actual
|
462
458
|
end
|
463
459
|
|
464
460
|
def test_image_with_metric
|
465
|
-
def @chapter.image(
|
466
|
-
item = Book::ImageIndex::Item.new(
|
467
|
-
item.instance_eval{@path=
|
461
|
+
def @chapter.image(_id)
|
462
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
463
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
468
464
|
item
|
469
465
|
end
|
470
466
|
|
471
467
|
actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
|
472
|
-
assert_equal %Q
|
468
|
+
assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n), actual
|
473
469
|
end
|
474
470
|
|
475
471
|
def test_image_with_metric2
|
476
|
-
def @chapter.image(
|
477
|
-
item = Book::ImageIndex::Item.new(
|
478
|
-
item.instance_eval{@path=
|
472
|
+
def @chapter.image(_id)
|
473
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
474
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
479
475
|
item
|
480
476
|
end
|
481
477
|
|
482
478
|
actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
|
483
|
-
assert_equal %Q
|
479
|
+
assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per sample" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n), actual
|
484
480
|
end
|
485
481
|
|
486
482
|
def test_image_with_tricky_id
|
487
|
-
def @chapter.image(
|
488
|
-
item = Book::ImageIndex::Item.new(
|
489
|
-
item.instance_eval{@path=
|
483
|
+
def @chapter.image(_id)
|
484
|
+
item = Book::ImageIndex::Item.new('123 あ_;', 1)
|
485
|
+
item.instance_eval { @path = './images/chap1-123 あ_;.png' }
|
490
486
|
item
|
491
487
|
end
|
492
488
|
|
493
489
|
actual = compile_block("//image[123 あ_;][sample photo]{\n//}\n")
|
494
|
-
assert_equal %Q
|
490
|
+
assert_equal %Q(<div id="id_123-_E3_81_82___3B" class="image">\n<img src="images/chap1-123 あ_;.png" alt="sample photo" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n), actual
|
495
491
|
end
|
496
492
|
|
497
493
|
def test_indepimage
|
498
|
-
def @chapter.image(
|
499
|
-
item = Book::ImageIndex::Item.new(
|
500
|
-
item.instance_eval{@path=
|
494
|
+
def @chapter.image(_id)
|
495
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
496
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
501
497
|
item
|
502
498
|
end
|
503
499
|
|
504
500
|
actual = compile_block("//indepimage[sampleimg][sample photo]\n")
|
505
|
-
assert_equal %Q
|
501
|
+
assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" />\n<p class="caption">\n図: sample photo\n</p>\n</div>\n), actual
|
506
502
|
end
|
507
503
|
|
508
504
|
def test_indepimage_without_caption
|
509
|
-
def @chapter.image(
|
510
|
-
item = Book::ImageIndex::Item.new(
|
511
|
-
item.instance_eval{@path=
|
505
|
+
def @chapter.image(_id)
|
506
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
507
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
512
508
|
item
|
513
509
|
end
|
514
510
|
|
515
511
|
actual = compile_block("//indepimage[sampleimg]\n")
|
516
|
-
assert_equal %Q
|
512
|
+
assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="" />\n</div>\n), actual
|
517
513
|
end
|
518
514
|
|
519
515
|
def test_indepimage_with_metric
|
520
|
-
def @chapter.image(
|
521
|
-
item = Book::ImageIndex::Item.new(
|
522
|
-
item.instance_eval{@path=
|
516
|
+
def @chapter.image(_id)
|
517
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
518
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
523
519
|
item
|
524
520
|
end
|
525
521
|
|
526
522
|
actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
|
527
|
-
assert_equal %Q
|
523
|
+
assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per" />\n<p class="caption">\n図: sample photo\n</p>\n</div>\n), actual
|
528
524
|
end
|
529
525
|
|
530
526
|
def test_indepimage_with_metric2
|
531
|
-
def @chapter.image(
|
532
|
-
item = Book::ImageIndex::Item.new(
|
533
|
-
item.instance_eval{@path=
|
527
|
+
def @chapter.image(_id)
|
528
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
529
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
534
530
|
item
|
535
531
|
end
|
536
532
|
|
537
|
-
actual = compile_block(
|
538
|
-
assert_equal %Q
|
533
|
+
actual = compile_block(%Q(//indepimage[sampleimg][sample photo][scale=1.2, html::class="sample",latex::ignore=params]\n))
|
534
|
+
assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" class="width-120per sample" />\n<p class="caption">\n図: sample photo\n</p>\n</div>\n), actual
|
539
535
|
end
|
540
536
|
|
541
537
|
def test_indepimage_without_caption_but_with_metric
|
542
|
-
def @chapter.image(
|
543
|
-
item = Book::ImageIndex::Item.new(
|
544
|
-
item.instance_eval{@path=
|
538
|
+
def @chapter.image(_id)
|
539
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1)
|
540
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
545
541
|
item
|
546
542
|
end
|
547
543
|
|
548
544
|
actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n")
|
549
|
-
assert_equal %Q
|
545
|
+
assert_equal %Q(<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="" class="width-120per" />\n</div>\n), actual
|
550
546
|
end
|
551
547
|
|
552
548
|
def test_dlist
|
553
549
|
actual = compile_block(": foo\n foo.\n bar.\n")
|
554
|
-
assert_equal %Q
|
550
|
+
assert_equal %Q(<dl>\n<dt>foo</dt>\n<dd>foo.bar.</dd>\n</dl>\n), actual
|
555
551
|
end
|
556
552
|
|
557
553
|
def test_dlist_with_bracket
|
558
554
|
actual = compile_block(": foo[bar]\n foo.\n bar.\n")
|
559
|
-
assert_equal %Q
|
555
|
+
assert_equal %Q(<dl>\n<dt>foo[bar]</dt>\n<dd>foo.bar.</dd>\n</dl>\n), actual
|
560
556
|
end
|
561
557
|
|
562
558
|
def test_dlist_with_comment
|
563
559
|
source = ": title\n body\n\#@ comment\n\#@ comment\n: title2\n body2\n"
|
564
560
|
actual = compile_block(source)
|
565
|
-
assert_equal %Q
|
561
|
+
assert_equal %Q(<dl>\n<dt>title</dt>\n<dd>body</dd>\n<dt>title2</dt>\n<dd>body2</dd>\n</dl>\n), actual
|
566
562
|
end
|
567
563
|
|
568
564
|
def test_dlist_beforeulol
|
569
565
|
actual = compile_block(" : foo\n foo.\n\npara\n\n : foo\n foo.\n\n 1. bar\n\n : foo\n foo.\n\n * bar\n")
|
570
|
-
assert_equal %Q
|
566
|
+
assert_equal %Q(<dl>\n<dt>foo</dt>\n<dd>foo.</dd>\n</dl>\n<p>para</p>\n<dl>\n<dt>foo</dt>\n<dd>foo.</dd>\n</dl>\n<ol>\n<li>bar</li>\n</ol>\n<dl>\n<dt>foo</dt>\n<dd>foo.</dd>\n</dl>\n<ul>\n<li>bar</li>\n</ul>\n), actual
|
571
567
|
end
|
572
568
|
|
573
569
|
def test_list
|
574
|
-
def @chapter.list(
|
575
|
-
Book::ListIndex::Item.new(
|
570
|
+
def @chapter.list(_id)
|
571
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
576
572
|
end
|
577
573
|
actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
|
578
|
-
assert_equal %Q
|
574
|
+
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
|
579
575
|
end
|
580
576
|
|
581
577
|
def test_inline_list
|
582
|
-
def @chapter.list(
|
583
|
-
Book::ListIndex::Item.new(
|
578
|
+
def @chapter.list(_id)
|
579
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
584
580
|
end
|
585
581
|
actual = compile_block("@<list>{sampletest}\n")
|
586
|
-
assert_equal %Q
|
582
|
+
assert_equal %Q(<p><span class="listref">リスト1.1</span></p>\n), actual
|
587
583
|
end
|
588
584
|
|
589
585
|
def test_inline_list_href
|
590
586
|
book = ReVIEW::Book::Base.load
|
591
|
-
book.config[
|
592
|
-
book.catalog = ReVIEW::Catalog.new(
|
587
|
+
book.config['chapterlink'] = true
|
588
|
+
book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
|
593
589
|
io1 = StringIO.new("//list[sampletest]{\nfoo\n//}\n")
|
594
590
|
io2 = StringIO.new("= BAR\n")
|
595
591
|
chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
|
@@ -598,22 +594,22 @@ EOS
|
|
598
594
|
builder = ReVIEW::HTMLBuilder.new
|
599
595
|
comp = ReVIEW::Compiler.new(builder)
|
600
596
|
builder.bind(comp, chap2, nil)
|
601
|
-
actual = builder.inline_list(
|
602
|
-
assert_equal %Q
|
597
|
+
actual = builder.inline_list('ch1|sampletest')
|
598
|
+
assert_equal %Q(<span class="listref"><a href="./ch1.html#sampletest">リスト1.1</a></span>), actual
|
603
599
|
end
|
604
600
|
|
605
601
|
def test_list_pygments
|
606
|
-
def @chapter.list(
|
607
|
-
Book::ListIndex::Item.new(
|
602
|
+
def @chapter.list(_id)
|
603
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
608
604
|
end
|
609
605
|
begin
|
610
606
|
require 'pygments'
|
611
607
|
rescue LoadError
|
612
|
-
$stderr.puts
|
608
|
+
$stderr.puts 'skip test_list_pygments_lang (cannot find pygments.rb)'
|
613
609
|
return true
|
614
610
|
end
|
615
|
-
@book.config[
|
616
|
-
@book.config[
|
611
|
+
@book.config['highlight'] = {}
|
612
|
+
@book.config['highlight']['html'] = 'pygments'
|
617
613
|
actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
|
618
614
|
|
619
615
|
expected = <<-EOS
|
@@ -630,47 +626,51 @@ test<i>2</i>
|
|
630
626
|
end
|
631
627
|
|
632
628
|
def test_list_pygments_lang
|
633
|
-
def @chapter.list(
|
634
|
-
Book::ListIndex::Item.new(
|
629
|
+
def @chapter.list(_id)
|
630
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
635
631
|
end
|
636
632
|
begin
|
637
633
|
require 'pygments'
|
638
634
|
rescue LoadError
|
639
|
-
$stderr.puts
|
635
|
+
$stderr.puts 'skip test_list_pygments_lang (cannot find pygments.rb)'
|
640
636
|
return true
|
641
637
|
end
|
642
|
-
@book.config[
|
643
|
-
@book.config[
|
638
|
+
@book.config['highlight'] = {}
|
639
|
+
@book.config['highlight']['html'] = 'pygments'
|
644
640
|
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")
|
645
641
|
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
642
|
+
expected = <<-EOS
|
643
|
+
<div id="samplelist" class="caption-code">
|
644
|
+
<p class="caption">リスト1.1: this is <b>test</b><&>_</p>
|
645
|
+
<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>)
|
646
|
+
(<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>)}
|
647
|
+
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #008000">true</span>
|
648
|
+
<span style="color: #008000; font-weight: bold">end</span>
|
649
|
+
</pre>
|
650
|
+
</div>
|
651
|
+
EOS
|
652
|
+
|
653
|
+
assert_equal expected, actual
|
654
654
|
end
|
655
655
|
|
656
656
|
def test_list_pygments_nulllang
|
657
|
-
def @chapter.list(
|
658
|
-
Book::ListIndex::Item.new(
|
657
|
+
def @chapter.list(_id)
|
658
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
659
659
|
end
|
660
660
|
begin
|
661
661
|
require 'pygments'
|
662
662
|
rescue LoadError
|
663
|
-
$stderr.puts
|
663
|
+
$stderr.puts 'skip test_list_pygments_nulllang (cannot find pygments.rb)'
|
664
664
|
return true
|
665
665
|
end
|
666
|
-
@book.config[
|
667
|
-
@book.config[
|
666
|
+
@book.config['highlight'] = {}
|
667
|
+
@book.config['highlight']['html'] = 'pygments'
|
668
668
|
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")
|
669
669
|
|
670
670
|
expected = <<-EOS
|
671
|
-
<div id="samplelist" class
|
672
|
-
<p class
|
673
|
-
<pre class
|
671
|
+
<div id="samplelist" class="caption-code">
|
672
|
+
<p class="caption">リスト1.1: this is <b>test</b><&>_</p>
|
673
|
+
<pre class="list highlight">def foo(a1, a2=:test)
|
674
674
|
(1..3).times{|i| a.include?(:foo)}
|
675
675
|
return true
|
676
676
|
end
|
@@ -684,43 +684,44 @@ end
|
|
684
684
|
begin
|
685
685
|
require 'rouge'
|
686
686
|
rescue LoadError
|
687
|
-
$stderr.puts
|
687
|
+
$stderr.puts 'skip test_list_rouge (cannot find Rouge)'
|
688
688
|
return true
|
689
689
|
end
|
690
|
-
def @chapter.list(
|
691
|
-
Book::ListIndex::Item.new(
|
690
|
+
def @chapter.list(_id)
|
691
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
692
692
|
end
|
693
|
-
@book.config[
|
694
|
-
@book.config[
|
693
|
+
@book.config['highlight'] = {}
|
694
|
+
@book.config['highlight']['html'] = 'rouge'
|
695
695
|
actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
|
696
696
|
|
697
|
-
assert_equal %Q
|
697
|
+
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
|
698
698
|
end
|
699
699
|
|
700
700
|
def test_list_rouge_lang
|
701
701
|
begin
|
702
702
|
require 'rouge'
|
703
703
|
rescue LoadError
|
704
|
-
$stderr.puts
|
704
|
+
$stderr.puts 'skip test_list_rouge_lang (cannot find Rouge)'
|
705
705
|
return true
|
706
706
|
end
|
707
|
-
def @chapter.list(
|
708
|
-
Book::ListIndex::Item.new(
|
707
|
+
def @chapter.list(_id)
|
708
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
709
709
|
end
|
710
|
-
@book.config[
|
711
|
-
@book.config[
|
710
|
+
@book.config['highlight'] = {}
|
711
|
+
@book.config['highlight']['html'] = 'rouge'
|
712
712
|
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")
|
713
713
|
|
714
|
-
expected =
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
"</pre>\n" +
|
722
|
-
"</div>\n"
|
714
|
+
expected = <<-EOS
|
715
|
+
<div id="samplelist" class="caption-code">
|
716
|
+
<p class="caption">リスト1.1: this is <b>test</b><&>_</p>
|
717
|
+
<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>
|
718
|
+
<span class="p">(</span><span class="mi">1</span><span class="o">..</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>
|
719
|
+
<span class="k">return</span> <span class="kp">true</span>
|
720
|
+
<span class="k">end</span>
|
723
721
|
|
722
|
+
</pre>
|
723
|
+
</div>
|
724
|
+
EOS
|
724
725
|
assert_equal expected, actual
|
725
726
|
end
|
726
727
|
|
@@ -728,33 +729,33 @@ end
|
|
728
729
|
begin
|
729
730
|
require 'rouge'
|
730
731
|
rescue LoadError
|
731
|
-
$stderr.puts
|
732
|
+
$stderr.puts 'skip test_list_rouge_nulllang (cannot find Rouge)'
|
732
733
|
return true
|
733
734
|
end
|
734
|
-
def @chapter.list(
|
735
|
-
Book::ListIndex::Item.new(
|
735
|
+
def @chapter.list(_id)
|
736
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
736
737
|
end
|
737
|
-
@book.config[
|
738
|
-
@book.config[
|
738
|
+
@book.config['highlight'] = {}
|
739
|
+
@book.config['highlight']['html'] = 'rouge'
|
739
740
|
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")
|
740
741
|
|
741
|
-
assert_equal
|
742
|
+
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">def foo(a1, a2=:test)\n (1..3).times{|i| a.include?(:foo)}\n return true\nend\n\n</pre>\n</div>\n), actual
|
742
743
|
end
|
743
744
|
|
744
745
|
def test_list_ext
|
745
|
-
def @chapter.list(
|
746
|
-
Book::ListIndex::Item.new(
|
746
|
+
def @chapter.list(_id)
|
747
|
+
Book::ListIndex::Item.new('samplelist.rb', 1)
|
747
748
|
end
|
748
749
|
actual = compile_block("//list[samplelist.rb][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
|
749
|
-
assert_equal %Q
|
750
|
+
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
|
750
751
|
end
|
751
752
|
|
752
753
|
def test_listnum
|
753
|
-
def @chapter.list(
|
754
|
-
Book::ListIndex::Item.new(
|
754
|
+
def @chapter.list(_id)
|
755
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
755
756
|
end
|
756
757
|
|
757
|
-
@book.config[
|
758
|
+
@book.config['highlight'] = false
|
758
759
|
actual = compile_block(<<-EOS)
|
759
760
|
//listnum[samplelist][this is @<b>{test}<&>_][ruby]{
|
760
761
|
def foo(a1, a2=:test)
|
@@ -764,7 +765,7 @@ end
|
|
764
765
|
//}
|
765
766
|
EOS
|
766
767
|
|
767
|
-
expected
|
768
|
+
expected = <<-EOS
|
768
769
|
<div id="samplelist" class="code">
|
769
770
|
<p class="caption">リスト1.1: this is <b>test</b><&>_</p>
|
770
771
|
<pre class="list language-ruby"> 1: def foo(a1, a2=:test)
|
@@ -779,11 +780,11 @@ EOS
|
|
779
780
|
end
|
780
781
|
|
781
782
|
def test_listnum_linenum
|
782
|
-
def @chapter.list(
|
783
|
-
Book::ListIndex::Item.new(
|
783
|
+
def @chapter.list(_id)
|
784
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
784
785
|
end
|
785
786
|
|
786
|
-
@book.config[
|
787
|
+
@book.config['highlight'] = false
|
787
788
|
actual = compile_block(<<-EOS)
|
788
789
|
//firstlinenum[100]
|
789
790
|
//listnum[samplelist][this is @<b>{test}<&>_][ruby]{
|
@@ -794,7 +795,7 @@ end
|
|
794
795
|
//}
|
795
796
|
EOS
|
796
797
|
|
797
|
-
expected
|
798
|
+
expected = <<-EOS
|
798
799
|
<div id="samplelist" class="code">
|
799
800
|
<p class="caption">リスト1.1: this is <b>test</b><&>_</p>
|
800
801
|
<pre class="list language-ruby">100: def foo(a1, a2=:test)
|
@@ -809,17 +810,17 @@ EOS
|
|
809
810
|
end
|
810
811
|
|
811
812
|
def test_listnum_pygments_lang
|
812
|
-
def @chapter.list(
|
813
|
-
Book::ListIndex::Item.new(
|
813
|
+
def @chapter.list(_id)
|
814
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
814
815
|
end
|
815
816
|
begin
|
816
817
|
require 'pygments'
|
817
818
|
rescue LoadError
|
818
|
-
$stderr.puts
|
819
|
+
$stderr.puts 'skip test_listnum_pygments_lang (cannot find pygments.rb)'
|
819
820
|
return true
|
820
821
|
end
|
821
|
-
@book.config[
|
822
|
-
@book.config[
|
822
|
+
@book.config['highlight'] = {}
|
823
|
+
@book.config['highlight']['html'] = 'pygments'
|
823
824
|
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")
|
824
825
|
|
825
826
|
expected = <<-EOS
|
@@ -836,46 +837,46 @@ EOS
|
|
836
837
|
end
|
837
838
|
|
838
839
|
def test_listnum_pygments_lang_linenum
|
839
|
-
def @chapter.list(
|
840
|
-
Book::ListIndex::Item.new(
|
840
|
+
def @chapter.list(_id)
|
841
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
841
842
|
end
|
842
843
|
begin
|
843
844
|
require 'pygments'
|
844
845
|
rescue LoadError
|
845
|
-
$stderr.puts
|
846
|
+
$stderr.puts 'skip test_listnum_pygments_lang (cannot find pygments.rb)'
|
846
847
|
return true
|
847
848
|
end
|
848
|
-
@book.config[
|
849
|
-
@book.config[
|
849
|
+
@book.config['highlight'] = {}
|
850
|
+
@book.config['highlight']['html'] = 'pygments'
|
850
851
|
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")
|
851
852
|
|
852
|
-
expected = <<-
|
853
|
-
<div id
|
854
|
-
<p class
|
855
|
-
<div class
|
856
|
-
<span style
|
857
|
-
<span style
|
858
|
-
<span style
|
853
|
+
expected = <<-EOS
|
854
|
+
<div id="samplelist" class="code">
|
855
|
+
<p class="caption">リスト1.1: this is <b>test</b><&>_</p>
|
856
|
+
<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>)
|
857
|
+
<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>)}
|
858
|
+
<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>
|
859
|
+
<span style="background-color: #f0f0f0; padding: 0 5px 0 5px">103 </span><span style="color: #008000; font-weight: bold">end</span>
|
859
860
|
</pre></div>
|
860
861
|
</div>
|
861
|
-
|
862
|
+
EOS
|
862
863
|
|
863
864
|
assert_equal expected, actual
|
864
865
|
end
|
865
866
|
|
866
867
|
def test_listnum_pygments_lang_without_lang
|
867
|
-
def @chapter.list(
|
868
|
-
Book::ListIndex::Item.new(
|
868
|
+
def @chapter.list(_id)
|
869
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
869
870
|
end
|
870
871
|
begin
|
871
872
|
require 'pygments'
|
872
873
|
rescue LoadError
|
873
|
-
$stderr.puts
|
874
|
+
$stderr.puts 'skip test_listnum_pygments_lang (cannot find pygments.rb)'
|
874
875
|
return true
|
875
876
|
end
|
876
|
-
@book.config[
|
877
|
-
@book.config[
|
878
|
-
@book.config[
|
877
|
+
@book.config['highlight'] = {}
|
878
|
+
@book.config['highlight']['html'] = 'pygments'
|
879
|
+
@book.config['highlight']['lang'] = 'ruby'
|
879
880
|
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")
|
880
881
|
|
881
882
|
expected = <<-EOS
|
@@ -895,31 +896,48 @@ EOB
|
|
895
896
|
begin
|
896
897
|
require 'rouge'
|
897
898
|
rescue LoadError
|
898
|
-
$stderr.puts
|
899
|
+
$stderr.puts 'skip test_listnum_rouge_lang (cannot find Rouge)'
|
899
900
|
return true
|
900
901
|
end
|
901
|
-
def @chapter.list(
|
902
|
-
Book::ListIndex::Item.new(
|
902
|
+
def @chapter.list(_id)
|
903
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
903
904
|
end
|
904
|
-
@book.config[
|
905
|
-
@book.config[
|
905
|
+
@book.config['highlight'] = {}
|
906
|
+
@book.config['highlight']['html'] = 'rouge'
|
906
907
|
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")
|
907
908
|
|
908
|
-
|
909
|
+
expected = <<-EOS
|
910
|
+
<div id="samplelist" class="code">
|
911
|
+
<p class="caption">リスト1.1: this is <b>test</b><&>_</p>
|
912
|
+
<table class="highlight rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
|
913
|
+
2
|
914
|
+
3
|
915
|
+
4
|
916
|
+
5
|
917
|
+
</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>
|
918
|
+
<span class="p">(</span><span class="mi">1</span><span class="o">..</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>
|
919
|
+
<span class="k">return</span> <span class="kp">true</span>
|
920
|
+
<span class="k">end</span>
|
921
|
+
|
922
|
+
</pre></td></tr></tbody></table>
|
923
|
+
</div>
|
924
|
+
EOS
|
925
|
+
|
926
|
+
assert_equal expected, actual
|
909
927
|
end
|
910
928
|
|
911
929
|
def test_listnum_rouge_lang_linenum
|
912
930
|
begin
|
913
931
|
require 'rouge'
|
914
932
|
rescue LoadError
|
915
|
-
$stderr.puts
|
933
|
+
$stderr.puts 'skip test_listnum_rouge_lang_linenum (cannot find Rouge)'
|
916
934
|
return true
|
917
935
|
end
|
918
|
-
def @chapter.list(
|
919
|
-
Book::ListIndex::Item.new(
|
936
|
+
def @chapter.list(_id)
|
937
|
+
Book::ListIndex::Item.new('samplelist', 1)
|
920
938
|
end
|
921
|
-
@book.config[
|
922
|
-
@book.config[
|
939
|
+
@book.config['highlight'] = {}
|
940
|
+
@book.config['highlight']['html'] = 'rouge'
|
923
941
|
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")
|
924
942
|
|
925
943
|
expected = <<-EOB
|
@@ -944,18 +962,18 @@ EOB
|
|
944
962
|
|
945
963
|
def test_emlist
|
946
964
|
actual = compile_block("//emlist{\nlineA\nlineB\n//}\n")
|
947
|
-
assert_equal %Q
|
965
|
+
assert_equal %Q(<div class="emlist-code">\n<pre class="emlist">lineA\nlineB\n</pre>\n</div>\n), actual
|
948
966
|
end
|
949
967
|
|
950
968
|
def test_emlist_pygments_lang
|
951
969
|
begin
|
952
970
|
require 'pygments'
|
953
971
|
rescue LoadError
|
954
|
-
$stderr.puts
|
972
|
+
$stderr.puts 'skip test_emlist_pygments_lang (cannot find pygments.rb)'
|
955
973
|
return true
|
956
974
|
end
|
957
|
-
@book.config[
|
958
|
-
@book.config[
|
975
|
+
@book.config['highlight'] = {}
|
976
|
+
@book.config['highlight']['html'] = 'pygments'
|
959
977
|
actual = compile_block("//emlist[][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
|
960
978
|
expected = <<-EOS
|
961
979
|
<div class="emlist-code">
|
@@ -968,18 +986,18 @@ EOB
|
|
968
986
|
|
969
987
|
def test_emlist_caption
|
970
988
|
actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n")
|
971
|
-
assert_equal %Q
|
989
|
+
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
|
972
990
|
end
|
973
991
|
|
974
992
|
def test_emlist_with_tab
|
975
993
|
actual = compile_block("//emlist{\n\tlineA\n\t\tlineB\n\tlineC\n//}\n")
|
976
|
-
assert_equal %Q
|
994
|
+
assert_equal %Q(<div class="emlist-code">\n<pre class="emlist"> lineA\n lineB\n lineC\n</pre>\n</div>\n), actual
|
977
995
|
end
|
978
996
|
|
979
997
|
def test_emlistnum
|
980
|
-
@book.config[
|
998
|
+
@book.config['highlight'] = false
|
981
999
|
actual = compile_block("//emlistnum{\nlineA\nlineB\n//}\n")
|
982
|
-
expected
|
1000
|
+
expected = <<-EOS
|
983
1001
|
<div class="emlistnum-code">
|
984
1002
|
<pre class="emlist"> 1: lineA
|
985
1003
|
2: lineB
|
@@ -990,9 +1008,9 @@ EOS
|
|
990
1008
|
end
|
991
1009
|
|
992
1010
|
def test_emlistnum_lang
|
993
|
-
@book.config[
|
1011
|
+
@book.config['highlight'] = false
|
994
1012
|
actual = compile_block("//emlistnum[cap][text]{\nlineA\nlineB\n//}\n")
|
995
|
-
expected
|
1013
|
+
expected = <<-EOS
|
996
1014
|
<div class="emlistnum-code">
|
997
1015
|
<p class="caption">cap</p>
|
998
1016
|
<pre class="emlist language-text"> 1: lineA
|
@@ -1004,9 +1022,9 @@ EOS
|
|
1004
1022
|
end
|
1005
1023
|
|
1006
1024
|
def test_emlistnum_lang_linenum
|
1007
|
-
@book.config[
|
1025
|
+
@book.config['highlight'] = false
|
1008
1026
|
actual = compile_block("//firstlinenum[1000]\n//emlistnum[cap][text]{\nlineA\nlineB\n//}\n")
|
1009
|
-
expected
|
1027
|
+
expected = <<-EOS
|
1010
1028
|
<div class="emlistnum-code">
|
1011
1029
|
<p class="caption">cap</p>
|
1012
1030
|
<pre class="emlist language-text">1000: lineA
|
@@ -1018,14 +1036,14 @@ EOS
|
|
1018
1036
|
end
|
1019
1037
|
|
1020
1038
|
def test_emlist_with_4tab
|
1021
|
-
@config[
|
1039
|
+
@config['tabwidth'] = 4
|
1022
1040
|
actual = compile_block("//emlist{\n\tlineA\n\t\tlineB\n\tlineC\n//}\n")
|
1023
|
-
assert_equal %Q
|
1041
|
+
assert_equal %Q(<div class="emlist-code">\n<pre class="emlist"> lineA\n lineB\n lineC\n</pre>\n</div>\n), actual
|
1024
1042
|
end
|
1025
1043
|
|
1026
1044
|
def test_cmd
|
1027
1045
|
actual = compile_block("//cmd{\nlineA\nlineB\n//}\n")
|
1028
|
-
assert_equal %Q
|
1046
|
+
assert_equal %Q(<div class="cmd-code">\n<pre class="cmd">lineA\nlineB\n</pre>\n</div>\n), actual
|
1029
1047
|
end
|
1030
1048
|
|
1031
1049
|
def test_cmd_pygments
|
@@ -1034,67 +1052,67 @@ EOS
|
|
1034
1052
|
rescue LoadError
|
1035
1053
|
return true
|
1036
1054
|
end
|
1037
|
-
@book.config[
|
1038
|
-
@book.config[
|
1055
|
+
@book.config['highlight'] = {}
|
1056
|
+
@book.config['highlight']['html'] = 'pygments'
|
1039
1057
|
actual = compile_block("//cmd{\nlineA\nlineB\n//}\n")
|
1040
|
-
assert_equal
|
1058
|
+
assert_equal %Q(<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
|
1041
1059
|
end
|
1042
1060
|
|
1043
1061
|
def test_cmd_caption
|
1044
1062
|
actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n")
|
1045
|
-
assert_equal %Q
|
1063
|
+
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
|
1046
1064
|
end
|
1047
1065
|
|
1048
1066
|
def test_bib
|
1049
|
-
def @chapter.bibpaper(
|
1050
|
-
Book::BibpaperIndex::Item.new(
|
1067
|
+
def @chapter.bibpaper(_id)
|
1068
|
+
Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
|
1051
1069
|
end
|
1052
1070
|
|
1053
|
-
assert_equal %Q
|
1071
|
+
assert_equal %Q(<a href="bib.html#bib-samplebib">[1]</a>), compile_inline('@<bib>{samplebib}')
|
1054
1072
|
end
|
1055
1073
|
|
1056
1074
|
def test_bib_noramlized
|
1057
|
-
def @chapter.bibpaper(
|
1058
|
-
Book::BibpaperIndex::Item.new(
|
1075
|
+
def @chapter.bibpaper(_id)
|
1076
|
+
Book::BibpaperIndex::Item.new('sampleb=ib', 1, 'sample bib')
|
1059
1077
|
end
|
1060
1078
|
|
1061
|
-
assert_equal %Q
|
1079
|
+
assert_equal %Q(<a href="bib.html#bib-id_sample_3Dbib">[1]</a>), compile_inline('@<bib>{sample=bib}')
|
1062
1080
|
end
|
1063
1081
|
|
1064
1082
|
def test_bib_htmlext
|
1065
|
-
def @chapter.bibpaper(
|
1066
|
-
Book::BibpaperIndex::Item.new(
|
1083
|
+
def @chapter.bibpaper(_id)
|
1084
|
+
Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
|
1067
1085
|
end
|
1068
1086
|
|
1069
|
-
@config[
|
1070
|
-
assert_equal %Q
|
1087
|
+
@config['htmlext'] = 'xhtml'
|
1088
|
+
assert_equal %Q(<a href="bib.xhtml#bib-samplebib">[1]</a>), compile_inline('@<bib>{samplebib}')
|
1071
1089
|
end
|
1072
1090
|
|
1073
1091
|
def test_bibpaper
|
1074
|
-
def @chapter.bibpaper(
|
1075
|
-
Book::BibpaperIndex::Item.new(
|
1092
|
+
def @chapter.bibpaper(_id)
|
1093
|
+
Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
|
1076
1094
|
end
|
1077
1095
|
|
1078
1096
|
actual = compile_block("//bibpaper[samplebib][sample bib @<b>{bold}]{\na\nb\n//}\n")
|
1079
|
-
assert_equal %Q
|
1097
|
+
assert_equal %Q(<div class="bibpaper">\n<a id="bib-samplebib">[1]</a> sample bib <b>bold</b>\n<p>ab</p></div>\n), actual
|
1080
1098
|
end
|
1081
1099
|
|
1082
1100
|
def test_bibpaper_normalized
|
1083
|
-
def @chapter.bibpaper(
|
1084
|
-
Book::BibpaperIndex::Item.new(
|
1101
|
+
def @chapter.bibpaper(_id)
|
1102
|
+
Book::BibpaperIndex::Item.new('sample=bib', 1, 'sample bib')
|
1085
1103
|
end
|
1086
1104
|
|
1087
1105
|
actual = compile_block("//bibpaper[sample=bib][sample bib @<b>{bold}]{\na\nb\n//}\n")
|
1088
|
-
assert_equal %Q
|
1106
|
+
assert_equal %Q(<div class="bibpaper">\n<a id="bib-id_sample_3Dbib">[1]</a> sample bib <b>bold</b>\n<p>ab</p></div>\n), actual
|
1089
1107
|
end
|
1090
1108
|
|
1091
1109
|
def test_bibpaper_with_anchor
|
1092
|
-
def @chapter.bibpaper(
|
1093
|
-
Book::BibpaperIndex::Item.new(
|
1110
|
+
def @chapter.bibpaper(_id)
|
1111
|
+
Book::BibpaperIndex::Item.new('samplebib', 1, 'sample bib')
|
1094
1112
|
end
|
1095
1113
|
|
1096
1114
|
actual = compile_block("//bibpaper[samplebib][sample bib @<href>{http://example.jp}]{\na\nb\n//}\n")
|
1097
|
-
assert_equal %Q
|
1115
|
+
assert_equal %Q(<div class="bibpaper">\n<a id="bib-samplebib">[1]</a> sample bib <a href="http://example.jp" class="link">http://example.jp</a>\n<p>ab</p></div>\n), actual
|
1098
1116
|
end
|
1099
1117
|
|
1100
1118
|
def column_helper(review)
|
@@ -1102,7 +1120,7 @@ EOS
|
|
1102
1120
|
end
|
1103
1121
|
|
1104
1122
|
def test_column_1
|
1105
|
-
review
|
1123
|
+
review = <<-EOS
|
1106
1124
|
===[column] prev column
|
1107
1125
|
|
1108
1126
|
inside prev column
|
@@ -1113,7 +1131,7 @@ inside column
|
|
1113
1131
|
|
1114
1132
|
===[/column]
|
1115
1133
|
EOS
|
1116
|
-
expected
|
1134
|
+
expected = <<-EOS
|
1117
1135
|
<div class="column">
|
1118
1136
|
|
1119
1137
|
<h3><a id="column-1"></a>prev column</h3>
|
@@ -1129,14 +1147,14 @@ EOS
|
|
1129
1147
|
end
|
1130
1148
|
|
1131
1149
|
def test_column_2
|
1132
|
-
review
|
1150
|
+
review = <<-EOS
|
1133
1151
|
===[column] test
|
1134
1152
|
|
1135
1153
|
inside column
|
1136
1154
|
|
1137
1155
|
=== next level
|
1138
1156
|
EOS
|
1139
|
-
expected
|
1157
|
+
expected = <<-EOS
|
1140
1158
|
<div class="column">
|
1141
1159
|
|
1142
1160
|
<h3><a id="column-1"></a>test</h3>
|
@@ -1150,20 +1168,20 @@ EOS
|
|
1150
1168
|
end
|
1151
1169
|
|
1152
1170
|
def test_column_3
|
1153
|
-
review
|
1171
|
+
review = <<-EOS
|
1154
1172
|
===[column] test
|
1155
1173
|
|
1156
1174
|
inside column
|
1157
1175
|
|
1158
1176
|
===[/column_dummy]
|
1159
1177
|
EOS
|
1160
|
-
assert_raise(ReVIEW::
|
1178
|
+
assert_raise(ReVIEW::ApplicationError) do
|
1161
1179
|
column_helper(review)
|
1162
1180
|
end
|
1163
1181
|
end
|
1164
1182
|
|
1165
1183
|
def test_column_ref
|
1166
|
-
review
|
1184
|
+
review = <<-EOS
|
1167
1185
|
===[column]{foo} test
|
1168
1186
|
|
1169
1187
|
inside column
|
@@ -1172,7 +1190,7 @@ inside column
|
|
1172
1190
|
|
1173
1191
|
this is @<column>{foo}.
|
1174
1192
|
EOS
|
1175
|
-
expected
|
1193
|
+
expected = <<-EOS
|
1176
1194
|
<div class="column">
|
1177
1195
|
|
1178
1196
|
<h3 id="foo"><a id="column-1"></a>test</h3>
|
@@ -1188,17 +1206,17 @@ EOS
|
|
1188
1206
|
|
1189
1207
|
def test_column_in_aother_chapter_ref
|
1190
1208
|
def @chapter.column_index
|
1191
|
-
items = [Book::ColumnIndex::Item.new(
|
1209
|
+
items = [Book::ColumnIndex::Item.new('chap1|column', 1, 'column_cap')]
|
1192
1210
|
Book::ColumnIndex.new(items)
|
1193
1211
|
end
|
1194
1212
|
|
1195
|
-
actual = compile_inline(
|
1196
|
-
expected =
|
1213
|
+
actual = compile_inline('test @<column>{chap1|column} test2')
|
1214
|
+
expected = 'test コラム「column_cap」 test2'
|
1197
1215
|
assert_equal expected, actual
|
1198
1216
|
end
|
1199
1217
|
|
1200
1218
|
def test_ul
|
1201
|
-
src
|
1219
|
+
src = <<-EOS
|
1202
1220
|
* AAA
|
1203
1221
|
* BBB
|
1204
1222
|
EOS
|
@@ -1208,7 +1226,7 @@ EOS
|
|
1208
1226
|
end
|
1209
1227
|
|
1210
1228
|
def test_ul_cont
|
1211
|
-
src
|
1229
|
+
src = <<-EOS
|
1212
1230
|
* AAA
|
1213
1231
|
-AA
|
1214
1232
|
* BBB
|
@@ -1220,12 +1238,12 @@ EOS
|
|
1220
1238
|
end
|
1221
1239
|
|
1222
1240
|
def test_ul_nest1
|
1223
|
-
src
|
1241
|
+
src = <<-EOS
|
1224
1242
|
* AAA
|
1225
1243
|
** AA
|
1226
1244
|
EOS
|
1227
1245
|
|
1228
|
-
expected
|
1246
|
+
expected = <<-EOS
|
1229
1247
|
<ul>
|
1230
1248
|
<li>AAA<ul>
|
1231
1249
|
<li>AA</li>
|
@@ -1238,14 +1256,14 @@ EOS
|
|
1238
1256
|
end
|
1239
1257
|
|
1240
1258
|
def test_ul_nest2
|
1241
|
-
src
|
1259
|
+
src = <<-EOS
|
1242
1260
|
* AAA
|
1243
1261
|
** AA
|
1244
1262
|
* BBB
|
1245
1263
|
** BB
|
1246
1264
|
EOS
|
1247
1265
|
|
1248
|
-
expected
|
1266
|
+
expected = <<-EOS
|
1249
1267
|
<ul>
|
1250
1268
|
<li>AAA<ul>
|
1251
1269
|
<li>AA</li>
|
@@ -1262,14 +1280,14 @@ EOS
|
|
1262
1280
|
end
|
1263
1281
|
|
1264
1282
|
def test_ul_nest3
|
1265
|
-
src
|
1283
|
+
src = <<-EOS
|
1266
1284
|
** AAA
|
1267
1285
|
* AA
|
1268
1286
|
* BBB
|
1269
1287
|
** BB
|
1270
1288
|
EOS
|
1271
1289
|
|
1272
|
-
expected
|
1290
|
+
expected = <<-EOS
|
1273
1291
|
<ul>
|
1274
1292
|
<li><ul>
|
1275
1293
|
<li>AAA</li>
|
@@ -1287,7 +1305,7 @@ EOS
|
|
1287
1305
|
end
|
1288
1306
|
|
1289
1307
|
def test_ul_nest4
|
1290
|
-
src
|
1308
|
+
src = <<-EOS
|
1291
1309
|
* A
|
1292
1310
|
** AA
|
1293
1311
|
*** AAA
|
@@ -1295,7 +1313,7 @@ EOS
|
|
1295
1313
|
** BB
|
1296
1314
|
EOS
|
1297
1315
|
|
1298
|
-
expected
|
1316
|
+
expected = <<-EOS
|
1299
1317
|
<ul>
|
1300
1318
|
<li>A<ul>
|
1301
1319
|
<li>AA<ul>
|
@@ -1315,7 +1333,7 @@ EOS
|
|
1315
1333
|
end
|
1316
1334
|
|
1317
1335
|
def test_ul_nest5
|
1318
|
-
src
|
1336
|
+
src = <<-EOS
|
1319
1337
|
* A
|
1320
1338
|
** AA
|
1321
1339
|
**** AAAA
|
@@ -1323,7 +1341,7 @@ EOS
|
|
1323
1341
|
** BB
|
1324
1342
|
EOS
|
1325
1343
|
|
1326
|
-
expected
|
1344
|
+
expected = <<-EOS
|
1327
1345
|
<ul>
|
1328
1346
|
<li>A<ul>
|
1329
1347
|
<li>AA<ul>
|
@@ -1346,12 +1364,12 @@ EOS
|
|
1346
1364
|
end
|
1347
1365
|
|
1348
1366
|
def test_ol
|
1349
|
-
src
|
1367
|
+
src = <<-EOS
|
1350
1368
|
3. AAA
|
1351
1369
|
3. BBB
|
1352
1370
|
EOS
|
1353
1371
|
|
1354
|
-
expected
|
1372
|
+
expected = <<-EOS
|
1355
1373
|
<ol>
|
1356
1374
|
<li>AAA</li>
|
1357
1375
|
<li>BBB</li>
|
@@ -1362,43 +1380,43 @@ EOS
|
|
1362
1380
|
end
|
1363
1381
|
|
1364
1382
|
def test_inline_raw0
|
1365
|
-
assert_equal
|
1383
|
+
assert_equal 'normal', compile_inline('@<raw>{normal}')
|
1366
1384
|
end
|
1367
1385
|
|
1368
1386
|
def test_inline_raw1
|
1369
|
-
assert_equal
|
1387
|
+
assert_equal 'body', compile_inline('@<raw>{|html|body}')
|
1370
1388
|
end
|
1371
1389
|
|
1372
1390
|
def test_inline_raw2
|
1373
|
-
assert_equal
|
1391
|
+
assert_equal 'body', compile_inline('@<raw>{|html, latex|body}')
|
1374
1392
|
end
|
1375
1393
|
|
1376
1394
|
def test_inline_raw3
|
1377
|
-
assert_equal
|
1395
|
+
assert_equal '', compile_inline('@<raw>{|idgxml, latex|body}')
|
1378
1396
|
end
|
1379
1397
|
|
1380
1398
|
def test_inline_raw4
|
1381
|
-
assert_equal
|
1399
|
+
assert_equal '|html body', compile_inline('@<raw>{|html body}')
|
1382
1400
|
end
|
1383
1401
|
|
1384
1402
|
def test_inline_raw5
|
1385
|
-
assert_equal "nor\nmal", compile_inline(
|
1403
|
+
assert_equal "nor\nmal", compile_inline('@<raw>{|html|nor\\nmal}')
|
1386
1404
|
end
|
1387
1405
|
|
1388
1406
|
def test_inline_embed0
|
1389
|
-
assert_equal
|
1407
|
+
assert_equal 'normal', compile_inline('@<embed>{normal}')
|
1390
1408
|
end
|
1391
1409
|
|
1392
1410
|
def test_inline_embed1
|
1393
|
-
assert_equal
|
1411
|
+
assert_equal 'body', compile_inline('@<embed>{|html|body}')
|
1394
1412
|
end
|
1395
1413
|
|
1396
1414
|
def test_inline_embed3
|
1397
|
-
assert_equal
|
1415
|
+
assert_equal '', compile_inline('@<embed>{|idgxml, latex|body}')
|
1398
1416
|
end
|
1399
1417
|
|
1400
1418
|
def test_inline_embed5
|
1401
|
-
assert_equal 'nor\\nmal', compile_inline(
|
1419
|
+
assert_equal 'nor\\nmal', compile_inline('@<embed>{|html|nor\\nmal}')
|
1402
1420
|
end
|
1403
1421
|
|
1404
1422
|
def test_inline_embed_math1
|
@@ -1443,82 +1461,82 @@ EOS
|
|
1443
1461
|
end
|
1444
1462
|
|
1445
1463
|
def test_block_raw0
|
1446
|
-
actual = compile_block(
|
1447
|
-
expected = %Q(
|
1464
|
+
actual = compile_block(%Q(//raw[<>!"\\n& ]\n))
|
1465
|
+
expected = %Q(<>!"\n& )
|
1448
1466
|
assert_equal expected, actual
|
1449
1467
|
end
|
1450
1468
|
|
1451
1469
|
def test_block_raw1
|
1452
|
-
actual = compile_block(
|
1453
|
-
expected = %Q(
|
1470
|
+
actual = compile_block(%Q(//raw[|html|<>!"\\n& ]\n))
|
1471
|
+
expected = %Q(<>!"\n& )
|
1454
1472
|
assert_equal expected, actual
|
1455
1473
|
end
|
1456
1474
|
|
1457
1475
|
def test_block_raw2
|
1458
|
-
actual = compile_block(
|
1459
|
-
expected = %Q(
|
1476
|
+
actual = compile_block(%Q(//raw[|html, latex|<>!"\\n& ]\n))
|
1477
|
+
expected = %Q(<>!"\n& )
|
1460
1478
|
assert_equal expected, actual
|
1461
1479
|
end
|
1462
1480
|
|
1463
1481
|
def test_block_raw3
|
1464
|
-
actual = compile_block(
|
1482
|
+
actual = compile_block(%Q(//raw[|latex, idgxml|<>!"\\n& ]\n))
|
1465
1483
|
expected = ''
|
1466
1484
|
assert_equal expected, actual
|
1467
1485
|
end
|
1468
1486
|
|
1469
1487
|
def test_block_raw4
|
1470
|
-
actual = compile_block(
|
1471
|
-
expected = %Q(|html
|
1488
|
+
actual = compile_block(%Q(//raw[|html <>!"\\n& ]\n))
|
1489
|
+
expected = %Q(|html <>!"\n& )
|
1472
1490
|
assert_equal expected, actual
|
1473
1491
|
end
|
1474
1492
|
|
1475
1493
|
def test_embed0
|
1476
1494
|
lines = '//embed{' + "\n" +
|
1477
|
-
|
1495
|
+
%Q( <>!"\\\\n& ) + "\n" +
|
1478
1496
|
'//}' + "\n"
|
1479
1497
|
actual = compile_block(lines)
|
1480
|
-
expected =
|
1498
|
+
expected = %Q( <>!"\\\\n& ) + "\n"
|
1481
1499
|
assert_equal expected, actual
|
1482
1500
|
end
|
1483
1501
|
|
1484
1502
|
def test_embed1
|
1485
1503
|
actual = compile_block("//embed[|html|]{\n" +
|
1486
|
-
"
|
1504
|
+
%Q(<>!"\\\\n& \n) +
|
1487
1505
|
"//}\n")
|
1488
|
-
expected = %Q(
|
1506
|
+
expected = %Q(<>!"\\\\n& \n)
|
1489
1507
|
assert_equal expected, actual
|
1490
1508
|
end
|
1491
1509
|
|
1492
1510
|
def test_embed2
|
1493
1511
|
actual = compile_block("//embed[html, latex]{\n" +
|
1494
|
-
"
|
1512
|
+
%Q(<>!"\\\\n& \n) +
|
1495
1513
|
"//}\n")
|
1496
|
-
expected = %Q(
|
1514
|
+
expected = %Q(<>!"\\\\n& \n)
|
1497
1515
|
assert_equal expected, actual
|
1498
1516
|
end
|
1499
1517
|
|
1500
1518
|
def test_embed2a
|
1501
1519
|
actual = compile_block("//embed[|html, latex|]{\n" +
|
1502
|
-
"
|
1520
|
+
%Q(<>!"\\\\n& \n) +
|
1503
1521
|
"//}\n")
|
1504
|
-
expected = %Q(
|
1522
|
+
expected = %Q(<>!"\\\\n& \n)
|
1505
1523
|
assert_equal expected, actual
|
1506
1524
|
end
|
1507
1525
|
|
1508
1526
|
def test_embed2b
|
1509
1527
|
actual = compile_block("//embed[html, latex]{\n" +
|
1510
1528
|
'#@# comments are not ignored in //embed block' + "\n" +
|
1511
|
-
"
|
1529
|
+
%Q(<>!"\\\\n& \n) +
|
1512
1530
|
"//}\n")
|
1513
|
-
expected = '#@# comments are not ignored in //embed block' + "\n" + %Q(
|
1531
|
+
expected = '#@# comments are not ignored in //embed block' + "\n" + %Q(<>!"\\\\n& \n)
|
1514
1532
|
assert_equal expected, actual
|
1515
1533
|
end
|
1516
1534
|
|
1517
1535
|
def test_inline_fn
|
1518
1536
|
fn = Book::FootnoteIndex.parse(['//footnote[foo][bar\\a\\$buz]'])
|
1519
|
-
@chapter.instance_eval{@footnote_index=fn}
|
1537
|
+
@chapter.instance_eval { @footnote_index = fn }
|
1520
1538
|
actual = compile_block("//footnote[foo][bar\\a\\$buz]\n")
|
1521
|
-
expected
|
1539
|
+
expected = <<-'EOS'
|
1522
1540
|
<div class="footnote" epub:type="footnote" id="fn-foo"><p class="footnote">[*1] bar\a\$buz</p></div>
|
1523
1541
|
EOS
|
1524
1542
|
assert_equal expected, actual
|
@@ -1526,9 +1544,9 @@ EOS
|
|
1526
1544
|
|
1527
1545
|
def test_inline_fn_with_tricky_id
|
1528
1546
|
fn = Book::FootnoteIndex.parse(['//footnote[123 あ_;][bar\\a\\$buz]'])
|
1529
|
-
@chapter.instance_eval{@footnote_index=fn}
|
1547
|
+
@chapter.instance_eval { @footnote_index = fn }
|
1530
1548
|
actual = compile_block("//footnote[123 あ_;][bar\\a\\$buz]\n")
|
1531
|
-
expected
|
1549
|
+
expected = <<-'EOS'
|
1532
1550
|
<div class="footnote" epub:type="footnote" id="fn-id_123-_E3_81_82___3B"><p class="footnote">[*1] bar\a\$buz</p></div>
|
1533
1551
|
EOS
|
1534
1552
|
assert_equal expected, actual
|
@@ -1536,7 +1554,7 @@ EOS
|
|
1536
1554
|
|
1537
1555
|
def test_inline_hd
|
1538
1556
|
book = ReVIEW::Book::Base.load
|
1539
|
-
book.catalog = ReVIEW::Catalog.new(
|
1557
|
+
book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
|
1540
1558
|
io1 = StringIO.new("= test1\n\nfoo\n\n== test1-1\n\nbar\n\n== test1-2\n\nbar\n\n")
|
1541
1559
|
io2 = StringIO.new("= test2\n\nfoo\n\n== test2-1\n\nbar\n\n== test2-2\n\nbar\n\n")
|
1542
1560
|
chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
|
@@ -1545,55 +1563,66 @@ EOS
|
|
1545
1563
|
builder = ReVIEW::HTMLBuilder.new
|
1546
1564
|
comp = ReVIEW::Compiler.new(builder)
|
1547
1565
|
builder.bind(comp, chap2, nil)
|
1548
|
-
hd = builder.inline_hd(
|
1549
|
-
assert_equal
|
1566
|
+
hd = builder.inline_hd('ch1|test1-1')
|
1567
|
+
assert_equal '「1.1 test1-1」', hd
|
1550
1568
|
end
|
1551
1569
|
|
1552
1570
|
def test_inline_hd_for_part
|
1553
1571
|
book = ReVIEW::Book::Base.load
|
1554
|
-
book.catalog = ReVIEW::Catalog.new(
|
1572
|
+
book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re ch2.re])
|
1555
1573
|
io1 = StringIO.new("= test1\n\nfoo\n\n== test1-1\n\nbar\n\n== test1-2\n\nbar\n\n")
|
1556
1574
|
io2 = StringIO.new("= test2\n\nfoo\n\n== test2-1\n\nbar\n\n== test2-2\n\nbar\n\n")
|
1557
1575
|
io_p1 = StringIO.new("= part1\n\nfoo\n\n== part1-1\n\nbar\n\n== part1-2\n\nbar\n\n")
|
1558
1576
|
chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1)
|
1559
1577
|
chap2 = ReVIEW::Book::Chapter.new(book, 2, 'ch2', 'ch2.re', io2)
|
1560
|
-
book.parts = [ReVIEW::Book::Part.new(self, 1, [chap1, chap2],
|
1578
|
+
book.parts = [ReVIEW::Book::Part.new(self, 1, [chap1, chap2], 'part1.re', io_p1)]
|
1561
1579
|
builder = ReVIEW::HTMLBuilder.new
|
1562
1580
|
comp = ReVIEW::Compiler.new(builder)
|
1563
1581
|
builder.bind(comp, chap2, nil)
|
1564
|
-
hd = builder.inline_hd(
|
1565
|
-
assert_equal
|
1582
|
+
hd = builder.inline_hd('part1|part1-1')
|
1583
|
+
assert_equal '「1.1 part1-1」', hd
|
1584
|
+
end
|
1585
|
+
|
1586
|
+
def test_inline_hd_with_block
|
1587
|
+
io1 = StringIO.new("= test1\n=={foo} foo\n//emlist{\n======\nbar\n======\n}\n//}\n=={bar} bar")
|
1588
|
+
chap1 = Book::Chapter.new(@book, 1, '-', nil, io1)
|
1589
|
+
location = Location.new(nil, nil)
|
1590
|
+
@builder.bind(@compiler, chap1, location)
|
1591
|
+
hd = @builder.inline_hd('foo')
|
1592
|
+
assert_equal '「1.1 foo」', hd
|
1593
|
+
hd = @builder.inline_hd('bar')
|
1594
|
+
assert_equal '「1.2 bar」', hd
|
1566
1595
|
end
|
1567
1596
|
|
1568
1597
|
def test_table
|
1569
1598
|
actual = compile_block("//table{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
|
1570
|
-
assert_equal %Q
|
1599
|
+
assert_equal %Q(<div class="table">\n<table>\n<tr><th>aaa</th><th>bbb</th></tr>\n<tr><td>ccc</td><td>ddd<>&</td></tr>\n</table>\n</div>\n),
|
1571
1600
|
actual
|
1572
1601
|
end
|
1573
1602
|
|
1574
1603
|
def test_inline_table
|
1575
|
-
def @chapter.table(
|
1576
|
-
Book::TableIndex::Item.new(
|
1604
|
+
def @chapter.table(_id)
|
1605
|
+
Book::TableIndex::Item.new('sampletable', 1)
|
1577
1606
|
end
|
1578
1607
|
actual = compile_block("@<table>{sampletest}\n")
|
1579
|
-
assert_equal %Q
|
1608
|
+
assert_equal %Q(<p><span class="tableref">表1.1</span></p>\n), actual
|
1580
1609
|
end
|
1581
1610
|
|
1582
1611
|
def test_emtable
|
1583
1612
|
actual = compile_block("//emtable[foo]{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n//emtable{\naaa\tbbb\n------------\nccc\tddd<>&\n//}\n")
|
1584
|
-
assert_equal %Q
|
1613
|
+
assert_equal %Q(<div class="table">\n<p class="caption">foo</p>\n<table>\n<tr><th>aaa</th><th>bbb</th></tr>\n<tr><td>ccc</td><td>ddd<>&</td></tr>\n</table>\n</div>\n<div class="table">\n<table>\n<tr><th>aaa</th><th>bbb</th></tr>\n<tr><td>ccc</td><td>ddd<>&</td></tr>\n</table>\n</div>\n),
|
1585
1614
|
actual
|
1586
1615
|
end
|
1587
1616
|
|
1588
1617
|
def test_imgtable
|
1589
|
-
def @chapter.image(
|
1590
|
-
item = Book::ImageIndex::Item.new(
|
1591
|
-
item.instance_eval{@path=
|
1618
|
+
def @chapter.image(_id)
|
1619
|
+
item = Book::ImageIndex::Item.new('sampleimg', 1, 'sample img')
|
1620
|
+
item.instance_eval { @path = './images/chap1-sampleimg.png' }
|
1592
1621
|
item
|
1593
1622
|
end
|
1594
1623
|
|
1595
1624
|
actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")
|
1596
|
-
expected = %Q
|
1625
|
+
expected = %Q(<div id="sampleimg" class="imgtable image">\n<p class="caption">表1.1: test for imgtable</p>\n<img src="images/chap1-sampleimg.png" alt="test for imgtable" />\n</div>\n)
|
1597
1626
|
assert_equal expected, actual
|
1598
1627
|
end
|
1599
1628
|
|
@@ -1632,24 +1661,29 @@ EOS
|
|
1632
1661
|
end
|
1633
1662
|
|
1634
1663
|
def test_comment
|
1635
|
-
actual = compile_block(
|
1636
|
-
assert_equal
|
1664
|
+
actual = compile_block('//comment[コメント]')
|
1665
|
+
assert_equal '', actual
|
1637
1666
|
end
|
1638
1667
|
|
1639
1668
|
def test_comment_for_draft
|
1640
|
-
@config[
|
1641
|
-
actual = compile_block(
|
1642
|
-
assert_equal %Q
|
1669
|
+
@config['draft'] = true
|
1670
|
+
actual = compile_block('//comment[コメント]')
|
1671
|
+
assert_equal %Q(<div class="draft-comment">コメント</div>\n), actual
|
1643
1672
|
end
|
1644
1673
|
|
1645
1674
|
def test_inline_comment
|
1646
|
-
actual = compile_inline(
|
1647
|
-
assert_equal
|
1675
|
+
actual = compile_inline('test @<comment>{コメント} test2')
|
1676
|
+
assert_equal 'test test2', actual
|
1648
1677
|
end
|
1649
1678
|
|
1650
1679
|
def test_inline_comment_for_draft
|
1651
|
-
@config[
|
1652
|
-
actual = compile_inline(
|
1653
|
-
assert_equal %Q
|
1680
|
+
@config['draft'] = true
|
1681
|
+
actual = compile_inline('test @<comment>{コメント} test2')
|
1682
|
+
assert_equal %Q(test <span class="draft-comment">コメント</span> test2), actual
|
1683
|
+
end
|
1684
|
+
|
1685
|
+
def test_inline_fence
|
1686
|
+
actual = compile_inline('test @<code>|@<code>{$サンプル$}|')
|
1687
|
+
assert_equal 'test <code class="inline-code tt">@<code>{$サンプル$}</code>', actual
|
1654
1688
|
end
|
1655
1689
|
end
|