review 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +42 -0
  3. data/README.rdoc +31 -0
  4. data/bin/review-catalog-converter +129 -0
  5. data/bin/review-check +4 -2
  6. data/bin/review-compile +7 -7
  7. data/bin/review-index +4 -3
  8. data/bin/review-init +3 -1
  9. data/bin/review-pdfmaker +2 -258
  10. data/bin/review-vol +2 -2
  11. data/doc/catalog.rdoc +18 -3
  12. data/doc/format.rdoc +2 -3
  13. data/doc/quickstart.rdoc +1 -1
  14. data/lib/epubmaker/epubv2.rb +16 -8
  15. data/lib/epubmaker/epubv3.rb +44 -12
  16. data/lib/epubmaker/producer.rb +4 -2
  17. data/lib/review/book.rb +0 -1
  18. data/lib/review/book/base.rb +72 -35
  19. data/lib/review/book/chapter.rb +8 -12
  20. data/lib/review/book/compilable.rb +8 -8
  21. data/lib/review/book/image_finder.rb +7 -0
  22. data/lib/review/book/index.rb +23 -5
  23. data/lib/review/book/volume.rb +2 -1
  24. data/lib/review/builder.rb +10 -5
  25. data/lib/review/catalog.rb +5 -0
  26. data/lib/review/compiler.rb +1 -1
  27. data/lib/review/configure.rb +12 -0
  28. data/lib/review/epubmaker.rb +13 -7
  29. data/lib/review/htmlbuilder.rb +26 -12
  30. data/lib/review/i18n.rb +2 -2
  31. data/lib/review/i18n.yml +21 -0
  32. data/lib/review/idgxmlbuilder.rb +11 -9
  33. data/lib/review/latexbuilder.rb +3 -2
  34. data/lib/review/{review.tex.erb → layout.tex.erb} +9 -1
  35. data/lib/review/markdownbuilder.rb +126 -4
  36. data/lib/review/pdfmaker.rb +291 -0
  37. data/lib/review/tocparser.rb +6 -5
  38. data/lib/review/tocprinter.rb +5 -2
  39. data/lib/review/version.rb +1 -1
  40. data/review.gemspec +1 -1
  41. data/rubocop-todo.yml +13 -0
  42. data/test/test_book.rb +95 -133
  43. data/test/test_book_chapter.rb +16 -21
  44. data/test/test_builder.rb +12 -7
  45. data/test/test_catalog.rb +15 -3
  46. data/test/test_catalog_converter_cmd.rb +73 -0
  47. data/test/test_epubmaker.rb +5 -5
  48. data/test/test_helper.rb +32 -21
  49. data/test/test_htmlbuilder.rb +219 -192
  50. data/test/test_i18n.rb +46 -19
  51. data/test/test_idgxmlbuilder.rb +177 -182
  52. data/test/test_inaobuilder.rb +1 -2
  53. data/test/test_index.rb +20 -0
  54. data/test/test_latexbuilder.rb +175 -183
  55. data/test/test_markdownbuilder.rb +41 -5
  56. data/test/test_pdfmaker.rb +130 -0
  57. data/test/test_topbuilder.rb +92 -96
  58. metadata +10 -6
  59. data/lib/review/book/parameters.rb +0 -98
  60. data/test/test_book_parameter.rb +0 -42
@@ -16,7 +16,8 @@ class BuidlerTest < Test::Unit::TestCase
16
16
 
17
17
  def setup
18
18
  @b = Builder.new
19
- @b.bind(MockCompiler.new, nil, nil)
19
+ chap = ReVIEW::Book::Chapter.new(nil, nil, '-', nil)
20
+ @b.bind(MockCompiler.new, chap, nil)
20
21
  end
21
22
 
22
23
  def test_initialize
@@ -25,8 +26,9 @@ class BuidlerTest < Test::Unit::TestCase
25
26
 
26
27
  def test_bind
27
28
  b = Builder.new
29
+ chap = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.load_default, nil, '-', nil)
28
30
  assert_nothing_raised do
29
- b.bind(nil, nil, nil)
31
+ b.bind(nil, chap, nil)
30
32
  end
31
33
  end
32
34
 
@@ -37,7 +39,8 @@ class BuidlerTest < Test::Unit::TestCase
37
39
  end
38
40
 
39
41
  b = Builder.new
40
- b.bind(nil, nil, nil)
42
+ chapter = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.load_default, nil, '-', nil)
43
+ b.bind(nil, chapter, nil)
41
44
  assert_equal '', b.result
42
45
  end
43
46
 
@@ -79,8 +82,9 @@ class BuidlerTest < Test::Unit::TestCase
79
82
  [:puts, "#{utf8_str}\n", "#{expect}\n"],
80
83
  ].each do |m, instr, expstr|
81
84
  b = Builder.new
82
- b.bind(nil, nil, nil)
83
- ReVIEW.book.config = params
85
+ chapter = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.load_default, nil, '-', nil)
86
+ b.bind(nil, chapter, nil)
87
+ chapter.book.config = params
84
88
  b.__send__(m, instr)
85
89
  if "".respond_to?(:encode)
86
90
  assert_equal expstr.encode("UTF-8"), b.result
@@ -128,9 +132,10 @@ class BuidlerTest < Test::Unit::TestCase
128
132
  end
129
133
 
130
134
  def test_convert_outencoding
131
- ReVIEW.book.config = {'outencoding' => "EUC"}
135
+ book = ReVIEW::Book::Base.new(nil)
136
+ book.config = {'outencoding' => "EUC"}
132
137
  b = Builder.new
133
- ret = b.convert_outencoding("a", ReVIEW.book.config["outencoding"])
138
+ ret = b.convert_outencoding("a", book.config["outencoding"])
134
139
  assert_equal "a", ret
135
140
  end
136
141
 
@@ -28,13 +28,13 @@ ch02.re
28
28
  assert_equal("", sut.chaps)
29
29
  end
30
30
 
31
- def test_postdef
31
+ def test_appendix
32
32
  sut = Catalog.new(yaml)
33
33
  exp =<<-EOS
34
34
  post01.re
35
35
  post02.re
36
36
  EOS
37
- assert_equal(exp.chomp, sut.postdef)
37
+ assert_equal(exp.chomp, sut.appendix)
38
38
  end
39
39
 
40
40
  def test_chaps_with_parts
@@ -72,6 +72,15 @@ part2.re
72
72
  sut.parts_with_chaps)
73
73
  end
74
74
 
75
+ def test_postdef
76
+ sut = Catalog.new(yaml)
77
+ exp =<<-EOS
78
+ back01.re
79
+ back02.re
80
+ EOS
81
+ assert_equal(exp.chomp, sut.postdef)
82
+ end
83
+
75
84
  private
76
85
  def yaml
77
86
  StringIO.new <<-EOS
@@ -84,10 +93,13 @@ CHAPS:
84
93
  - ch01.re
85
94
  - ch02.re
86
95
 
87
- POSTDEF:
96
+ APPENDIX:
88
97
  - post01.re
89
98
  - post02.re
90
99
 
100
+ POSTDEF:
101
+ - back01.re
102
+ - back02.re
91
103
  EOS
92
104
  end
93
105
 
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+ require 'tmpdir'
3
+ require 'fileutils'
4
+ require 'yaml'
5
+ require 'rbconfig'
6
+
7
+ load File.expand_path('../bin/review-catalog-converter', File.dirname(__FILE__))
8
+
9
+ class CatalogConverterCmdTest < Test::Unit::TestCase
10
+ def test_parse_chaps
11
+ input = <<-EOS
12
+ ch01.re
13
+ ch02.re
14
+ ch03.re
15
+ EOS
16
+
17
+ expected = <<-EOS
18
+ CHAPS:
19
+ - ch01.re
20
+ - ch02.re
21
+ - ch03.re
22
+
23
+ EOS
24
+ assert_equal expected, parse_chaps(input)
25
+ end
26
+
27
+ def test_parse_chaps_empty
28
+ assert_equal "CHAPS:\n\n", parse_chaps("")
29
+ assert_equal "CHAPS:\n\n", parse_chaps(nil)
30
+ end
31
+
32
+ def test_parse_parts
33
+ parts = <<-EOS
34
+ pt01
35
+ pt02
36
+ pt03
37
+ EOS
38
+
39
+ chaps = <<-EOS
40
+ ch01.re
41
+
42
+ ch02.re
43
+ ch03.re
44
+
45
+ ch04.re
46
+ EOS
47
+
48
+ expected = <<-EOS
49
+ CHAPS:
50
+ - pt01:
51
+ - ch01.re
52
+ - pt02:
53
+ - ch02.re
54
+ - ch03.re
55
+ - pt03:
56
+ - ch04.re
57
+
58
+ EOS
59
+
60
+ assert_equal expected, parse_parts(parts, chaps)
61
+ end
62
+
63
+ def test_parse_parts_chaps_empty
64
+ assert_equal "CHAPS:\n\n", parse_parts("", "")
65
+ assert_equal "CHAPS:\n\n", parse_parts(nil, nil)
66
+ end
67
+
68
+ def test_parse_postdef
69
+ assert_equal "APPENDIX:\n\n", parse_postdef("", true)
70
+ assert_equal "POSTDEF:\n\n", parse_postdef("")
71
+ assert_equal "POSTDEF:\n\n", parse_postdef("", false)
72
+ end
73
+ end
@@ -190,7 +190,7 @@ EOT
190
190
 
191
191
  def stage3
192
192
  # add more items
193
- @producer.contents << Content.new({"file" => "ch01.html", "title" => "CH01", "level" => 1})
193
+ @producer.contents << Content.new({"file" => "ch01.html", "title" => "CH01<>&\"", "level" => 1})
194
194
  @producer.contents << Content.new({"file" => "ch02.html", "title" => "CH02", "level" => 1})
195
195
  @producer.contents << Content.new({"file" => "ch02.html#S1", "title" => "CH02.1", "level" => 2})
196
196
  @producer.contents << Content.new({"file" => "ch02.html#S1.1", "title" => "CH02.1.1", "level" => 3})
@@ -214,7 +214,7 @@ EOT
214
214
  def test_stage3_add_various_items
215
215
  stage3
216
216
  expect = [
217
- Content.new("ch01.html", "ch01-html", "application/xhtml+xml", "CH01", 1),
217
+ Content.new("ch01.html", "ch01-html", "application/xhtml+xml", "CH01<>&\"", 1),
218
218
  Content.new("ch02.html", "ch02-html", "application/xhtml+xml", "CH02", 1),
219
219
  Content.new("ch02.html#S1", "ch02-html#S1","html#s1","CH02.1", 2),
220
220
  Content.new("ch02.html#S1.1", "ch02-html#S1-1", "1", "CH02.1.1", 3),
@@ -306,7 +306,7 @@ EOT
306
306
  </navPoint>
307
307
  <navPoint id="nav-2" playOrder="2">
308
308
  <navLabel>
309
- <text>CH01</text>
309
+ <text>CH01&lt;&gt;&amp;&quot;</text>
310
310
  </navLabel>
311
311
  <content src="ch01.html"/>
312
312
  </navPoint>
@@ -404,7 +404,7 @@ EOT
404
404
  <body>
405
405
  <h1 class="toc-title">Table of Contents</h1>
406
406
 
407
- <ul class="toc-h1"><li><a href="ch01.html">CH01</a></li>
407
+ <ul class="toc-h1"><li><a href="ch01.html">CH01&lt;&gt;&amp;&quot;</a></li>
408
408
  <li><a href="ch02.html">CH02</a>
409
409
  <ul class="toc-h2"><li><a href="ch02.html#S1">CH02.1</a></li>
410
410
  <li><a href="ch02.html#S2">CH02.2</a></li>
@@ -436,7 +436,7 @@ EOT
436
436
  <body>
437
437
  <h1 class="toc-title">Table of Contents</h1>
438
438
  <ul class="toc-h1">
439
- <li><a href="ch01.html">CH01</a></li>
439
+ <li><a href="ch01.html">CH01&lt;&gt;&amp;&quot;</a></li>
440
440
  <li><a href="ch02.html">CH02</a></li>
441
441
  <li><a href="ch02.html#S1">CH02.1</a></li>
442
442
  <li><a href="ch02.html#S2">CH02.2</a></li>
@@ -1,27 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib/')
2
2
  require 'test/unit'
3
3
 
4
- def ul_helper(src, expect)
5
- io = StringIO.new(src)
6
- li = LineInput.new(io)
7
- @compiler.__send__(:compile_ulist, li)
8
- assert_equal expect, @builder.raw_result
9
- end
10
-
11
- def ol_helper(src, expect)
12
- io = StringIO.new(src)
13
- li = LineInput.new(io)
14
- @compiler.__send__(:compile_olist, li)
15
- assert_equal expect, @builder.raw_result
16
- end
17
-
18
- def builder_helper(src, expect, method_sym)
19
- io = StringIO.new(src)
20
- li = LineInput.new(io)
21
- @compiler.__send__(method_sym, li)
22
- assert_equal expect, @builder.raw_result
23
- end
24
-
25
4
  def touch_file(path)
26
5
  File.open(path, "w").close
27
6
  path
@@ -32,3 +11,35 @@ def prepare_samplebook(srcdir)
32
11
  FileUtils.cp_r(Dir.glob(samplebook_dir + "/*"), srcdir)
33
12
  YAML.load(File.open(srcdir + "/config.yml"))
34
13
  end
14
+
15
+ def compile_inline(text)
16
+ @builder.compile_inline(text)
17
+ end
18
+
19
+ def compile_block(text)
20
+ method_name = "compile_block_#{@builder.target_name}"
21
+ if !self.respond_to?(method_name, true)
22
+ method_name = "compile_block_default"
23
+ end
24
+ self.__send__(method_name, text)
25
+ end
26
+
27
+ def compile_block_default(text)
28
+ @chapter.content = text
29
+ @compiler.compile(@chapter)
30
+ end
31
+
32
+ def compile_block_html(text)
33
+ @chapter.content = text
34
+ matched = @compiler.compile(@chapter).match(/<body>\n(.+)<\/body>/m)
35
+ if matched && matched.size > 1
36
+ matched[1]
37
+ else
38
+ ""
39
+ end
40
+ end
41
+
42
+ def compile_block_idgxml(text)
43
+ @chapter.content = text
44
+ @compiler.compile(@chapter).gsub(/.*<doc xmlns:aid="http:\/\/ns.adobe.com\/AdobeInDesign\/4.0\/">/m,"").gsub(/<\/doc>\n/, "")
45
+ end
@@ -18,15 +18,16 @@ class HTMLBuidlerTest < Test::Unit::TestCase
18
18
  "outencoding" => "UTF-8",
19
19
  "stylesheet" => nil, # for HTMLBuilder
20
20
  })
21
- ReVIEW.book.config = @config
21
+ @book = Book::Base.new(".")
22
+ @book.config = @config
22
23
  @compiler = ReVIEW::Compiler.new(@builder)
23
- @chapter = Book::Chapter.new(Book::Base.new(nil), 1, '-', nil, StringIO.new)
24
+ @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
24
25
  location = Location.new(nil, nil)
25
26
  @builder.bind(@compiler, @chapter, location)
26
27
  end
27
28
 
28
29
  def test_xmlns_ops_prefix_epub3
29
- ReVIEW.book.config["epubversion"] = 3
30
+ @book.config["epubversion"] = 3
30
31
  assert_equal "epub", @builder.xmlns_ops_prefix
31
32
  end
32
33
 
@@ -35,184 +36,179 @@ class HTMLBuidlerTest < Test::Unit::TestCase
35
36
  end
36
37
 
37
38
  def test_headline_level1
38
- @builder.headline(1,"test","this is test.")
39
- assert_equal %Q|<h1 id="test"><a id="h1"></a>第1章 this is test.</h1>\n|, @builder.raw_result
39
+ actual = compile_block("={test} this is test.\n")
40
+ assert_equal %Q|<h1 id="test"><a id="h1"></a>第1章 this is test.</h1>\n|, actual
40
41
  end
41
42
 
42
43
  def test_headline_level1_postdef
43
44
  @chapter.instance_eval do
44
- def on_POSTDEF?
45
+ def on_APPENDIX?
45
46
  true
46
47
  end
47
48
  end
48
- @builder.headline(1,"test","this is test.")
49
- assert_equal %Q|<h1 id="test"><a id="h1"></a>付録1 this is test.</h1>\n|, @builder.raw_result
49
+ actual = compile_block("={test} this is test.\n")
50
+ assert_equal %Q|<h1 id="test"><a id="h1"></a>付録1 this is test.</h1>\n|, actual
50
51
  end
51
52
 
52
53
  def test_headline_level2_postdef
53
54
  @chapter.instance_eval do
54
- def on_POSTDEF?
55
+ def on_APPENDIX?
55
56
  true
56
57
  end
57
58
  end
58
- @builder.headline(2,"test","this is test.")
59
- assert_equal %Q|\n<h2 id="test"><a id="h1-1"></a>1.1 this is test.</h2>\n|, @builder.raw_result
59
+ actual = compile_block("=={test} this is test.\n")
60
+ assert_equal %Q|\n<h2 id="test"><a id="h1-1"></a>1.1 this is test.</h2>\n|, actual
60
61
  end
61
62
 
62
63
  def test_headline_level1_postdef_roman
63
64
  @chapter.book.config["appendix_format"] = "roman"
64
65
  @chapter.instance_eval do
65
- def on_POSTDEF?
66
+ def on_APPENDIX?
66
67
  true
67
68
  end
68
69
  end
69
- @builder.headline(1,"test","this is test.")
70
- assert_equal %Q|<h1 id="test"><a id="h1"></a>付録I this is test.</h1>\n|, @builder.raw_result
70
+ actual = compile_block("={test} this is test.\n")
71
+ assert_equal %Q|<h1 id="test"><a id="h1"></a>付録I this is test.</h1>\n|, actual
71
72
  end
72
73
 
73
74
  def test_headline_level2_postdef_roman
74
75
  @chapter.book.config["appendix_format"] = "roman"
75
76
  @chapter.instance_eval do
76
- def on_POSTDEF?
77
+ def on_APPENDIX?
77
78
  true
78
79
  end
79
80
  end
80
- @builder.headline(2,"test","this is test.")
81
- assert_equal %Q|\n<h2 id="test"><a id="h1-1"></a>I.1 this is test.</h2>\n|, @builder.raw_result
81
+ actual = compile_block("=={test} this is test.\n")
82
+ assert_equal %Q|\n<h2 id="test"><a id="h1-1"></a>I.1 this is test.</h2>\n|, actual
82
83
  end
83
84
 
84
85
  def test_headline_level1_postdef_alpha
85
86
  @chapter.book.config["appendix_format"] = "alpha"
86
87
  @chapter.instance_eval do
87
- def on_POSTDEF?
88
+ def on_APPENDIX?
88
89
  true
89
90
  end
90
91
  end
91
- @builder.headline(1,"test","this is test.")
92
- assert_equal %Q|<h1 id="test"><a id="h1"></a>付録A this is test.</h1>\n|, @builder.raw_result
92
+ actual = compile_block("={test} this is test.\n")
93
+ assert_equal %Q|<h1 id="test"><a id="h1"></a>付録A this is test.</h1>\n|, actual
93
94
  end
94
95
 
95
96
  def test_headline_level2_postdef_alpha
96
97
  @chapter.book.config["appendix_format"] = "alpha"
97
98
  @chapter.instance_eval do
98
- def on_POSTDEF?
99
+ def on_APPENDIX?
99
100
  true
100
101
  end
101
102
  end
102
- @builder.headline(2,"test","this is test.")
103
- assert_equal %Q|\n<h2 id="test"><a id="h1-1"></a>A.1 this is test.</h2>\n|, @builder.raw_result
103
+ actual = compile_block("=={test} this is test.\n")
104
+ assert_equal %Q|\n<h2 id="test"><a id="h1-1"></a>A.1 this is test.</h2>\n|, actual
104
105
  end
105
106
 
106
107
  def test_headline_level1_without_secno
107
- ReVIEW.book.config["secnolevel"] = 0
108
- @builder.headline(1,"test","this is test.")
109
- assert_equal %Q|<h1 id="test"><a id="h1"></a>this is test.</h1>\n|, @builder.raw_result
108
+ @book.config["secnolevel"] = 0
109
+ actual = compile_block("={test} this is test.\n")
110
+ assert_equal %Q|<h1 id="test"><a id="h1"></a>this is test.</h1>\n|, actual
110
111
  end
111
112
 
112
113
  def test_headline_level1_with_tricky_id
113
- @builder.headline(1,"123 あ_;","this is test.")
114
- assert_equal %Q|<h1 id="id_123-_E3_81_82___3B"><a id="h1"></a>第1章 this is test.</h1>\n|, @builder.raw_result
114
+ actual = compile_block("={123 あ_;} this is test.\n")
115
+ assert_equal %Q|<h1 id="id_123-_E3_81_82___3B"><a id="h1"></a>第1章 this is test.</h1>\n|, actual
115
116
  end
116
117
 
117
118
  def test_headline_level1_with_inlinetag
118
- @builder.headline(1,"test","this @<b>{is} test.<&\">")
119
- assert_equal %Q|<h1 id="test"><a id="h1"></a>第1章 this <b>is</b> test.&lt;&amp;&quot;&gt;</h1>\n|, @builder.raw_result
119
+ actual = compile_block("={test} this @<b>{is} test.<&\">\n")
120
+ assert_equal %Q|<h1 id="test"><a id="h1"></a>第1章 this <b>is</b> test.&lt;&amp;&quot;&gt;</h1>\n|, actual
120
121
  end
121
122
 
122
123
  def test_headline_level2
123
- @builder.headline(2,"test","this is test.")
124
- assert_equal %Q|\n<h2 id="test"><a id="h1-1"></a>1.1 this is test.</h2>\n|, @builder.raw_result
124
+ actual = compile_block("=={test} this is test.\n")
125
+ assert_equal %Q|\n<h2 id="test"><a id="h1-1"></a>1.1 this is test.</h2>\n|, actual
125
126
  end
126
127
 
127
128
  def test_headline_level3
128
- @builder.headline(3,"test","this is test.")
129
- assert_equal %Q|\n<h3 id="test"><a id="h1-0-1"></a>this is test.</h3>\n|, @builder.raw_result
129
+ actual = compile_block("==={test} this is test.\n")
130
+ assert_equal %Q|\n<h3 id="test"><a id="h1-0-1"></a>this is test.</h3>\n|, actual
130
131
  end
131
132
 
132
133
  def test_headline_level3_with_secno
133
- ReVIEW.book.config["secnolevel"] = 3
134
- @builder.headline(3,"test","this is test.")
135
- assert_equal %Q|\n<h3 id="test"><a id="h1-0-1"></a>1.0.1 this is test.</h3>\n|, @builder.raw_result
134
+ @book.config["secnolevel"] = 3
135
+ actual = compile_block("==={test} this is test.\n")
136
+ assert_equal %Q|\n<h3 id="test"><a id="h1-0-1"></a>1.0.1 this is test.</h3>\n|, actual
136
137
  end
137
138
 
138
139
  def test_label
139
- @builder.label("label_test")
140
- assert_equal %Q|<a id="label_test"></a>\n|, @builder.raw_result
140
+ actual = compile_block("//label[label_test]\n")
141
+ assert_equal %Q|<a id="label_test"></a>\n|, actual
141
142
  end
142
143
 
143
144
  def test_label_with_tricky_id
144
- @builder.label("123 あ_;")
145
- assert_equal %Q|<a id="id_123-_E3_81_82___3B"></a>\n|, @builder.raw_result
145
+ actual = compile_block("//label[123 あ_;]\n")
146
+ assert_equal %Q|<a id="id_123-_E3_81_82___3B"></a>\n|, actual
146
147
  end
147
148
 
148
149
  def test_href
149
- ret = @builder.compile_href("http://github.com", "GitHub")
150
- assert_equal %Q|<a href="http://github.com" class="link">GitHub</a>|, ret
150
+ actual = compile_inline("@<href>{http://github.com,GitHub}")
151
+ assert_equal %Q|<a href="http://github.com" class="link">GitHub</a>|, actual
151
152
  end
152
153
 
153
154
  def test_href_without_label
154
- ret = @builder.compile_href("http://github.com",nil)
155
- assert_equal %Q|<a href="http://github.com" class="link">http://github.com</a>|, ret
155
+ actual = compile_inline("@<href>{http://github.com}")
156
+ assert_equal %Q|<a href="http://github.com" class="link">http://github.com</a>|, actual
156
157
  end
157
158
 
158
159
  def test_inline_href
159
- ret = @builder.inline_href("http://github.com, Git\\,Hub")
160
- assert_equal %Q|<a href="http://github.com" class="link">Git,Hub</a>|, ret
161
- end
162
-
163
- def test_inline_href_without_label
164
- ret = @builder.inline_href("http://github.com")
165
- assert_equal %Q|<a href="http://github.com" class="link">http://github.com</a>|, ret
160
+ actual = compile_inline("@<href>{http://github.com,Git\\,Hub}")
161
+ assert_equal %Q|<a href="http://github.com" class="link">Git,Hub</a>|, actual
166
162
  end
167
163
 
168
164
  def test_inline_raw
169
- ret = @builder.inline_raw("@<tt>{inline}")
170
- assert_equal %Q|@<tt>{inline}|, ret
165
+ actual = compile_inline("@<raw>{@<tt>{inline\\}}")
166
+ assert_equal %Q|@<tt>{inline}|, actual
171
167
  end
172
168
 
173
169
  def test_inline_in_table
174
- ret = @builder.table(["<b>1</b>\t<i>2</i>", "------------", "<b>3</b>\t<i>4</i>&lt;&gt;&amp;"])
175
- 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>&lt;&gt;&amp;</td></tr>\n</table>\n</div>\n|, @builder.raw_result
170
+ actual = compile_block("//table{\n@<b>{1}\t@<i>{2}\n------------\n@<b>{3}\t@<i>{4}<>&\n//}\n")
171
+ 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>&lt;&gt;&amp;</td></tr>\n</table>\n</div>\n|, actual
176
172
  end
177
173
 
178
174
  def test_inline_br
179
- ret = @builder.inline_br("")
180
- assert_equal %Q|<br />|, ret
175
+ actual = compile_inline("@<br>{}")
176
+ assert_equal %Q|<br />|, actual
181
177
  end
182
178
 
183
179
  def test_inline_i
184
- ret = @builder.compile_inline("test @<i>{inline test} test2")
185
- assert_equal %Q|test <i>inline test</i> test2|, ret
180
+ actual = compile_inline("test @<i>{inline test} test2")
181
+ assert_equal %Q|test <i>inline test</i> test2|, actual
186
182
  end
187
183
 
188
184
  def test_inline_i_and_escape
189
- ret = @builder.compile_inline("test @<i>{inline<&;\\ test} test2")
190
- assert_equal %Q|test <i>inline&lt;&amp;;\\ test</i> test2|, ret
185
+ actual = compile_inline("test @<i>{inline<&;\\ test} test2")
186
+ assert_equal %Q|test <i>inline&lt;&amp;;\\ test</i> test2|, actual
191
187
  end
192
188
 
193
189
  def test_inline_b
194
- ret = @builder.compile_inline("test @<b>{inline test} test2")
195
- assert_equal %Q|test <b>inline test</b> test2|, ret
190
+ actual = compile_inline("test @<b>{inline test} test2")
191
+ assert_equal %Q|test <b>inline test</b> test2|, actual
196
192
  end
197
193
 
198
194
  def test_inline_b_and_escape
199
- ret = @builder.compile_inline("test @<b>{inline<&;\\ test} test2")
200
- assert_equal %Q|test <b>inline&lt;&amp;;\\ test</b> test2|, ret
195
+ actual = compile_inline("test @<b>{inline<&;\\ test} test2")
196
+ assert_equal %Q|test <b>inline&lt;&amp;;\\ test</b> test2|, actual
201
197
  end
202
198
 
203
199
  def test_inline_tt
204
- ret = @builder.compile_inline("test @<tt>{inline test} test2")
205
- assert_equal %Q|test <tt>inline test</tt> test2|, ret
200
+ actual = compile_inline("test @<tt>{inline test} test2")
201
+ assert_equal %Q|test <tt>inline test</tt> test2|, actual
206
202
  end
207
203
 
208
204
  def test_inline_tti
209
- ret = @builder.compile_inline("test @<tti>{inline test} test2")
210
- assert_equal %Q|test <tt><i>inline test</i></tt> test2|, ret
205
+ actual = compile_inline("test @<tti>{inline test} test2")
206
+ assert_equal %Q|test <tt><i>inline test</i></tt> test2|, actual
211
207
  end
212
208
 
213
209
  def test_inline_ttb
214
- ret = @builder.compile_inline("test @<ttb>{inline test} test2")
215
- assert_equal %Q|test <tt><b>inline test</b></tt> test2|, ret
210
+ actual = compile_inline("test @<ttb>{inline test} test2")
211
+ assert_equal %Q|test <tt><b>inline test</b></tt> test2|, actual
216
212
  end
217
213
 
218
214
  def test_inline_hd_chap
@@ -222,32 +218,32 @@ class HTMLBuidlerTest < Test::Unit::TestCase
222
218
  end
223
219
 
224
220
  @config["secnolevel"] = 2
225
- ret = @builder.compile_inline("test @<hd>{chap1|test} test2")
226
- assert_equal %Q|test 「te_st」 test2|, ret
221
+ actual = compile_inline("test @<hd>{chap1|test} test2")
222
+ assert_equal %Q|test 「te_st」 test2|, actual
227
223
 
228
224
  @config["secnolevel"] = 3
229
- ret = @builder.compile_inline("test @<hd>{chap1|test} test2")
230
- assert_equal %Q|test 「1.1.1 te_st」 test2|, ret
225
+ actual = compile_inline("test @<hd>{chap1|test} test2")
226
+ assert_equal %Q|test 「1.1.1 te_st」 test2|, actual
231
227
  end
232
228
 
233
229
  def test_inline_uchar
234
- ret = @builder.compile_inline("test @<uchar>{2460} test2")
235
- assert_equal %Q|test &#x2460; test2|, ret
230
+ actual = compile_inline("test @<uchar>{2460} test2")
231
+ assert_equal %Q|test &#x2460; test2|, actual
236
232
  end
237
233
 
238
234
  def test_inline_ruby
239
- ret = @builder.compile_inline("@<ruby>{粗雑,クルード}と思われているなら@<ruby>{繊細,テクニカル}にやり、繊細と思われているなら粗雑にやる。")
240
- assert_equal "<ruby><rb>粗雑</rb><rp>(</rp><rt>クルード</rt><rp>)</rp></ruby>と思われているなら<ruby><rb>繊細</rb><rp>(</rp><rt>テクニカル</rt><rp>)</rp></ruby>にやり、繊細と思われているなら粗雑にやる。", ret
235
+ actual = compile_inline("@<ruby>{粗雑,クルード}と思われているなら@<ruby>{繊細,テクニカル}にやり、繊細と思われているなら粗雑にやる。")
236
+ assert_equal "<ruby><rb>粗雑</rb><rp>(</rp><rt>クルード</rt><rp>)</rp></ruby>と思われているなら<ruby><rb>繊細</rb><rp>(</rp><rt>テクニカル</rt><rp>)</rp></ruby>にやり、繊細と思われているなら粗雑にやる。", actual
241
237
  end
242
238
 
243
239
  def test_inline_ruby_comma
244
- ret = @builder.compile_inline("@<ruby>{foo\\, bar\\, buz,フー・バー・バズ}")
245
- assert_equal "<ruby><rb>foo, bar, buz</rb><rp>(</rp><rt>フー・バー・バズ</rt><rp>)</rp></ruby>", ret
240
+ actual = compile_inline("@<ruby>{foo\\, bar\\, buz,フー・バー・バズ}")
241
+ assert_equal "<ruby><rb>foo, bar, buz</rb><rp>(</rp><rt>フー・バー・バズ</rt><rp>)</rp></ruby>", actual
246
242
  end
247
243
 
248
244
  def test_inline_ref
249
- ret = @builder.compile_inline("@<ref>{外部参照<>&}")
250
- assert_equal %Q|<a target='外部参照&lt;&gt;&amp;'>「●● 外部参照&lt;&gt;&amp;」</a>|, ret
245
+ actual = compile_inline("@<ref>{外部参照<>&}")
246
+ assert_equal %Q|<a target='外部参照&lt;&gt;&amp;'>「●● 外部参照&lt;&gt;&amp;」</a>|, actual
251
247
  end
252
248
 
253
249
  def test_inline_mathml
@@ -258,37 +254,35 @@ class HTMLBuidlerTest < Test::Unit::TestCase
258
254
  return true
259
255
  end
260
256
  @config["mathml"] = true
261
- ret = @builder.compile_inline("@<m>{\\frac{-b \\pm \\sqrt{b^2 - 4ac\\}\\}{2a\\}}")
257
+ actual = compile_inline("@<m>{\\frac{-b \\pm \\sqrt{b^2 - 4ac\\}\\}{2a\\}}")
262
258
  @config["mathml"] = nil
263
- 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'>&#xb1;</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>", ret
259
+ 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'>&#xb1;</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
264
260
  end
265
261
 
266
262
  def test_quote
267
- lines = ["foo", "bar", "","buz"]
268
- @builder.quote(lines)
269
- assert_equal %Q|<blockquote><p>foobar</p>\n<p>buz</p></blockquote>\n|, @builder.raw_result
263
+ actual = compile_block("//quote{\nfoo\nbar\n\nbuz\n//}\n")
264
+ assert_equal %Q|<blockquote><p>foobar</p>\n<p>buz</p></blockquote>\n|, actual
270
265
  end
271
266
 
272
267
  def test_memo
273
- @builder.memo(["test1", "", "test<i>2</i>"], "this is @<b>{test}<&>_")
274
- assert_equal %Q|<div class="memo">\n<p class="caption">this is <b>test</b>&lt;&amp;&gt;_</p>\n<p>test1</p>\n<p>test<i>2</i></p>\n</div>\n|, @builder.raw_result
268
+ actual = compile_block("//memo[this is @<b>{test}<&>_]{\ntest1\n\ntest@<i>{2}\n//}\n")
269
+ assert_equal %Q|<div class="memo">\n<p class="caption">this is <b>test</b>&lt;&amp;&gt;_</p>\n<p>test1</p>\n<p>test<i>2</i></p>\n</div>\n|, actual
275
270
  end
276
271
 
277
272
  def test_noindent
278
273
  @builder.noindent
279
- @builder.paragraph(["foo", "bar"])
280
- @builder.paragraph(["foo2", "bar2"])
281
- assert_equal %Q|<p class="noindent">foobar</p>\n<p>foo2bar2</p>\n|, @builder.raw_result
274
+ actual = compile_block("foo\nbar\n\nfoo2\nbar2\n")
275
+ assert_equal %Q|<p class="noindent">foobar</p>\n<p>foo2bar2</p>\n|, actual
282
276
  end
283
277
 
284
278
  def test_flushright
285
- @builder.flushright(["foo", "bar", "", "buz"])
286
- assert_equal %Q|<p class="flushright">foobar</p>\n<p class="flushright">buz</p>\n|, @builder.raw_result
279
+ actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
280
+ assert_equal %Q|<p class="flushright">foobar</p>\n<p class="flushright">buz</p>\n|, actual
287
281
  end
288
282
 
289
283
  def test_centering
290
- @builder.centering(["foo", "bar", "", "buz"])
291
- assert_equal %Q|<p class="center">foobar</p>\n<p class="center">buz</p>\n|, @builder.raw_result
284
+ actual = compile_block("//centering{\nfoo\nbar\n\nbuz\n//}\n")
285
+ assert_equal %Q|<p class="center">foobar</p>\n<p class="center">buz</p>\n|, actual
292
286
  end
293
287
 
294
288
  def test_image
@@ -298,8 +292,8 @@ class HTMLBuidlerTest < Test::Unit::TestCase
298
292
  item
299
293
  end
300
294
 
301
- @builder.image_image("sampleimg","sample photo",nil)
302
- 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|, @builder.raw_result
295
+ actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
296
+ 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
303
297
  end
304
298
 
305
299
  def test_image_with_metric
@@ -309,8 +303,8 @@ class HTMLBuidlerTest < Test::Unit::TestCase
309
303
  item
310
304
  end
311
305
 
312
- @builder.image_image("sampleimg","sample photo","scale=1.2")
313
- assert_equal %Q|<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" width="120%" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n|, @builder.raw_result
306
+ actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
307
+ assert_equal %Q|<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" width="120%" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n|, actual
314
308
  end
315
309
 
316
310
  def test_image_with_metric2
@@ -319,8 +313,9 @@ class HTMLBuidlerTest < Test::Unit::TestCase
319
313
  item.instance_eval{@path="./images/chap1-sampleimg.png"}
320
314
  item
321
315
  end
322
- @builder.image_image("sampleimg","sample photo","scale=1.2,html::class=sample,latex::ignore=params")
323
- assert_equal %Q|<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" width="120%" class="sample" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n|, @builder.raw_result
316
+
317
+ actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
318
+ assert_equal %Q|<div id="sampleimg" class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" width="120%" class="sample" />\n<p class="caption">\n図1.1: sample photo\n</p>\n</div>\n|, actual
324
319
  end
325
320
 
326
321
  def test_image_with_tricky_id
@@ -330,8 +325,8 @@ class HTMLBuidlerTest < Test::Unit::TestCase
330
325
  item
331
326
  end
332
327
 
333
- @builder.image_image("123 あ_;","sample photo",nil)
334
- 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|, @builder.raw_result
328
+ actual = compile_block("//image[123 あ_;][sample photo]{\n//}\n")
329
+ 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
335
330
  end
336
331
 
337
332
  def test_indepimage
@@ -341,8 +336,8 @@ class HTMLBuidlerTest < Test::Unit::TestCase
341
336
  item
342
337
  end
343
338
 
344
- @builder.indepimage("sampleimg","sample photo",nil)
345
- assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" />\n<p class="caption">\n図: sample photo\n</p>\n</div>\n|, @builder.raw_result
339
+ actual = compile_block("//indepimage[sampleimg][sample photo]\n")
340
+ assert_equal %Q|<div 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
346
341
  end
347
342
 
348
343
  def test_indepimage_without_caption
@@ -352,8 +347,8 @@ class HTMLBuidlerTest < Test::Unit::TestCase
352
347
  item
353
348
  end
354
349
 
355
- @builder.indepimage("sampleimg",nil,nil)
356
- assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="" />\n</div>\n|, @builder.raw_result
350
+ actual = compile_block("//indepimage[sampleimg]\n")
351
+ assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="" />\n</div>\n|, actual
357
352
  end
358
353
 
359
354
  def test_indepimage_with_metric
@@ -363,8 +358,8 @@ class HTMLBuidlerTest < Test::Unit::TestCase
363
358
  item
364
359
  end
365
360
 
366
- @builder.indepimage("sampleimg","sample photo","scale=1.2")
367
- assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" width="120%" />\n<p class="caption">\n図: sample photo\n</p>\n</div>\n|, @builder.raw_result
361
+ actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
362
+ assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" width="120%" />\n<p class="caption">\n図: sample photo\n</p>\n</div>\n|, actual
368
363
  end
369
364
 
370
365
  def test_indepimage_with_metric2
@@ -374,8 +369,8 @@ class HTMLBuidlerTest < Test::Unit::TestCase
374
369
  item
375
370
  end
376
371
 
377
- @builder.indepimage("sampleimg","sample photo","scale=1.2, html::class=\"sample\",latex::ignore=params")
378
- assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" width="120%" class="sample" />\n<p class="caption">\n図: sample photo\n</p>\n</div>\n|, @builder.raw_result
372
+ actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2, html::class=\"sample\",latex::ignore=params]\n")
373
+ assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="sample photo" width="120%" class="sample" />\n<p class="caption">\n図: sample photo\n</p>\n</div>\n|, actual
379
374
  end
380
375
 
381
376
  def test_indepimage_without_caption_but_with_metric
@@ -385,17 +380,26 @@ class HTMLBuidlerTest < Test::Unit::TestCase
385
380
  item
386
381
  end
387
382
 
388
- @builder.indepimage("sampleimg",nil,"scale=1.2")
389
- assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="" width="120%" />\n</div>\n|, @builder.raw_result
383
+ actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n")
384
+ assert_equal %Q|<div class="image">\n<img src="images/chap1-sampleimg.png" alt="" width="120%" />\n</div>\n|, actual
385
+ end
386
+
387
+ def test_dlist
388
+ actual = compile_block(": foo\n foo.\n bar.\n")
389
+ assert_equal %Q|<dl>\n<dt>foo</dt>\n<dd>foo.bar.</dd>\n</dl>\n|, actual
390
+ end
391
+
392
+ def test_dlist_with_bracket
393
+ actual = compile_block(": foo[bar]\n foo.\n bar.\n")
394
+ assert_equal %Q|<dl>\n<dt>foo[bar]</dt>\n<dd>foo.bar.</dd>\n</dl>\n|, actual
390
395
  end
391
396
 
392
397
  def test_list
393
398
  def @chapter.list(id)
394
399
  Book::ListIndex::Item.new("samplelist",1)
395
400
  end
396
- @builder.list(["test1", "test1.5", "", "test<i>2</i>"], "samplelist", "this is @<b>{test}<&>_")
397
-
398
- assert_equal %Q|<div class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n<pre class="list">test1\ntest1.5\n\ntest<i>2</i>\n</pre>\n</div>\n|, @builder.raw_result
401
+ actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
402
+ assert_equal %Q|<div class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n<pre class="list">test1\ntest1.5\n\ntest<i>2</i>\n</pre>\n</div>\n|, actual
399
403
  end
400
404
 
401
405
  def test_list_pygments
@@ -407,41 +411,41 @@ class HTMLBuidlerTest < Test::Unit::TestCase
407
411
  rescue LoadError
408
412
  return true
409
413
  end
410
- ReVIEW.book.config["pygments"] = true
411
- @builder.list(["test1", "test1.5", "", "test<i>2</i>"], "samplelist", "this is @<b>{test}<&>_")
414
+ @book.config["pygments"] = true
415
+ actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\ntest1\ntest1.5\n\ntest@<i>{2}\n//}\n")
412
416
 
413
- assert_equal %Q|<div class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n<pre class="list">test1\ntest1.5\n\ntest<span style="color: #008000; font-weight: bold">&lt;i&gt;</span>2<span style="color: #008000; font-weight: bold">&lt;/i&gt;</span>\n</pre>\n</div>\n|, @builder.raw_result
417
+ assert_equal %Q|<div class="caption-code">\n<p class="caption">リスト1.1: this is <b>test</b>&lt;&amp;&gt;_</p>\n<pre class="list">test1\ntest1.5\n\ntest<span style="color: #008000; font-weight: bold">&lt;i&gt;</span>2<span style="color: #008000; font-weight: bold">&lt;/i&gt;</span>\n</pre>\n</div>\n|, actual
414
418
  end
415
419
 
416
420
  def test_emlist
417
- @builder.emlist(["lineA","lineB"])
418
- assert_equal %Q|<div class="emlist-code">\n<pre class="emlist">lineA\nlineB\n</pre>\n</div>\n|, @builder.raw_result
421
+ actual = compile_block("//emlist{\nlineA\nlineB\n//}\n")
422
+ assert_equal %Q|<div class="emlist-code">\n<pre class="emlist">lineA\nlineB\n</pre>\n</div>\n|, actual
419
423
  end
420
424
 
421
425
  def test_emlist_caption
422
- @builder.emlist(["lineA","lineB"],"cap1")
423
- assert_equal %Q|<div class="emlist-code">\n<p class="caption">cap1</p>\n<pre class="emlist">lineA\nlineB\n</pre>\n</div>\n|, @builder.raw_result
426
+ actual = compile_block("//emlist[cap1]{\nlineA\nlineB\n//}\n")
427
+ 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
424
428
  end
425
429
 
426
430
  def test_emlist_with_tab
427
- @builder.emlist(["\tlineA","\t\tlineB","\tlineC"])
428
- assert_equal %Q|<div class="emlist-code">\n<pre class="emlist"> lineA\n lineB\n lineC\n</pre>\n</div>\n|, @builder.raw_result
431
+ actual = compile_block("//emlist{\n\tlineA\n\t\tlineB\n\tlineC\n//}\n")
432
+ assert_equal %Q|<div class="emlist-code">\n<pre class="emlist"> lineA\n lineB\n lineC\n</pre>\n</div>\n|, actual
429
433
  end
430
434
 
431
435
  def test_emlist_with_4tab
432
- @builder.instance_eval{@tabwidth=4}
433
- @builder.emlist(["\tlineA","\t\tlineB","\tlineC"])
434
- assert_equal %Q|<div class="emlist-code">\n<pre class="emlist"> lineA\n lineB\n lineC\n</pre>\n</div>\n|, @builder.raw_result
436
+ @config["tabwidth"] = 4
437
+ actual = compile_block("//emlist{\n\tlineA\n\t\tlineB\n\tlineC\n//}\n")
438
+ assert_equal %Q|<div class="emlist-code">\n<pre class="emlist"> lineA\n lineB\n lineC\n</pre>\n</div>\n|, actual
435
439
  end
436
440
 
437
441
  def test_cmd
438
- @builder.cmd(["lineA","lineB"])
439
- assert_equal %Q|<div class="cmd-code">\n<pre class="cmd">lineA\nlineB\n</pre>\n</div>\n|, @builder.raw_result
442
+ actual = compile_block("//cmd{\nlineA\nlineB\n//}\n")
443
+ assert_equal %Q|<div class="cmd-code">\n<pre class="cmd">lineA\nlineB\n</pre>\n</div>\n|, actual
440
444
  end
441
445
 
442
446
  def test_cmd_caption
443
- @builder.cmd(["lineA","lineB"], "cap1")
444
- assert_equal %Q|<div class="cmd-code">\n<p class="caption">cap1</p>\n<pre class="cmd">lineA\nlineB\n</pre>\n</div>\n|, @builder.raw_result
447
+ actual = compile_block("//cmd[cap1]{\nlineA\nlineB\n//}\n")
448
+ 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
445
449
  end
446
450
 
447
451
  def test_bib
@@ -449,7 +453,15 @@ class HTMLBuidlerTest < Test::Unit::TestCase
449
453
  Book::BibpaperIndex::Item.new("samplebib",1,"sample bib")
450
454
  end
451
455
 
452
- assert_equal %Q|<a href="./bib.html#bib-samplebib">[1]</a>|, @builder.inline_bib("samplebib")
456
+ assert_equal %Q|<a href="bib.html#bib-samplebib">[1]</a>|, compile_inline("@<bib>{samplebib}")
457
+ end
458
+
459
+ def test_bib_noramlized
460
+ def @chapter.bibpaper(id)
461
+ Book::BibpaperIndex::Item.new("sampleb=ib",1,"sample bib")
462
+ end
463
+
464
+ assert_equal %Q|<a href="bib.html#bib-id_sample_3Dbib">[1]</a>|, compile_inline("@<bib>{sample=bib}")
453
465
  end
454
466
 
455
467
  def test_bibpaper
@@ -457,8 +469,17 @@ class HTMLBuidlerTest < Test::Unit::TestCase
457
469
  Book::BibpaperIndex::Item.new("samplebib",1,"sample bib")
458
470
  end
459
471
 
460
- @builder.bibpaper(["a", "b"], "samplebib", "sample bib @<b>{bold}")
461
- assert_equal %Q|<div class=\"bibpaper\">\n<a id=\"bib-samplebib\">[1]</a> sample bib <b>bold</b>\n<p>ab</p></div>\n|, @builder.raw_result
472
+ actual = compile_block("//bibpaper[samplebib][sample bib @<b>{bold}]{\na\nb\n//}\n")
473
+ 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
474
+ end
475
+
476
+ def test_bibpaper_normalized
477
+ def @chapter.bibpaper(id)
478
+ Book::BibpaperIndex::Item.new("sample=bib",1,"sample bib")
479
+ end
480
+
481
+ actual = compile_block("//bibpaper[sample=bib][sample bib @<b>{bold}]{\na\nb\n//}\n")
482
+ 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
462
483
  end
463
484
 
464
485
  def test_bibpaper_with_anchor
@@ -466,14 +487,12 @@ class HTMLBuidlerTest < Test::Unit::TestCase
466
487
  Book::BibpaperIndex::Item.new("samplebib",1,"sample bib")
467
488
  end
468
489
 
469
- @builder.bibpaper(["a", "b"], "samplebib", "sample bib @<href>{http://example.jp}")
470
- 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|, @builder.raw_result
490
+ actual = compile_block("//bibpaper[samplebib][sample bib @<href>{http://example.jp}]{\na\nb\n//}\n")
491
+ 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
471
492
  end
472
493
 
473
494
  def column_helper(review)
474
- chap_singleton = class << @chapter; self; end
475
- chap_singleton.send(:define_method, :content) { review }
476
- @compiler.compile(@chapter).match(/<body>\n(.+)<\/body>/m)[1]
495
+ compile_block(review)
477
496
  end
478
497
 
479
498
  def test_column_1
@@ -488,7 +507,7 @@ inside column
488
507
 
489
508
  ===[/column]
490
509
  EOS
491
- expect =<<-EOS
510
+ expected =<<-EOS
492
511
  <div class="column">
493
512
 
494
513
  <h3><a id="column-1"></a>prev column</h3>
@@ -500,7 +519,7 @@ EOS
500
519
  <p>inside column</p>
501
520
  </div>
502
521
  EOS
503
- assert_equal expect, column_helper(review)
522
+ assert_equal expected, column_helper(review)
504
523
  end
505
524
 
506
525
  def test_column_2
@@ -511,7 +530,7 @@ inside column
511
530
 
512
531
  === next level
513
532
  EOS
514
- expect =<<-EOS
533
+ expected =<<-EOS
515
534
  <div class="column">
516
535
 
517
536
  <h3><a id="column-1"></a>test</h3>
@@ -521,7 +540,7 @@ EOS
521
540
  <h3><a id="h1-0-1"></a>next level</h3>
522
541
  EOS
523
542
 
524
- assert_equal expect, column_helper(review)
543
+ assert_equal expected, column_helper(review)
525
544
  end
526
545
 
527
546
  def test_column_3
@@ -547,7 +566,7 @@ inside column
547
566
 
548
567
  this is @<column>{foo}.
549
568
  EOS
550
- expect =<<-EOS
569
+ expected =<<-EOS
551
570
  <div class="column">
552
571
 
553
572
  <h3 id="foo"><a id="column-1"></a>test</h3>
@@ -558,7 +577,7 @@ EOS
558
577
  <p>this is test.</p>
559
578
  EOS
560
579
 
561
- assert_equal expect, column_helper(review)
580
+ assert_equal expected, column_helper(review)
562
581
  end
563
582
 
564
583
 
@@ -567,8 +586,9 @@ EOS
567
586
  * AAA
568
587
  * BBB
569
588
  EOS
570
- expect = "<ul>\n<li>AAA</li>\n<li>BBB</li>\n</ul>\n"
571
- ul_helper(src, expect)
589
+ expected = "<ul>\n<li>AAA</li>\n<li>BBB</li>\n</ul>\n"
590
+ actual = compile_block(src)
591
+ assert_equal expected, actual
572
592
  end
573
593
 
574
594
  def test_ul_cont
@@ -578,8 +598,9 @@ EOS
578
598
  * BBB
579
599
  -BB
580
600
  EOS
581
- expect = "<ul>\n<li>AAA-AA</li>\n<li>BBB-BB</li>\n</ul>\n"
582
- ul_helper(src, expect)
601
+ expected = "<ul>\n<li>AAA-AA</li>\n<li>BBB-BB</li>\n</ul>\n"
602
+ actual = compile_block(src)
603
+ assert_equal expected, actual
583
604
  end
584
605
 
585
606
  def test_ul_nest1
@@ -588,7 +609,7 @@ EOS
588
609
  ** AA
589
610
  EOS
590
611
 
591
- expect =<<-EOS
612
+ expected =<<-EOS
592
613
  <ul>
593
614
  <li>AAA<ul>
594
615
  <li>AA</li>
@@ -596,7 +617,8 @@ EOS
596
617
  </li>
597
618
  </ul>
598
619
  EOS
599
- ul_helper(src, expect)
620
+ actual = compile_block(src)
621
+ assert_equal expected, actual
600
622
  end
601
623
 
602
624
  def test_ul_nest2
@@ -607,7 +629,7 @@ EOS
607
629
  ** BB
608
630
  EOS
609
631
 
610
- expect =<<-EOS
632
+ expected =<<-EOS
611
633
  <ul>
612
634
  <li>AAA<ul>
613
635
  <li>AA</li>
@@ -619,7 +641,8 @@ EOS
619
641
  </li>
620
642
  </ul>
621
643
  EOS
622
- ul_helper(src, expect)
644
+ actual = compile_block(src)
645
+ assert_equal expected, actual
623
646
  end
624
647
 
625
648
  def test_ul_nest3
@@ -630,7 +653,7 @@ EOS
630
653
  ** BB
631
654
  EOS
632
655
 
633
- expect =<<-EOS
656
+ expected =<<-EOS
634
657
  <ul>
635
658
  <li><ul>
636
659
  <li>AAA</li>
@@ -643,7 +666,8 @@ EOS
643
666
  </li>
644
667
  </ul>
645
668
  EOS
646
- ul_helper(src, expect)
669
+ actual = compile_block(src)
670
+ assert_equal expected, actual
647
671
  end
648
672
 
649
673
  def test_ul_nest4
@@ -655,7 +679,7 @@ EOS
655
679
  ** BB
656
680
  EOS
657
681
 
658
- expect =<<-EOS
682
+ expected =<<-EOS
659
683
  <ul>
660
684
  <li>A<ul>
661
685
  <li>AA<ul>
@@ -670,7 +694,8 @@ EOS
670
694
  </li>
671
695
  </ul>
672
696
  EOS
673
- ul_helper(src, expect)
697
+ actual = compile_block(src)
698
+ assert_equal expected, actual
674
699
  end
675
700
 
676
701
  def test_ul_nest5
@@ -682,7 +707,7 @@ EOS
682
707
  ** BB
683
708
  EOS
684
709
 
685
- expect =<<-EOS
710
+ expected =<<-EOS
686
711
  <ul>
687
712
  <li>A<ul>
688
713
  <li>AA<ul>
@@ -700,7 +725,8 @@ EOS
700
725
  </li>
701
726
  </ul>
702
727
  EOS
703
- ul_helper(src, expect)
728
+ actual = compile_block(src)
729
+ assert_equal expected, actual
704
730
  end
705
731
 
706
732
  def test_ol
@@ -709,86 +735,87 @@ EOS
709
735
  3. BBB
710
736
  EOS
711
737
 
712
- expect =<<-EOS
738
+ expected =<<-EOS
713
739
  <ol>
714
740
  <li>AAA</li>
715
741
  <li>BBB</li>
716
742
  </ol>
717
743
  EOS
718
- ol_helper(src, expect)
744
+ actual = compile_block(src)
745
+ assert_equal expected, actual
719
746
  end
720
747
 
721
748
  def test_inline_raw0
722
- assert_equal "normal", @builder.inline_raw("normal")
749
+ assert_equal "normal", compile_inline("@<raw>{normal}")
723
750
  end
724
751
 
725
752
  def test_inline_raw1
726
- assert_equal "body", @builder.inline_raw("|html|body")
753
+ assert_equal "body", compile_inline("@<raw>{|html|body}")
727
754
  end
728
755
 
729
756
  def test_inline_raw2
730
- assert_equal "body", @builder.inline_raw("|html, latex|body")
757
+ assert_equal "body", compile_inline("@<raw>{|html, latex|body}")
731
758
  end
732
759
 
733
760
  def test_inline_raw3
734
- assert_equal "", @builder.inline_raw("|idgxml, latex|body")
761
+ assert_equal "", compile_inline("@<raw>{|idgxml, latex|body}")
735
762
  end
736
763
 
737
764
  def test_inline_raw4
738
- assert_equal "|html body", @builder.inline_raw("|html body")
765
+ assert_equal "|html body", compile_inline("@<raw>{|html body}")
739
766
  end
740
767
 
741
768
  def test_inline_raw5
742
- assert_equal "nor\nmal", @builder.inline_raw("|html|nor\\nmal")
769
+ assert_equal "nor\nmal", compile_inline("@<raw>{|html|nor\\nmal}")
743
770
  end
744
771
 
745
772
  def test_block_raw0
746
- @builder.raw("<>!\"\\n& ")
747
- expect = %Q(<>!\"\n& )
748
- assert_equal expect.chomp, @builder.raw_result
773
+ actual = compile_block("//raw[<>!\"\\n& ]\n")
774
+ expected = %Q(<>!\"\n& )
775
+ assert_equal expected, actual
749
776
  end
750
777
 
751
778
  def test_block_raw1
752
- @builder.raw("|html|<>!\"\\n& ")
753
- expect = %Q(<>!\"\n& )
754
- assert_equal expect.chomp, @builder.raw_result
779
+ actual = compile_block("//raw[|html|<>!\"\\n& ]\n")
780
+ expected = %Q(<>!\"\n& )
781
+ assert_equal expected, actual
755
782
  end
756
783
 
757
784
  def test_block_raw2
758
- @builder.raw("|html, latex|<>!\"\\n& ")
759
- expect = %Q(<>!\"\n& )
760
- assert_equal expect.chomp, @builder.raw_result
785
+ actual = compile_block("//raw[|html, latex|<>!\"\\n& ]\n")
786
+ expected = %Q(<>!\"\n& )
787
+ assert_equal expected, actual
761
788
  end
762
789
 
763
790
  def test_block_raw3
764
- @builder.raw("|latex, idgxml|<>!\"\\n& ")
765
- expect = ''
766
- assert_equal expect.chomp, @builder.raw_result
791
+ actual = compile_block("//raw[|latex, idgxml|<>!\"\\n& ]\n")
792
+ expected = ''
793
+ assert_equal expected, actual
767
794
  end
768
795
 
769
796
  def test_block_raw4
770
- @builder.raw("|html <>!\"\\n& ")
771
- expect = %Q(|html <>!\"\n& )
772
- assert_equal expect.chomp, @builder.raw_result
797
+ actual = compile_block("//raw[|html <>!\"\\n& ]\n")
798
+ expected = %Q(|html <>!\"\n& )
799
+ assert_equal expected, actual
773
800
  end
774
801
 
775
802
  def test_inline_fn
776
803
  fn = Book::FootnoteIndex.parse(['//footnote[foo][bar\\a\\$buz]'])
777
804
  @chapter.instance_eval{@footnote_index=fn}
778
- @builder.footnote("foo",'bar\\a\\$buz')
779
- expect =<<-'EOS'
805
+ actual = compile_block("//footnote[foo][bar\\a\\$buz]\n")
806
+ expected =<<-'EOS'
780
807
  <div class="footnote" id="fn-foo"><p class="footnote">[<a href="#fnb-foo">*1</a>] bar\a\$buz</p></div>
781
808
  EOS
782
- assert_equal expect, @builder.raw_result
809
+ assert_equal expected, actual
783
810
  end
784
811
 
785
812
  def test_inline_fn_with_tricky_id
786
813
  fn = Book::FootnoteIndex.parse(['//footnote[123 あ_;][bar\\a\\$buz]'])
787
814
  @chapter.instance_eval{@footnote_index=fn}
788
- @builder.footnote("123 あ_;",'bar\\a\\$buz')
789
- expect =<<-'EOS'
815
+ actual = compile_block("//footnote[123 あ_;][bar\\a\\$buz]\n")
816
+ expected =<<-'EOS'
790
817
  <div class="footnote" id="fn-id_123-_E3_81_82___3B"><p class="footnote">[<a href="#fnb-id_123-_E3_81_82___3B">*1</a>] bar\a\$buz</p></div>
791
818
  EOS
792
- assert_equal expect, @builder.raw_result
819
+ assert_equal expected, actual
793
820
  end
794
821
  end