review-peg 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +36 -0
  3. data/.rubocop.yml +47 -0
  4. data/.rubocop_todo.yml +605 -0
  5. data/.travis.yml +18 -0
  6. data/COPYING +515 -0
  7. data/ChangeLog +2449 -0
  8. data/Dockerfile +22 -0
  9. data/Gemfile +6 -0
  10. data/README.rdoc +81 -0
  11. data/Rakefile +51 -0
  12. data/bin/review-catalog-converter-peg +129 -0
  13. data/bin/review-check-peg +169 -0
  14. data/bin/review-checkdep-peg +63 -0
  15. data/bin/review-compile-peg +202 -0
  16. data/bin/review-epubmaker-legacy-peg +1024 -0
  17. data/bin/review-epubmaker-peg +44 -0
  18. data/bin/review-index-peg +110 -0
  19. data/bin/review-init-peg +151 -0
  20. data/bin/review-pdfmaker-peg +18 -0
  21. data/bin/review-preproc-peg +131 -0
  22. data/bin/review-validate-peg +51 -0
  23. data/bin/review-vol-peg +100 -0
  24. data/debian/README.Debian +12 -0
  25. data/debian/README.source +5 -0
  26. data/debian/changelog +5 -0
  27. data/debian/compat +1 -0
  28. data/debian/control +22 -0
  29. data/debian/copyright +62 -0
  30. data/debian/docs +6 -0
  31. data/debian/manpage.1.ex +59 -0
  32. data/debian/patches/path.diff +91 -0
  33. data/debian/patches/series +1 -0
  34. data/debian/review.install +13 -0
  35. data/debian/review.links +4 -0
  36. data/debian/rules +13 -0
  37. data/debian/source/format +1 -0
  38. data/doc/NEWS.ja.md +350 -0
  39. data/doc/NEWS.md +354 -0
  40. data/doc/catalog.ja.md +53 -0
  41. data/doc/catalog.md +52 -0
  42. data/doc/format.ja.md +734 -0
  43. data/doc/format.md +746 -0
  44. data/doc/format_idg.ja.md +203 -0
  45. data/doc/quickstart.ja.md +222 -0
  46. data/doc/quickstart.md +252 -0
  47. data/doc/ruby-uuid/README +11 -0
  48. data/doc/ruby-uuid/README.ja +34 -0
  49. data/doc/sample.css +108 -0
  50. data/doc/sample.yml +238 -0
  51. data/lib/epubmaker.rb +24 -0
  52. data/lib/epubmaker/content.rb +93 -0
  53. data/lib/epubmaker/epubcommon.rb +424 -0
  54. data/lib/epubmaker/epubv2.rb +139 -0
  55. data/lib/epubmaker/epubv3.rb +222 -0
  56. data/lib/epubmaker/producer.rb +330 -0
  57. data/lib/lineinput.rb +107 -0
  58. data/lib/review.rb +3 -0
  59. data/lib/review/book.rb +43 -0
  60. data/lib/review/book/base.rb +401 -0
  61. data/lib/review/book/chapter.rb +100 -0
  62. data/lib/review/book/compilable.rb +184 -0
  63. data/lib/review/book/image_finder.rb +71 -0
  64. data/lib/review/book/index.rb +413 -0
  65. data/lib/review/book/page_metric.rb +47 -0
  66. data/lib/review/book/part.rb +54 -0
  67. data/lib/review/book/volume.rb +67 -0
  68. data/lib/review/builder.rb +452 -0
  69. data/lib/review/catalog.rb +52 -0
  70. data/lib/review/compiler.rb +5183 -0
  71. data/lib/review/compiler/literals_1_9.kpeg +22 -0
  72. data/lib/review/compiler/literals_1_9.rb +435 -0
  73. data/lib/review/configure.rb +64 -0
  74. data/lib/review/epubbuilder.rb +18 -0
  75. data/lib/review/epubmaker.rb +480 -0
  76. data/lib/review/ewbbuilder.rb +381 -0
  77. data/lib/review/exception.rb +21 -0
  78. data/lib/review/extentions.rb +4 -0
  79. data/lib/review/extentions/array.rb +25 -0
  80. data/lib/review/extentions/object.rb +9 -0
  81. data/lib/review/extentions/string.rb +33 -0
  82. data/lib/review/htmlbuilder.rb +1166 -0
  83. data/lib/review/htmllayout.rb +41 -0
  84. data/lib/review/htmltoc.rb +45 -0
  85. data/lib/review/htmlutils.rb +90 -0
  86. data/lib/review/i18n.rb +96 -0
  87. data/lib/review/i18n.yml +169 -0
  88. data/lib/review/idgxmlbuilder.rb +1233 -0
  89. data/lib/review/inaobuilder.rb +357 -0
  90. data/lib/review/latexbuilder.rb +941 -0
  91. data/lib/review/latexindex.rb +35 -0
  92. data/lib/review/latexutils.rb +95 -0
  93. data/lib/review/layout.tex.erb +340 -0
  94. data/lib/review/lineinput.rb +17 -0
  95. data/lib/review/location.rb +24 -0
  96. data/lib/review/makerhelper.rb +67 -0
  97. data/lib/review/markdownbuilder.rb +339 -0
  98. data/lib/review/node.rb +288 -0
  99. data/lib/review/pdfmaker.rb +332 -0
  100. data/lib/review/preprocessor.rb +530 -0
  101. data/lib/review/review.kpeg +745 -0
  102. data/lib/review/sec_counter.rb +69 -0
  103. data/lib/review/template.rb +21 -0
  104. data/lib/review/textbuilder.rb +17 -0
  105. data/lib/review/textutils.rb +16 -0
  106. data/lib/review/tocparser.rb +348 -0
  107. data/lib/review/tocprinter.rb +205 -0
  108. data/lib/review/topbuilder.rb +796 -0
  109. data/lib/review/unfold.rb +138 -0
  110. data/lib/review/version.rb +3 -0
  111. data/lib/uuid.rb +312 -0
  112. data/review.gemspec +32 -0
  113. data/templates/html/layout-html5.html.erb +17 -0
  114. data/templates/html/layout-xhtml1.html.erb +20 -0
  115. data/templates/ncx/epubv2.ncx.erb +11 -0
  116. data/templates/opf/epubv2.opf.erb +21 -0
  117. data/templates/opf/epubv3.opf.erb +18 -0
  118. data/templates/xml/container.xml.erb +6 -0
  119. data/test/CHAPS +2 -0
  120. data/test/assets/test.xml.erb +3 -0
  121. data/test/assets/test_template.tex +255 -0
  122. data/test/assets/test_template_backmatter.tex +32 -0
  123. data/test/bib.re +13 -0
  124. data/test/book_test_helper.rb +35 -0
  125. data/test/sample-book/README.md +7 -0
  126. data/test/sample-book/src/Rakefile +58 -0
  127. data/test/sample-book/src/_cover.html +3 -0
  128. data/test/sample-book/src/catalog.yml +10 -0
  129. data/test/sample-book/src/ch01.re +71 -0
  130. data/test/sample-book/src/ch02.re +3 -0
  131. data/test/sample-book/src/config.yml +186 -0
  132. data/test/sample-book/src/images/ch01-imgsample.jpg +0 -0
  133. data/test/sample-book/src/images/cover.jpg +0 -0
  134. data/test/sample-book/src/preface.re +15 -0
  135. data/test/sample-book/src/sty/jumoline.sty +310 -0
  136. data/test/sample-book/src/sty/reviewmacro.sty +39 -0
  137. data/test/sample-book/src/style.css +251 -0
  138. data/test/sample-book/src/vendor/jumoline/README +29 -0
  139. data/test/sample-book/src/vendor/jumoline/jumoline.dtx +2988 -0
  140. data/test/sample-book/src/vendor/jumoline/jumoline.ins +6 -0
  141. data/test/test.re +43 -0
  142. data/test/test_book.rb +556 -0
  143. data/test/test_book_chapter.rb +280 -0
  144. data/test/test_book_part.rb +54 -0
  145. data/test/test_builder.rb +80 -0
  146. data/test/test_catalog.rb +119 -0
  147. data/test/test_catalog_converter_cmd.rb +73 -0
  148. data/test/test_compiler.rb +92 -0
  149. data/test/test_configure.rb +50 -0
  150. data/test/test_epub3maker.rb +529 -0
  151. data/test/test_epubmaker.rb +569 -0
  152. data/test/test_epubmaker_cmd.rb +40 -0
  153. data/test/test_helper.rb +92 -0
  154. data/test/test_htmlbuilder.rb +1114 -0
  155. data/test/test_htmltoc.rb +32 -0
  156. data/test/test_htmlutils.rb +50 -0
  157. data/test/test_i18n.rb +180 -0
  158. data/test/test_idgxmlbuilder.rb +608 -0
  159. data/test/test_image_finder.rb +82 -0
  160. data/test/test_inaobuilder.rb +245 -0
  161. data/test/test_index.rb +174 -0
  162. data/test/test_latexbuilder.rb +732 -0
  163. data/test/test_lineinput.rb +182 -0
  164. data/test/test_makerhelper.rb +66 -0
  165. data/test/test_markdownbuilder.rb +125 -0
  166. data/test/test_pdfmaker.rb +171 -0
  167. data/test/test_pdfmaker_cmd.rb +40 -0
  168. data/test/test_preprocessor.rb +23 -0
  169. data/test/test_review_ext.rb +31 -0
  170. data/test/test_template.rb +26 -0
  171. data/test/test_textutils.rb +32 -0
  172. data/test/test_topbuilder.rb +291 -0
  173. data/test/test_uuid.rb +157 -0
  174. metadata +357 -0
@@ -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-peg', 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
@@ -0,0 +1,92 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+ require 'review/compiler'
5
+ require 'review/book'
6
+ require 'review/latexbuilder'
7
+ require 'review/htmlbuilder'
8
+
9
+ class CompilerTest < Test::Unit::TestCase
10
+ include ReVIEW
11
+
12
+ def setup
13
+ @builder = HTMLBuilder.new()
14
+ @param = {
15
+ "secnolevel" => 2, # for IDGXMLBuilder, HTMLBuilder
16
+ "inencoding" => "UTF-8",
17
+ "outencoding" => "UTF-8",
18
+ "subdirmode" => nil,
19
+ "stylesheet" => nil, # for HTMLBuilder
20
+ }
21
+ ReVIEW.book.param = @param
22
+ @compiler = ReVIEW::Compiler.new(@builder)
23
+ @chapter = Book::Chapter.new(Book::Base.new(nil), 1, '-', nil, StringIO.new)
24
+ location = Location.new(nil, nil)
25
+ @builder.bind(@compiler, @chapter, location)
26
+
27
+ def @compiler.compile_command(name, args, lines, node)
28
+ args
29
+ end
30
+
31
+ end
32
+
33
+ def test_parse_args
34
+ args = compile_blockelem("//dummy[foo][bar]\n", false)
35
+ assert_equal ["foo","bar"], args.parse_args(:doc,:doc)
36
+ end
37
+
38
+ def test_parse_args_with_brace1
39
+ args = compile_blockelem("//dummy[fo[\\][\\]o][bar]", false)
40
+ assert_equal ["fo[][]o","bar"], args.parse_args(:doc, :doc)
41
+ end
42
+
43
+ def test_parse_args_with_brace2
44
+ args = compile_blockelem("//dummy[f\\]o\\]o][bar]", false)
45
+ assert_equal ["f]o]o","bar"], args.parse_args(:doc, :doc)
46
+ end
47
+
48
+ def test_parse_args_with_backslash
49
+ args = compile_blockelem("//dummy[foo][bar\\buz]", false)
50
+ assert_equal ["foo","bar\\buz"], args.parse_args(:doc, :doc)
51
+ end
52
+
53
+ def test_parse_args_with_backslash2
54
+ args = compile_blockelem("//dummy[foo][bar\\#\\[\\!]", false)
55
+ assert_equal ["foo","bar\\#\\[\\!"], args.parse_args(:doc, :doc)
56
+ end
57
+
58
+ def test_parse_args_with_backslash3
59
+ args = compile_blockelem("//dummy[foo][bar\\\\buz]", false)
60
+ assert_equal ["foo","bar\\buz"], args.parse_args(:doc, :doc)
61
+ end
62
+
63
+ def test_compile_inline
64
+ def @compiler.inline_ruby(*args)
65
+ return args
66
+ end
67
+ args = compile_inline("@<ruby>{abc}",false)
68
+ assert_equal "abc", args.content[0].content.to_doc
69
+ end
70
+
71
+ def test_inline_ruby
72
+ # def @compiler.inline_ruby(*args)
73
+ # return args
74
+ # end
75
+ args = compile_inline("@<ruby>{foo,bar}",false)
76
+ assert_equal "foo", args.content[0].content[0].to_doc
77
+ assert_equal "bar", args.content[0].content[1].to_doc
78
+ args = compile_inline("@<ruby>{foo\\,\\,,\\,bar\\,buz}", false)
79
+ assert_equal "foo,,", args.content[0].content[0].to_doc
80
+ assert_equal ",bar,buz", args.content[0].content[1].to_doc
81
+ end
82
+
83
+ def test_compile_inline_backslash
84
+ def @compiler.inline_dummy(*args)
85
+ return args
86
+ end
87
+ Compiler.definline :dummy
88
+ args = compile_inline("@<dummy>{abc\\d\\#a}", false)
89
+ assert_equal "abc\\d\\#a", args.content[0].content.to_doc
90
+ end
91
+ end
92
+
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+ require 'review/epubmaker'
5
+
6
+ class ConfigureTest < Test::Unit::TestCase
7
+ include ReVIEW
8
+
9
+ def setup
10
+ @maker = ReVIEW::EPUBMaker.new
11
+ @config = ReVIEW::Configure.values
12
+ @config.merge!({
13
+ "bookname" => "sample",
14
+ "title" => "Sample Book",
15
+ "version" => 2,
16
+ "urnid" => "http://example.jp/",
17
+ "date" => "2011-01-01",
18
+ "language" => "ja",
19
+ "epubmaker" => {"flattocindent" => true},
20
+ })
21
+ @output = StringIO.new
22
+ I18n.setup(@config["language"])
23
+ end
24
+
25
+ def test_configure_class
26
+ assert_equal ReVIEW::Configure, @config.class
27
+ end
28
+
29
+ def test_configure_get
30
+ bookname = @config["bookname"]
31
+ assert_equal "sample", bookname
32
+ end
33
+
34
+ def test_configure_get2
35
+ assert_equal true, @config["epubmaker"]["flattocindent"]
36
+ end
37
+
38
+ def test_configure_with_maker
39
+ @config.maker = "epubmaker"
40
+ assert_equal true, @config["flattocindent"]
41
+ assert_equal true, @config["epubmaker"]["flattocindent"]
42
+ end
43
+
44
+ def test_configure_with_invalidmaker
45
+ @config.maker = "pdfmaker"
46
+ assert_equal nil, @config["flattocindent"]
47
+ assert_equal true, @config["epubmaker"]["flattocindent"]
48
+ end
49
+
50
+ end
@@ -0,0 +1,529 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+ require 'epubmaker'
5
+ require 'review/epubmaker'
6
+
7
+ class EPUB3MakerTest < Test::Unit::TestCase
8
+ include EPUBMaker
9
+
10
+ def setup
11
+ @producer = Producer.new
12
+ @producer.merge_params({
13
+ "bookname" => "sample",
14
+ "title" => "Sample Book",
15
+ "epubversion" => 3,
16
+ "urnid" => "http://example.jp/",
17
+ "date" => "2011-01-01",
18
+ "language" => "en",
19
+ "modified" => "2014-12-13T14:15:16Z"
20
+ })
21
+ @output = StringIO.new
22
+ end
23
+
24
+ def test_initialize
25
+ assert Producer.new
26
+ end
27
+
28
+ def test_resource_en
29
+ @producer.merge_params({"language" => "en"})
30
+ assert_equal "Table of Contents", @producer.res.v("toctitle")
31
+ end
32
+
33
+ def test_resource_ja
34
+ @producer.merge_params({"language" => "ja"})
35
+ assert_equal "目次", @producer.res.v("toctitle")
36
+ end
37
+
38
+ def test_mimetype
39
+ @producer.mimetype(@output)
40
+ assert_equal %Q[application/epub+zip], @output.string
41
+ end
42
+
43
+ def test_container
44
+ @producer.container(@output)
45
+ expect = <<EOT
46
+ <?xml version="1.0" encoding="UTF-8"?>
47
+ <container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
48
+ <rootfiles>
49
+ <rootfile full-path="OEBPS/sample.opf" media-type="application/oebps-package+xml" />
50
+ </rootfiles>
51
+ </container>
52
+ EOT
53
+ assert_equal expect, @output.string
54
+ end
55
+
56
+ def test_stage1_opf
57
+ @producer.opf(@output)
58
+ expect = <<EOT
59
+ <?xml version="1.0" encoding="UTF-8"?>
60
+ <package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" xml:lang="en">
61
+ <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
62
+ <dc:title id="title">Sample Book</dc:title>
63
+ <dc:language id="language">en</dc:language>
64
+ <dc:date id="date">2011-01-01</dc:date>
65
+ <meta property="dcterms:modified">2014-12-13T14:15:16Z</meta>
66
+ <dc:identifier id="BookId">http://example.jp/</dc:identifier>
67
+ </metadata>
68
+ <manifest>
69
+ <item properties="nav" id="sample-toc.html" href="sample-toc.html" media-type="application/xhtml+xml"/>
70
+ <item id="sample" href="sample.html" media-type="application/xhtml+xml"/>
71
+ </manifest>
72
+ <spine>
73
+ <itemref idref="sample" linear="no"/>
74
+ </spine>
75
+ <guide>
76
+ <reference type="cover" title="Cover" href="sample.html"/>
77
+ <reference type="toc" title="Table of Contents" href="sample-toc.html"/>
78
+ </guide>
79
+ </package>
80
+ EOT
81
+ assert_equal expect, @output.string
82
+ end
83
+
84
+ def test_stage1_ncx
85
+ @producer.ncx(@output)
86
+ expect = <<EOT
87
+ <?xml version="1.0" encoding="UTF-8"?>
88
+ <!DOCTYPE html>
89
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
90
+ <head>
91
+ <meta charset="UTF-8" />
92
+ <meta name="generator" content="Re:VIEW" />
93
+ <title>Table of Contents</title>
94
+ </head>
95
+ <body>
96
+ <nav xmlns:epub="http://www.idpf.org/2007/ops" epub:type="toc" id="toc">
97
+ <h1 class="toc-title">Table of Contents</h1>
98
+
99
+ <ol class="toc-h1"></ol> </nav>
100
+ </body>
101
+ </html>
102
+ EOT
103
+ assert_equal expect, @output.string
104
+ end
105
+
106
+ def stage2
107
+ # add one item
108
+ @producer.contents << Content.new({"file" => "ch01.html", "title" => "CH01", "level" => 1})
109
+ end
110
+
111
+ def test_stage2_add_l1item
112
+ stage2
113
+ expect = EPUBMaker::Content.new("ch01.html",
114
+ "ch01-html",
115
+ "application/xhtml+xml",
116
+ "CH01",
117
+ 1)
118
+ assert_equal expect, @producer.contents[0]
119
+ end
120
+
121
+ def test_stage2_opf
122
+ stage2
123
+ @producer.opf(@output)
124
+ expect = <<EOT
125
+ <?xml version="1.0" encoding="UTF-8"?>
126
+ <package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" xml:lang="en">
127
+ <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
128
+ <dc:title id="title">Sample Book</dc:title>
129
+ <dc:language id="language">en</dc:language>
130
+ <dc:date id="date">2011-01-01</dc:date>
131
+ <meta property="dcterms:modified">2014-12-13T14:15:16Z</meta>
132
+ <dc:identifier id="BookId">http://example.jp/</dc:identifier>
133
+ </metadata>
134
+ <manifest>
135
+ <item properties="nav" id="sample-toc.html" href="sample-toc.html" media-type="application/xhtml+xml"/>
136
+ <item id="sample" href="sample.html" media-type="application/xhtml+xml"/>
137
+ <item id="ch01-html" href="ch01.html" media-type="application/xhtml+xml"/>
138
+ </manifest>
139
+ <spine>
140
+ <itemref idref="sample" linear="no"/>
141
+ <itemref idref="ch01-html"/>
142
+ </spine>
143
+ <guide>
144
+ <reference type="cover" title="Cover" href="sample.html"/>
145
+ <reference type="toc" title="Table of Contents" href="sample-toc.html"/>
146
+ </guide>
147
+ </package>
148
+ EOT
149
+ assert_equal expect, @output.string
150
+ end
151
+
152
+ def test_stage2_ncx
153
+ stage2
154
+ @producer.ncx(@output)
155
+ expect = <<EOT
156
+ <?xml version="1.0" encoding="UTF-8"?>
157
+ <!DOCTYPE html>
158
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
159
+ <head>
160
+ <meta charset="UTF-8" />
161
+ <meta name="generator" content="Re:VIEW" />
162
+ <title>Table of Contents</title>
163
+ </head>
164
+ <body>
165
+ <nav xmlns:epub="http://www.idpf.org/2007/ops" epub:type="toc" id="toc">
166
+ <h1 class="toc-title">Table of Contents</h1>
167
+
168
+ <ol class="toc-h1"><li><a href="ch01.html">CH01</a></li>
169
+ </ol> </nav>
170
+ </body>
171
+ </html>
172
+ EOT
173
+ assert_equal expect, @output.string
174
+ end
175
+
176
+ def stage3
177
+ # add more items
178
+ @producer.contents << Content.new({"file" => "ch01.html", "title" => "CH01<>&\"", "level" => 1})
179
+ @producer.contents << Content.new({"file" => "ch02.html", "title" => "CH02", "level" => 1})
180
+ @producer.contents << Content.new({"file" => "ch02.html#S1", "title" => "CH02.1", "level" => 2})
181
+ @producer.contents << Content.new({"file" => "ch02.html#S1.1", "title" => "CH02.1.1", "level" => 3})
182
+ @producer.contents << Content.new({"file" => "ch02.html#S1.1.1", "title" => "CH02.1.1.1", "level" => 4})
183
+ @producer.contents << Content.new({"file" => "ch02.html#S1.1.1.1", "title" => "CH02.1.1.1.1", "level" => 5})
184
+ @producer.contents << Content.new({"file" => "ch02.html#S1.1.2", "title" => "CH02.1.1.2", "level" => 4})
185
+ @producer.contents << Content.new({"file" => "ch02.html#S2", "title" => "CH02.2", "level" => 2})
186
+ @producer.contents << Content.new({"file" => "ch02.html#S2.1", "title" => "CH02.2.1", "level" => 3})
187
+ @producer.contents << Content.new({"file" => "ch03.html", "title" => "CH03", "level" => 1, "properties" => ["mathml"]})
188
+ @producer.contents << Content.new({"file" => "ch03.html#S1", "title" => "CH03.1", "level" => 2})
189
+ @producer.contents << Content.new({"file" => "ch03.html#S1.1", "title" => "CH03.1.1", "level" => 3})
190
+ @producer.contents << Content.new({"file" => "ch04.html", "title" => "CH04", "level" => 1})
191
+ @producer.contents << Content.new({"file" => "sample.png"})
192
+ @producer.contents << Content.new({"file" => "sample.jpg"})
193
+ @producer.contents << Content.new({"file" => "sample.JPEG"})
194
+ @producer.contents << Content.new({"file" => "sample.SvG"})
195
+ @producer.contents << Content.new({"file" => "sample.GIF"})
196
+ @producer.contents << Content.new({"file" => "sample.css"})
197
+ end
198
+
199
+ def test_stage3_add_various_items
200
+ stage3
201
+ expect = [
202
+ Content.new("ch01.html", "ch01-html", "application/xhtml+xml", "CH01<>&\"", 1),
203
+ Content.new("ch02.html", "ch02-html", "application/xhtml+xml", "CH02", 1),
204
+ Content.new("ch02.html#S1", "ch02-html#S1","html#s1","CH02.1", 2),
205
+ Content.new("ch02.html#S1.1", "ch02-html#S1-1", "1", "CH02.1.1", 3),
206
+ Content.new("ch02.html#S1.1.1", "ch02-html#S1-1-1","1", "CH02.1.1.1", 4),
207
+ Content.new("ch02.html#S1.1.1.1", "ch02-html#S1-1-1-1", "1","CH02.1.1.1.1", 5),
208
+ Content.new("ch02.html#S1.1.2", "ch02-html#S1-1-2", "2", "CH02.1.1.2", 4),
209
+ Content.new("ch02.html#S2", "ch02-html#S2", "html#s2", "CH02.2", 2),
210
+ Content.new("ch02.html#S2.1", "ch02-html#S2-1", "1", "CH02.2.1", 3),
211
+ Content.new("ch03.html", "ch03-html", "application/xhtml+xml", "CH03", 1, nil, ["mathml"]),
212
+ Content.new("ch03.html#S1", "ch03-html#S1", "html#s1", "CH03.1", 2),
213
+ Content.new("ch03.html#S1.1", "ch03-html#S1-1", "1", "CH03.1.1", 3),
214
+ Content.new("ch04.html", "ch04-html", "application/xhtml+xml", "CH04", 1),
215
+ Content.new("sample.png", "sample-png", "image/png"),
216
+ Content.new("sample.jpg", "sample-jpg", "image/jpeg"),
217
+ Content.new("sample.JPEG", "sample-JPEG", "image/jpeg"),
218
+ Content.new("sample.SvG", "sample-SvG", "image/svg+xml"),
219
+ Content.new("sample.GIF", "sample-GIF", "image/gif"),
220
+ Content.new("sample.css", "sample-css", "text/css")
221
+ ]
222
+
223
+ assert_equal expect, @producer.contents
224
+ end
225
+
226
+ def test_stage3_opf
227
+ stage3
228
+ @producer.opf(@output)
229
+ expect = <<EOT
230
+ <?xml version="1.0" encoding="UTF-8"?>
231
+ <package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" xml:lang="en">
232
+ <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
233
+ <dc:title id="title">Sample Book</dc:title>
234
+ <dc:language id="language">en</dc:language>
235
+ <dc:date id="date">2011-01-01</dc:date>
236
+ <meta property="dcterms:modified">2014-12-13T14:15:16Z</meta>
237
+ <dc:identifier id="BookId">http://example.jp/</dc:identifier>
238
+ </metadata>
239
+ <manifest>
240
+ <item properties="nav" id="sample-toc.html" href="sample-toc.html" media-type="application/xhtml+xml"/>
241
+ <item id="sample" href="sample.html" media-type="application/xhtml+xml"/>
242
+ <item id="ch01-html" href="ch01.html" media-type="application/xhtml+xml"/>
243
+ <item id="ch02-html" href="ch02.html" media-type="application/xhtml+xml"/>
244
+ <item id="ch03-html" href="ch03.html" media-type="application/xhtml+xml" properties="mathml"/>
245
+ <item id="ch04-html" href="ch04.html" media-type="application/xhtml+xml"/>
246
+ <item id="sample-png" href="sample.png" media-type="image/png"/>
247
+ <item id="sample-jpg" href="sample.jpg" media-type="image/jpeg"/>
248
+ <item id="sample-JPEG" href="sample.JPEG" media-type="image/jpeg"/>
249
+ <item id="sample-SvG" href="sample.SvG" media-type="image/svg+xml"/>
250
+ <item id="sample-GIF" href="sample.GIF" media-type="image/gif"/>
251
+ <item id="sample-css" href="sample.css" media-type="text/css"/>
252
+ </manifest>
253
+ <spine>
254
+ <itemref idref="sample" linear="no"/>
255
+ <itemref idref="ch01-html"/>
256
+ <itemref idref="ch02-html"/>
257
+ <itemref idref="ch03-html"/>
258
+ <itemref idref="ch04-html"/>
259
+ </spine>
260
+ <guide>
261
+ <reference type="cover" title="Cover" href="sample.html"/>
262
+ <reference type="toc" title="Table of Contents" href="sample-toc.html"/>
263
+ </guide>
264
+ </package>
265
+ EOT
266
+ assert_equal expect, @output.string
267
+ end
268
+
269
+ def test_stage3_ncx
270
+ stage3
271
+ @producer.ncx(@output)
272
+ expect = <<EOT
273
+ <?xml version="1.0" encoding="UTF-8"?>
274
+ <!DOCTYPE html>
275
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
276
+ <head>
277
+ <meta charset="UTF-8" />
278
+ <meta name="generator" content="Re:VIEW" />
279
+ <title>Table of Contents</title>
280
+ </head>
281
+ <body>
282
+ <nav xmlns:epub="http://www.idpf.org/2007/ops" epub:type="toc" id="toc">
283
+ <h1 class="toc-title">Table of Contents</h1>
284
+
285
+ <ol class="toc-h1"><li><a href="ch01.html">CH01&lt;&gt;&amp;&quot;</a></li>
286
+ <li><a href="ch02.html">CH02</a>
287
+ <ol class="toc-h2"><li><a href="ch02.html#S1">CH02.1</a></li>
288
+ <li><a href="ch02.html#S2">CH02.2</a></li>
289
+ </ol></li>
290
+ <li><a href="ch03.html">CH03</a>
291
+ <ol class="toc-h2"><li><a href="ch03.html#S1">CH03.1</a></li>
292
+ </ol></li>
293
+ <li><a href="ch04.html">CH04</a></li>
294
+ </ol> </nav>
295
+ </body>
296
+ </html>
297
+ EOT
298
+ assert_equal expect, @output.string
299
+ end
300
+
301
+ def test_stage3_mytoc
302
+ stage3
303
+ @producer.mytoc(@output)
304
+ expect = <<EOT
305
+ <?xml version="1.0" encoding="UTF-8"?>
306
+ <!DOCTYPE html>
307
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
308
+ <head>
309
+ <meta charset="UTF-8" />
310
+ <meta name="generator" content="Re:VIEW" />
311
+ <title>Table of Contents</title>
312
+ </head>
313
+ <body>
314
+ <h1 class="toc-title">Table of Contents</h1>
315
+
316
+ <ul class="toc-h1"><li><a href="ch01.html">CH01&lt;&gt;&amp;&quot;</a></li>
317
+ <li><a href="ch02.html">CH02</a>
318
+ <ul class="toc-h2"><li><a href="ch02.html#S1">CH02.1</a></li>
319
+ <li><a href="ch02.html#S2">CH02.2</a></li>
320
+ </ul></li>
321
+ <li><a href="ch03.html">CH03</a>
322
+ <ul class="toc-h2"><li><a href="ch03.html#S1">CH03.1</a></li>
323
+ </ul></li>
324
+ <li><a href="ch04.html">CH04</a></li>
325
+ </ul></body>
326
+ </html>
327
+ EOT
328
+ assert_equal expect, @output.string
329
+ end
330
+
331
+ def test_stage3_flat
332
+ @producer.merge_params({"epubmaker" =>
333
+ {"flattoc" => true, "flattocindent" => false}
334
+ })
335
+ stage3
336
+ @producer.mytoc(@output)
337
+ expect = <<EOT
338
+ <?xml version="1.0" encoding="UTF-8"?>
339
+ <!DOCTYPE html>
340
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
341
+ <head>
342
+ <meta charset="UTF-8" />
343
+ <meta name="generator" content="Re:VIEW" />
344
+ <title>Table of Contents</title>
345
+ </head>
346
+ <body>
347
+ <h1 class="toc-title">Table of Contents</h1>
348
+ <ul class="toc-h1">
349
+ <li><a href="ch01.html">CH01&lt;&gt;&amp;&quot;</a></li>
350
+ <li><a href="ch02.html">CH02</a></li>
351
+ <li><a href="ch02.html#S1">CH02.1</a></li>
352
+ <li><a href="ch02.html#S2">CH02.2</a></li>
353
+ <li><a href="ch03.html">CH03</a></li>
354
+ <li><a href="ch03.html#S1">CH03.1</a></li>
355
+ <li><a href="ch04.html">CH04</a></li>
356
+ </ul>
357
+ </body>
358
+ </html>
359
+ EOT
360
+ assert_equal expect, @output.string
361
+ end
362
+
363
+ def test_stage3_cover
364
+ stage3
365
+ @producer.cover(@output)
366
+ expect = <<EOT
367
+ <?xml version="1.0" encoding="UTF-8"?>
368
+ <!DOCTYPE html>
369
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
370
+ <head>
371
+ <meta charset="UTF-8" />
372
+ <meta name="generator" content="Re:VIEW" />
373
+ <title>Sample Book</title>
374
+ </head>
375
+ <body epub:type="cover">
376
+ <h1 class="cover-title">Sample Book</h1>
377
+ </body>
378
+ </html>
379
+ EOT
380
+ assert_equal expect, @output.string
381
+ end
382
+
383
+ def test_stage3_cover_with_image
384
+ stage3
385
+ @producer.params["coverimage"] = "sample.png"
386
+ @producer.cover(@output)
387
+ expect = <<EOT
388
+ <?xml version="1.0" encoding="UTF-8"?>
389
+ <!DOCTYPE html>
390
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
391
+ <head>
392
+ <meta charset="UTF-8" />
393
+ <meta name="generator" content="Re:VIEW" />
394
+ <title>Sample Book</title>
395
+ </head>
396
+ <body epub:type="cover">
397
+ <div id="cover-image" class="cover-image">
398
+ <img src="sample.png" alt="Sample Book" class="max"/>
399
+ </div>
400
+ </body>
401
+ </html>
402
+ EOT
403
+ assert_equal expect, @output.string
404
+ end
405
+
406
+ def test_colophon_default
407
+ @producer.params["aut"] = ["Mr.Smith"]
408
+ @producer.params["pbl"] = ["BLUEPRINT"]
409
+ @producer.colophon(@output)
410
+ expect = <<EOT
411
+ <?xml version="1.0" encoding="UTF-8"?>
412
+ <!DOCTYPE html>
413
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
414
+ <head>
415
+ <meta charset="UTF-8" />
416
+ <meta name="generator" content="Re:VIEW" />
417
+ <title>Colophon</title>
418
+ </head>
419
+ <body>
420
+ <div class="colophon">
421
+ <p class="title">Sample Book</p>
422
+ <div class="pubhistory">
423
+ <p>published by Jan. 1, 2011</p>
424
+ </div>
425
+ <table class="colophon">
426
+ <tr><th>Author</th><td>Mr.Smith</td></tr>
427
+ <tr><th>Publisher</th><td>BLUEPRINT</td></tr>
428
+ </table>
429
+ </div>
430
+ </body>
431
+ </html>
432
+ EOT
433
+ assert_equal expect, @output.string
434
+ end
435
+
436
+ def test_colophon_pht
437
+ @producer.params["aut"] = ["Mr.Smith"]
438
+ @producer.params["pbl"] = ["BLUEPRINT"]
439
+ @producer.params["pht"] = ["Mrs.Smith"]
440
+ @producer.colophon(@output)
441
+ expect = <<EOT
442
+ <?xml version="1.0" encoding="UTF-8"?>
443
+ <!DOCTYPE html>
444
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
445
+ <head>
446
+ <meta charset="UTF-8" />
447
+ <meta name="generator" content="Re:VIEW" />
448
+ <title>Colophon</title>
449
+ </head>
450
+ <body>
451
+ <div class="colophon">
452
+ <p class="title">Sample Book</p>
453
+ <div class="pubhistory">
454
+ <p>published by Jan. 1, 2011</p>
455
+ </div>
456
+ <table class="colophon">
457
+ <tr><th>Author</th><td>Mr.Smith</td></tr>
458
+ <tr><th>Publisher</th><td>BLUEPRINT</td></tr>
459
+ <tr><th>Director of Photography</th><td>Mrs.Smith</td></tr>
460
+ </table>
461
+ </div>
462
+ </body>
463
+ </html>
464
+ EOT
465
+ assert_equal expect, @output.string
466
+ end
467
+
468
+ # def test_duplicate_id
469
+ # stage3
470
+ # assert_raise(Error) do
471
+ # @producer.contents << Content.new({"file" => "ch02.html#S1", "title" => "CH02.1", "level" => 2})
472
+ # end
473
+ # end
474
+
475
+ def test_detect_mathml
476
+ Dir.mktmpdir do |dir|
477
+ epubmaker = ReVIEW::EPUBMaker.new
478
+ path = File.join(dir,"test.html")
479
+ html = <<EOT
480
+ <?xml version="1.0" encoding="UTF-8"?>
481
+ <!DOCTYPE html>
482
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
483
+ <head>
484
+ <meta charset="UTF-8" />
485
+ <meta name="generator" content="Re:VIEW" />
486
+ <title>Colophon</title>
487
+ </head>
488
+ <body>
489
+ <div>
490
+ <p><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></p>
491
+ </div>
492
+ </body>
493
+ </html>
494
+ EOT
495
+ File.open(path, "w") do |f|
496
+ f.write(html)
497
+ end
498
+ assert_equal ["mathml"], epubmaker.detect_properties(path)
499
+ end
500
+ end
501
+
502
+
503
+ def test_detect_mathml_ns
504
+ Dir.mktmpdir do |dir|
505
+ epubmaker = ReVIEW::EPUBMaker.new
506
+ path = File.join(dir,"test.html")
507
+ html = <<EOT
508
+ <?xml version="1.0" encoding="UTF-8"?>
509
+ <!DOCTYPE html>
510
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="en">
511
+ <head>
512
+ <meta charset="UTF-8" />
513
+ <meta name="generator" content="Re:VIEW" />
514
+ <title>Colophon</title>
515
+ </head>
516
+ <body>
517
+ <div>
518
+ <p><span class=\"equation\"><m:math xmlns:m='http://www.w3.org/1998/Math/MathML' display='inline'><m:mfrac><m:mrow><m:mo stretchy='false'>-</m:mo><m:mi>b</m:mi><m:mo stretchy='false'>&#xb1;</m:mo><m:msqrt><m:mrow><m:msup><m:mi>b</m:mi><m:mn>2</m:mn></m:msup><m:mo stretchy='false'>-</m:mo><m:mn>4</m:mn><m:mi>a</m:mi><m:mi>c</m:mi></m:mrow></m:msqrt></m:mrow><m:mrow><m:mn>2</m:mn><m:mi>a</m:mi></m:mrow></m:mfrac></m:math></span></p>
519
+ </div>
520
+ </body>
521
+ </html>
522
+ EOT
523
+ File.open(path, "w") do |f|
524
+ f.write(html)
525
+ end
526
+ assert_equal ["mathml"], epubmaker.detect_properties(path)
527
+ end
528
+ end
529
+ end