test/test_epub3maker.rb in review-5.0.0 vs test/test_epub3maker.rb in review-5.1.0

- old
+ new

@@ -1,61 +1,61 @@ require 'test_helper' -require 'epubmaker' +require 'review/configure' require 'review/epubmaker' class EPUB3MakerTest < Test::Unit::TestCase - include EPUBMaker - def setup - @producer = Producer.new - @producer.merge_config( + config = ReVIEW::Configure.values + config.merge!( 'bookname' => 'sample', 'title' => 'Sample Book', 'epubversion' => 3, 'urnid' => 'http://example.jp/', 'date' => '2011-01-01', 'language' => 'en', 'modified' => '2014-12-13T14:15:16Z', 'titlepage' => nil ) - @output = StringIO.new + @producer = ReVIEW::EPUBMaker::Producer.new(config) end def test_initialize - assert Producer.new + assert ReVIEW::EPUBMaker::Producer.new(ReVIEW::Configure.values) end def test_resource_en - @producer.merge_config('language' => 'en') - assert_equal 'Table of Contents', @producer.res.v('toctitle') + @producer.config['language'] = 'en' + @producer.modify_config + assert_equal 'Table of Contents', ReVIEW::I18n.t('toctitle') end def test_resource_ja - @producer.merge_config('language' => 'ja') - assert_equal '目次', @producer.res.v('toctitle') + @producer.config['language'] = 'ja' + @producer.modify_config + assert_equal '目次', ReVIEW::I18n.t('toctitle') end def test_mimetype - @producer.mimetype(@output) - assert_equal 'application/epub+zip', @output.string + output = @producer.instance_eval { @epub.mimetype } + assert_equal 'application/epub+zip', output end def test_container - @producer.container(@output) + output = @producer.instance_eval { @epub.container } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0"> <rootfiles> <rootfile full-path="OEBPS/sample.opf" media-type="application/oebps-package+xml" /> </rootfiles> </container> EOT - assert_equal expect, @output.string + assert_equal expect, output end def test_stage1_opf - @producer.opf(@output) + output = @producer.instance_eval { @epub.opf } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" xml:lang="en"> <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf"> <dc:title id="title">Sample Book</dc:title> @@ -75,19 +75,20 @@ <reference type="cover" title="Cover" href="sample.html"/> <reference type="toc" title="Table of Contents" href="sample-toc.html"/> </guide> </package> EOT - assert_equal expect, @output.string + assert_equal expect, output end def test_stage1_opf_ebpaj - @producer.merge_config( + @producer.config.merge!( 'opf_prefix' => { 'ebpaj' => 'http://www.ebpaj.jp/' }, 'opf_meta' => { 'ebpaj:guide-version' => '1.1.2' } ) - @producer.opf(@output) + @producer.modify_config + output = @producer.instance_eval { @epub.opf } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" xml:lang="en" prefix="ebpaj: http://www.ebpaj.jp/"> <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf"> <dc:title id="title">Sample Book</dc:title> @@ -108,18 +109,19 @@ <reference type="cover" title="Cover" href="sample.html"/> <reference type="toc" title="Table of Contents" href="sample-toc.html"/> </guide> </package> EOT - assert_equal expect, @output.string + assert_equal expect, output end def test_stage1_opf_fileas - @producer.config['title'] = { 'name' => 'これは書籍です', 'file-as' => 'コレハショセキデス' } - @producer.config['aut'] = [{ 'name' => '著者A', 'file-as' => 'チョシャA' }, { 'name' => '著者B', 'file-as' => 'チョシャB' }] - @producer.config['pbl'] = [{ 'name' => '出版社', 'file-as' => 'シュッパンシャ' }] - @producer.opf(@output) + @producer.config.merge!('title' => { 'name' => 'これは書籍です', 'file-as' => 'コレハショセキデス' }, + 'aut' => [{ 'name' => '著者A', 'file-as' => 'チョシャA' }, { 'name' => '著者B', 'file-as' => 'チョシャB' }], + 'pbl' => [{ 'name' => '出版社', 'file-as' => 'シュッパンシャ' }]) + @producer.modify_config + output = @producer.instance_eval { @epub.opf } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" xml:lang="en"> <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf"> <dc:title id="title">これは書籍です</dc:title> @@ -152,15 +154,15 @@ <reference type="cover" title="Cover" href="sample.html"/> <reference type="toc" title="Table of Contents" href="sample-toc.html"/> </guide> </package> EOT - assert_equal expect, @output.string + assert_equal expect, output end def test_stage1_ncx - @producer.ncx(@output) + output = @producer.instance_eval { @epub.ncx([]) } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <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"> <head> @@ -174,31 +176,31 @@ <ol class="toc-h1"></ol> </nav> </body> </html> EOT - assert_equal expect, @output.string + assert_equal expect, output end def stage2 # add one item - @producer.contents << Content.new({ 'file' => 'ch01.html', 'title' => 'CH01', 'level' => 1 }) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch01.html', title: 'CH01', level: 1) end def test_stage2_add_l1item stage2 - expect = EPUBMaker::Content.new('ch01.html', - 'ch01-html', - 'application/xhtml+xml', - 'CH01', - 1) + expect = ReVIEW::EPUBMaker::Content.new(file: 'ch01.html', + id: 'ch01-html', + media: 'application/xhtml+xml', + title: 'CH01', + level: 1) assert_equal expect, @producer.contents[0] end def test_stage2_opf stage2 - @producer.opf(@output) + output = @producer.instance_eval { @epub.opf } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" xml:lang="en"> <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf"> <dc:title id="title">Sample Book</dc:title> @@ -220,16 +222,16 @@ <reference type="cover" title="Cover" href="sample.html"/> <reference type="toc" title="Table of Contents" href="sample-toc.html"/> </guide> </package> EOT - assert_equal expect, @output.string + assert_equal expect, output end def test_stage2_ncx stage2 - @producer.ncx(@output) + output = @producer.instance_eval { @epub.ncx([]) } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <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"> <head> @@ -244,66 +246,66 @@ <ol class="toc-h1"><li><a href="ch01.html">CH01</a></li> </ol> </nav> </body> </html> EOT - assert_equal expect, @output.string + assert_equal expect, output end def stage3 # add more items - @producer.contents << Content.new({ 'file' => 'ch01.html', 'title' => %Q(CH01<>&"), 'level' => 1 }) - @producer.contents << Content.new({ 'file' => 'ch02.html', 'title' => 'CH02', 'level' => 1 }) - @producer.contents << Content.new({ 'file' => 'ch02.html#S1', 'title' => 'CH02.1', 'level' => 2 }) - @producer.contents << Content.new({ 'file' => 'ch02.html#S1.1', 'title' => 'CH02.1.1', 'level' => 3 }) - @producer.contents << Content.new({ 'file' => 'ch02.html#S1.1.1', 'title' => 'CH02.1.1.1', 'level' => 4 }) - @producer.contents << Content.new({ 'file' => 'ch02.html#S1.1.1.1', 'title' => 'CH02.1.1.1.1', 'level' => 5 }) - @producer.contents << Content.new({ 'file' => 'ch02.html#S1.1.2', 'title' => 'CH02.1.1.2', 'level' => 4 }) - @producer.contents << Content.new({ 'file' => 'ch02.html#S2', 'title' => 'CH02.2', 'level' => 2 }) - @producer.contents << Content.new({ 'file' => 'ch02.html#S2.1', 'title' => 'CH02.2.1', 'level' => 3 }) - @producer.contents << Content.new({ 'file' => 'ch03.html', 'title' => 'CH03', 'level' => 1, 'properties' => ['mathml'] }) - @producer.contents << Content.new({ 'file' => 'ch03.html#S1', 'title' => 'CH03.1', 'level' => 2 }) - @producer.contents << Content.new({ 'file' => 'ch03.html#S1.1', 'title' => 'CH03.1.1', 'level' => 3 }) - @producer.contents << Content.new({ 'file' => 'ch04.html', 'title' => 'CH04', 'level' => 1 }) - @producer.contents << Content.new({ 'file' => 'sample.png' }) - @producer.contents << Content.new({ 'file' => 'sample.jpg' }) - @producer.contents << Content.new({ 'file' => 'sample.JPEG' }) - @producer.contents << Content.new({ 'file' => 'sample.SvG' }) - @producer.contents << Content.new({ 'file' => 'sample.GIF' }) - @producer.contents << Content.new({ 'file' => 'sample.css' }) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch01.html', title: %Q(CH01<>&"), level: 1) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html', title: 'CH02', level: 1) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1', title: 'CH02.1', level: 2) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1', title: 'CH02.1.1', level: 3) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.1', title: 'CH02.1.1.1', level: 4) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.1.1', title: 'CH02.1.1.1.1', level: 5) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.2', title: 'CH02.1.1.2', level: 4) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2', title: 'CH02.2', level: 2) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2.1', title: 'CH02.2.1', level: 3) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch03.html', title: 'CH03', level: 1, properties: ['mathml']) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1', title: 'CH03.1', level: 2) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1.1', title: 'CH03.1.1', level: 3) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'ch04.html', title: 'CH04', level: 1) + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.png') + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.jpg') + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.JPEG') + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.SvG') + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.GIF') + @producer.contents << ReVIEW::EPUBMaker::Content.new(file: 'sample.css') end def test_stage3_add_various_items stage3 expect = [ - Content.new('ch01.html', 'ch01-html', 'application/xhtml+xml', %Q(CH01<>&"), 1), - Content.new('ch02.html', 'ch02-html', 'application/xhtml+xml', 'CH02', 1), - Content.new('ch02.html#S1', 'ch02-html#S1', 'html#s1', 'CH02.1', 2), - Content.new('ch02.html#S1.1', 'ch02-html#S1-1', '1', 'CH02.1.1', 3), - Content.new('ch02.html#S1.1.1', 'ch02-html#S1-1-1', '1', 'CH02.1.1.1', 4), - Content.new('ch02.html#S1.1.1.1', 'ch02-html#S1-1-1-1', '1', 'CH02.1.1.1.1', 5), - Content.new('ch02.html#S1.1.2', 'ch02-html#S1-1-2', '2', 'CH02.1.1.2', 4), - Content.new('ch02.html#S2', 'ch02-html#S2', 'html#s2', 'CH02.2', 2), - Content.new('ch02.html#S2.1', 'ch02-html#S2-1', '1', 'CH02.2.1', 3), - Content.new('ch03.html', 'ch03-html', 'application/xhtml+xml', 'CH03', 1, nil, ['mathml']), - Content.new('ch03.html#S1', 'ch03-html#S1', 'html#s1', 'CH03.1', 2), - Content.new('ch03.html#S1.1', 'ch03-html#S1-1', '1', 'CH03.1.1', 3), - Content.new('ch04.html', 'ch04-html', 'application/xhtml+xml', 'CH04', 1), - Content.new('sample.png', 'sample-png', 'image/png'), - Content.new('sample.jpg', 'sample-jpg', 'image/jpeg'), - Content.new('sample.JPEG', 'sample-JPEG', 'image/jpeg'), - Content.new('sample.SvG', 'sample-SvG', 'image/svg+xml'), - Content.new('sample.GIF', 'sample-GIF', 'image/gif'), - Content.new('sample.css', 'sample-css', 'text/css') + ReVIEW::EPUBMaker::Content.new(file: 'ch01.html', id: 'ch01-html', media: 'application/xhtml+xml', title: %Q(CH01<>&"), level: 1), + ReVIEW::EPUBMaker::Content.new(file: 'ch02.html', id: 'ch02-html', media: 'application/xhtml+xml', title: 'CH02', level: 1), + ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1', id: 'ch02-html#S1', media: 'html#s1', title: 'CH02.1', level: 2), + ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1', id: 'ch02-html#S1-1', media: '1', title: 'CH02.1.1', level: 3), + ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.1', id: 'ch02-html#S1-1-1', media: '1', title: 'CH02.1.1.1', level: 4), + ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.1.1', id: 'ch02-html#S1-1-1-1', media: '1', title: 'CH02.1.1.1.1', level: 5), + ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S1.1.2', id: 'ch02-html#S1-1-2', media: '2', title: 'CH02.1.1.2', level: 4), + ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2', id: 'ch02-html#S2', media: 'html#s2', title: 'CH02.2', level: 2), + ReVIEW::EPUBMaker::Content.new(file: 'ch02.html#S2.1', id: 'ch02-html#S2-1', media: '1', title: 'CH02.2.1', level: 3), + ReVIEW::EPUBMaker::Content.new(file: 'ch03.html', id: 'ch03-html', media: 'application/xhtml+xml', title: 'CH03', level: 1, properties: ['mathml']), + ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1', id: 'ch03-html#S1', media: 'html#s1', title: 'CH03.1', level: 2), + ReVIEW::EPUBMaker::Content.new(file: 'ch03.html#S1.1', id: 'ch03-html#S1-1', media: '1', title: 'CH03.1.1', level: 3), + ReVIEW::EPUBMaker::Content.new(file: 'ch04.html', id: 'ch04-html', media: 'application/xhtml+xml', title: 'CH04', level: 1), + ReVIEW::EPUBMaker::Content.new(file: 'sample.png', id: 'sample-png', media: 'image/png'), + ReVIEW::EPUBMaker::Content.new(file: 'sample.jpg', id: 'sample-jpg', media: 'image/jpeg'), + ReVIEW::EPUBMaker::Content.new(file: 'sample.JPEG', id: 'sample-JPEG', media: 'image/jpeg'), + ReVIEW::EPUBMaker::Content.new(file: 'sample.SvG', id: 'sample-SvG', media: 'image/svg+xml'), + ReVIEW::EPUBMaker::Content.new(file: 'sample.GIF', id: 'sample-GIF', media: 'image/gif'), + ReVIEW::EPUBMaker::Content.new(file: 'sample.css', id: 'sample-css', media: 'text/css') ] assert_equal expect, @producer.contents end def test_stage3_opf stage3 - @producer.opf(@output) + output = @producer.instance_eval { @epub.opf } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" xml:lang="en"> <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf"> <dc:title id="title">Sample Book</dc:title> @@ -337,16 +339,17 @@ <reference type="cover" title="Cover" href="sample.html"/> <reference type="toc" title="Table of Contents" href="sample-toc.html"/> </guide> </package> EOT - assert_equal expect, @output.string + assert_equal expect, output end def test_stage3_ncx stage3 - @producer.ncx(@output) + @producer.config['toclevel'] = 2 + output = @producer.instance_eval { @epub.ncx([]) } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <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"> <head> @@ -369,16 +372,17 @@ <li><a href="ch04.html">CH04</a></li> </ol> </nav> </body> </html> EOT - assert_equal expect, @output.string + assert_equal expect, output end def test_stage3_mytoc stage3 - @producer.mytoc(@output) + @producer.config['toclevel'] = 2 + output = @producer.instance_eval { @epub.mytoc } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <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"> <head> @@ -399,17 +403,21 @@ </ul></li> <li><a href="ch04.html">CH04</a></li> </ul></body> </html> EOT - assert_equal expect, @output.string + assert_equal expect, output end def test_stage3_flat - @producer.merge_config('epubmaker' => { 'flattoc' => true, 'flattocindent' => false }) + @producer.config.deep_merge!( + 'toclevel' => 2, + 'epubmaker' => { 'flattoc' => true, 'flattocindent' => false } + ) + @producer.modify_config stage3 - @producer.mytoc(@output) + output = @producer.instance_eval { @epub.mytoc } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <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"> <head> @@ -429,16 +437,16 @@ <li><a href="ch04.html">CH04</a></li> </ul> </body> </html> EOT - assert_equal expect, @output.string + assert_equal expect, output end def test_stage3_cover stage3 - @producer.cover(@output) + output = @producer.instance_eval { @epub.cover } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <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"> <head> @@ -449,17 +457,18 @@ <body epub:type="cover"> <h1 class="cover-title">Sample Book</h1> </body> </html> EOT - assert_equal expect, @output.string + assert_equal expect, output end def test_stage3_cover_with_image stage3 @producer.config['coverimage'] = 'sample.png' - @producer.cover(@output) + @producer.modify_config + output = @producer.instance_eval { @epub.cover } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <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"> <head> @@ -472,17 +481,18 @@ <img src="sample.png" alt="Sample Book" class="max"/> </div> </body> </html> EOT - assert_equal expect, @output.string + assert_equal expect, output end def test_colophon_default - @producer.config['aut'] = ['Mr.Smith'] - @producer.config['pbl'] = ['BLUEPRINT'] - @producer.colophon(@output) + @producer.config.merge!('aut' => ['Mr.Smith'], + 'pbl' => ['BLUEPRINT']) + @producer.modify_config + output = @producer.instance_eval { @epub.colophon } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <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"> <head> @@ -502,18 +512,19 @@ </table> </div> </body> </html> EOT - assert_equal expect, @output.string + assert_equal expect, output end def test_colophon_pht - @producer.config['aut'] = ['Mr.Smith'] - @producer.config['pbl'] = ['BLUEPRINT'] - @producer.config['pht'] = ['Mrs.Smith'] - @producer.colophon(@output) + @producer.config.merge!('aut' => ['Mr.Smith'], + 'pbl' => ['BLUEPRINT'], + 'pht' => ['Mrs.Smith']) + @producer.modify_config + output = @producer.instance_eval { @epub.colophon } expect = <<EOT <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <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"> <head> @@ -534,35 +545,35 @@ </table> </div> </body> </html> EOT - assert_equal expect, @output.string + assert_equal expect, output end def test_colophon_history - @producer.config['aut'] = ['Mr.Smith'] - @producer.config['pbl'] = ['BLUEPRINT'] - @producer.config['pht'] = ['Mrs.Smith'] - @producer.merge_config('language' => 'ja') + @producer.config.merge!('aut' => 'Mr.Smith', + 'pbl' => 'BLUEPRINT', + 'pht' => 'Mrs.Smith', + 'language' => 'ja') + @producer.modify_config history = @producer.instance_eval { @epub.colophon_history } expect = <<EOT <div class="pubhistory"> <p>2011年1月1日 発行</p> </div> EOT assert_equal expect, history end def test_colophon_history_2 - @producer.config['aut'] = ['Mr.Smith'] - @producer.config['pbl'] = ['BLUEPRINT'] - @producer.config['pht'] = ['Mrs.Smith'] - @producer.merge_config( - 'language' => 'ja', - 'history' => [['2011-08-03 v1.0.0版発行', '2012-02-15 v1.1.0版発行']] - ) + @producer.config.merge!('aut' => ['Mr.Smith'], + 'pbl' => ['BLUEPRINT'], + 'pht' => ['Mrs.Smith'], + 'language' => 'ja', + 'history' => [['2011-08-03 v1.0.0版発行', '2012-02-15 v1.1.0版発行']]) + @producer.modify_config history = @producer.instance_eval { @epub.colophon_history } expect = <<EOT <div class="pubhistory"> <p>2011年8月3日 v1.0.0版発行</p> <p>2012年2月15日 v1.1.0版発行</p> @@ -570,17 +581,16 @@ EOT assert_equal expect, history end def test_colophon_history_date - @producer.config['aut'] = ['Mr.Smith'] - @producer.config['pbl'] = ['BLUEPRINT'] - @producer.config['pht'] = ['Mrs.Smith'] - @producer.merge_config( - 'language' => 'ja', - 'history' => [['2011-08-03', '2012-02-15']] - ) + @producer.config.merge!('aut' => ['Mr.Smith'], + 'pbl' => ['BLUEPRINT'], + 'pht' => ['Mrs.Smith'], + 'language' => 'ja', + 'history' => [['2011-08-03', '2012-02-15']]) + @producer.modify_config history = @producer.instance_eval { @epub.colophon_history } expect = <<EOT <div class="pubhistory"> <p>2011年8月3日 初版第1刷 発行</p> <p>2012年2月15日 初版第2刷 発行</p> @@ -588,19 +598,18 @@ EOT assert_equal expect, history end def test_colophon_history_date2 - @producer.config['aut'] = ['Mr.Smith'] - @producer.config['pbl'] = ['BLUEPRINT'] - @producer.config['pht'] = ['Mrs.Smith'] - @producer.merge_config( - 'language' => 'ja', - 'history' => [['2011-08-03', '2012-02-15'], - ['2012-10-01'], - ['2013-03-01']] - ) + @producer.config.merge!('aut' => ['Mr.Smith'], + 'pbl' => ['BLUEPRINT'], + 'pht' => ['Mrs.Smith'], + 'language' => 'ja', + 'history' => [['2011-08-03', '2012-02-15'], + ['2012-10-01'], + ['2013-03-01']]) + @producer.modify_config history = @producer.instance_eval { @epub.colophon_history } expect = <<EOT <div class="pubhistory"> <p>2011年8月3日 初版第1刷 発行</p> <p>2012年2月15日 初版第2刷 発行</p> @@ -683,7 +692,42 @@ large.jpg: 250x150 exceeds a limit. suggeted value is 95x57 large.png: 250x150 exceeds a limit. suggeted value is 95x57 large.svg: 250x150 exceeds a limit. suggeted value is 95x57 EOS assert_equal expected, err + end + + def test_build_part + Dir.mktmpdir do |tmpdir| + book = ReVIEW::Book::Base.new + book.catalog = ReVIEW::Catalog.new('CHAPS' => %w[ch1.re]) + io1 = StringIO.new("//list[sampletest][a]{\nfoo\n//}\n") + chap1 = ReVIEW::Book::Chapter.new(book, 1, 'ch1', 'ch1.re', io1) + part1 = ReVIEW::Book::Part.new(book, 1, [chap1]) + book.parts = [part1] + epubmaker = ReVIEW::EPUBMaker.new + epubmaker.instance_eval do + @config = book.config + @producer = ReVIEW::EPUBMaker::Producer.new(@config) + end + epubmaker.build_part(part1, tmpdir, 'part1.html') + + expected = <<-EOB +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html> +<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="ja"> +<head> + <meta charset="UTF-8" /> + <meta name="generator" content="Re:VIEW" /> + <title></title> +</head> +<body> +<div class="part"> +<h1 class="part-number">第I部</h1> +</div> +</body> +</html> + EOB + assert_equal expected, File.read(File.join(tmpdir, 'part1.html')) + end end end