From 1a5a20791bfb85ca4f435e94d629a2da9878b421 Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Mon, 21 Dec 2020 11:14:31 +0900 Subject: [PATCH 1/6] Content.new takes only hash --- lib/epubmaker/content.rb | 32 +++++++++------------------ test/test_epub3maker.rb | 48 ++++++++++++++++++++-------------------- test/test_epubmaker.rb | 48 ++++++++++++++++++++-------------------- 3 files changed, 58 insertions(+), 70 deletions(-) diff --git a/lib/epubmaker/content.rb b/lib/epubmaker/content.rb index df0f4c8a2..67cf06ea8 100644 --- a/lib/epubmaker/content.rb +++ b/lib/epubmaker/content.rb @@ -34,31 +34,19 @@ def inspect end # :call-seq: - # initialize(file, id, media, title, level, notoc) # initialize(hash) # Construct Content object by passing a sequence of parameters or hash. # Keys of +hash+ relate with each parameters. - # +file+ (or +hash+["file"]) is required. Others are optional. - def initialize(fileorhash, id = nil, media = nil, title = nil, level = nil, notoc = nil, properties = nil, chaptype = nil) # rubocop:disable Metrics/ParameterLists - if fileorhash.instance_of?(Hash) - @id = fileorhash['id'] - @file = fileorhash['file'] - @media = fileorhash['media'] - @title = fileorhash['title'] - @level = fileorhash['level'] - @notoc = fileorhash['notoc'] - @properties = fileorhash['properties'] || [] - @chaptype = fileorhash['chaptype'] - else - @file = fileorhash - @id = id - @media = media - @title = title - @level = level - @notoc = notoc - @properties = properties || [] - @chaptype = chaptype - end + # +hash+['file'] is required. Others are optional. + def initialize(hash) + @id = hash['id'] + @file = hash['file'] + @media = hash['media'] + @title = hash['title'] + @level = hash['level'] + @notoc = hash['notoc'] + @properties = hash['properties'] || [] + @chaptype = hash['chaptype'] complement end diff --git a/test/test_epub3maker.rb b/test/test_epub3maker.rb index 4262d9ebe..c026ce636 100644 --- a/test/test_epub3maker.rb +++ b/test/test_epub3maker.rb @@ -186,11 +186,11 @@ def stage2 def test_stage2_add_l1item stage2 - expect = EPUBMaker::Content.new('ch01.html', - 'ch01-html', - 'application/xhtml+xml', - 'CH01', - 1) + expect = EPUBMaker::Content.new({ 'file' => 'ch01.html', + 'id' => 'ch01-html', + 'media' => 'application/xhtml+xml', + 'title' => 'CH01', + 'level' => 1 }) assert_equal expect, @producer.contents[0] end @@ -275,25 +275,25 @@ def stage3 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') + Content.new({ 'file' => 'ch01.html', 'id' => 'ch01-html', 'media' => 'application/xhtml+xml', 'title' => %Q(CH01<>&"), 'level' => 1 }), + Content.new({ 'file' => 'ch02.html', 'id' => 'ch02-html', 'media' => 'application/xhtml+xml', 'title' => 'CH02', 'level' => 1 }), + Content.new({ 'file' => 'ch02.html#S1', 'id' => 'ch02-html#S1', 'media' => 'html#s1', 'title' => 'CH02.1', 'level' => 2 }), + Content.new({ 'file' => 'ch02.html#S1.1', 'id' => 'ch02-html#S1-1', 'media' => '1', 'title' => 'CH02.1.1', 'level' => 3 }), + Content.new({ 'file' => 'ch02.html#S1.1.1', 'id' => 'ch02-html#S1-1-1', 'media' => '1', 'title' => 'CH02.1.1.1', 'level' => 4 }), + 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 }), + Content.new({ 'file' => 'ch02.html#S1.1.2', 'id' => 'ch02-html#S1-1-2', 'media' => '2', 'title' => 'CH02.1.1.2', 'level' => 4 }), + Content.new({ 'file' => 'ch02.html#S2', 'id' => 'ch02-html#S2', 'media' => 'html#s2', 'title' => 'CH02.2', 'level' => 2 }), + Content.new({ 'file' => 'ch02.html#S2.1', 'id' => 'ch02-html#S2-1', 'media' => '1', 'title' => 'CH02.2.1', 'level' => 3 }), + Content.new({ 'file' => 'ch03.html', 'id' => 'ch03-html', 'media' => 'application/xhtml+xml', 'title' => 'CH03', 'level' => 1, 'properties' => ['mathml'] }), + Content.new({ 'file' => 'ch03.html#S1', 'id' => 'ch03-html#S1', 'media' => 'html#s1', 'title' => 'CH03.1', 'level' => 2 }), + Content.new({ 'file' => 'ch03.html#S1.1', 'id' => 'ch03-html#S1-1', 'media' => '1', 'title' => 'CH03.1.1', 'level' => 3 }), + Content.new({ 'file' => 'ch04.html', 'id' => 'ch04-html', 'media' => 'application/xhtml+xml', 'title' => 'CH04', 'level' => 1 }), + Content.new({ 'file' => 'sample.png', 'id' => 'sample-png', 'media' => 'image/png' }), + Content.new({ 'file' => 'sample.jpg', 'id' => 'sample-jpg', 'media' => 'image/jpeg' }), + Content.new({ 'file' => 'sample.JPEG', 'id' => 'sample-JPEG', 'media' => 'image/jpeg' }), + Content.new({ 'file' => 'sample.SvG', 'id' => 'sample-SvG', 'media' => 'image/svg+xml' }), + Content.new({ 'file' => 'sample.GIF', 'id' => 'sample-GIF', 'media' => 'image/gif' }), + Content.new({ 'file' => 'sample.css', 'id' => 'sample-css', 'media' => 'text/css' }) ] assert_equal expect, @producer.contents diff --git a/test/test_epubmaker.rb b/test/test_epubmaker.rb index 07877935f..1e159d3f6 100644 --- a/test/test_epubmaker.rb +++ b/test/test_epubmaker.rb @@ -172,11 +172,11 @@ def stage2 def test_stage2_add_l1item stage2 - expect = EPUBMaker::Content.new('ch01.html', - 'ch01-html', - 'application/xhtml+xml', - 'CH01', - 1) + expect = EPUBMaker::Content.new({ 'file' => 'ch01.html', + 'id' => 'ch01-html', + 'media' => 'application/xhtml+xml', + 'title' => 'CH01', + 'level' => 1 }) assert_equal expect, @producer.contents[0] end @@ -272,25 +272,25 @@ def stage3 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), - 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') + Content.new({ 'file' => 'ch01.html', 'id' => 'ch01-html', 'media' => 'application/xhtml+xml', 'title' => %Q(CH01<>&"), 'level' => 1 }), + Content.new({ 'file' => 'ch02.html', 'id' => 'ch02-html', 'media' => 'application/xhtml+xml', 'title' => 'CH02', 'level' => 1 }), + Content.new({ 'file' => 'ch02.html#S1', 'id' => 'ch02-html#S1', 'media' => 'html#s1', 'title' => 'CH02.1', 'level' => 2 }), + Content.new({ 'file' => 'ch02.html#S1.1', 'id' => 'ch02-html#S1-1', 'media' => '1', 'title' => 'CH02.1.1', 'level' => 3 }), + Content.new({ 'file' => 'ch02.html#S1.1.1', 'id' => 'ch02-html#S1-1-1', 'media' => '1', 'title' => 'CH02.1.1.1', 'level' => 4 }), + 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 }), + Content.new({ 'file' => 'ch02.html#S1.1.2', 'id' => 'ch02-html#S1-1-2', 'media' => '2', 'title' => 'CH02.1.1.2', 'level' => 4 }), + Content.new({ 'file' => 'ch02.html#S2', 'id' => 'ch02-html#S2', 'media' => 'html#s2', 'title' => 'CH02.2', 'level' => 2 }), + Content.new({ 'file' => 'ch02.html#S2.1', 'id' => 'ch02-html#S2-1', 'media' => '1', 'title' => 'CH02.2.1', 'level' => 3 }), + Content.new({ 'file' => 'ch03.html', 'id' => 'ch03-html', 'media' => 'application/xhtml+xml', 'title' => 'CH03', 'level' => 1 }), + Content.new({ 'file' => 'ch03.html#S1', 'id' => 'ch03-html#S1', 'media' => 'html#s1', 'title' => 'CH03.1', 'level' => 2 }), + Content.new({ 'file' => 'ch03.html#S1.1', 'id' => 'ch03-html#S1-1', 'media' => '1', 'title' => 'CH03.1.1', 'level' => 3 }), + Content.new({ 'file' => 'ch04.html', 'id' => 'ch04-html', 'media' => 'application/xhtml+xml', 'title' => 'CH04', 'level' => 1 }), + Content.new({ 'file' => 'sample.png', 'id' => 'sample-png', 'media' => 'image/png' }), + Content.new({ 'file' => 'sample.jpg', 'id' => 'sample-jpg', 'media' => 'image/jpeg' }), + Content.new({ 'file' => 'sample.JPEG', 'id' => 'sample-JPEG', 'media' => 'image/jpeg' }), + Content.new({ 'file' => 'sample.SvG', 'id' => 'sample-SvG', 'media' => 'image/svg+xml' }), + Content.new({ 'file' => 'sample.GIF', 'id' => 'sample-GIF', 'media' => 'image/gif' }), + Content.new({ 'file' => 'sample.css', 'id' => 'sample-css', 'media' => 'text/css' }) ] assert_equal expect, @producer.contents From e2dce6bb340c701c92447ab8ef72adf2d5acd6b3 Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Mon, 21 Dec 2020 18:11:22 +0900 Subject: [PATCH 2/6] change to named parameter --- lib/epubmaker.rb | 4 +- lib/epubmaker/content.rb | 25 +++++------ lib/epubmaker/producer.rb | 4 +- lib/review/epubmaker.rb | 18 ++++---- test/test_epub3maker.rb | 88 ++++++++++++++++++------------------- test/test_epubmaker.rb | 92 +++++++++++++++++++-------------------- 6 files changed, 115 insertions(+), 116 deletions(-) diff --git a/lib/epubmaker.rb b/lib/epubmaker.rb index f7e642c69..145ce0469 100644 --- a/lib/epubmaker.rb +++ b/lib/epubmaker.rb @@ -11,8 +11,8 @@ # require 'epubmaker' # producer = EPUBMaker::Producer.new # config = producer.load("config.yml") -# producer.contents.push(EPUBMaker::Content.new({"file" => "ch01.xhtml"})) -# producer.contents.push(EPUBMaker::Content.new({"file" => "ch02.xhtml"})) +# producer.contents.push(EPUBMaker::Content.new({file: "ch01.xhtml"})) +# producer.contents.push(EPUBMaker::Content.new({file: "ch02.xhtml"})) # ... # producer.import_imageinfo("images") # producer.produce diff --git a/lib/epubmaker/content.rb b/lib/epubmaker/content.rb index 67cf06ea8..4bfa98276 100644 --- a/lib/epubmaker/content.rb +++ b/lib/epubmaker/content.rb @@ -34,19 +34,18 @@ def inspect end # :call-seq: - # initialize(hash) - # Construct Content object by passing a sequence of parameters or hash. - # Keys of +hash+ relate with each parameters. - # +hash+['file'] is required. Others are optional. - def initialize(hash) - @id = hash['id'] - @file = hash['file'] - @media = hash['media'] - @title = hash['title'] - @level = hash['level'] - @notoc = hash['notoc'] - @properties = hash['properties'] || [] - @chaptype = hash['chaptype'] + # initialize(params) + # Construct Content object by passing named parameters. + # +params+[:file] is required. Others are optional. + def initialize(params) + @id = params[:id] + @file = params[:file] + @media = params[:media] + @title = params[:title] + @level = params[:level] + @notoc = params[:notoc] + @properties = params[:properties] || [] + @chaptype = params[:chaptype] complement end diff --git a/lib/epubmaker/producer.rb b/lib/epubmaker/producer.rb index 6fa8d622d..c3dbf316d 100644 --- a/lib/epubmaker/producer.rb +++ b/lib/epubmaker/producer.rb @@ -172,9 +172,9 @@ def import_imageinfo(path, base = nil, allow_exts = nil) if f =~ /\.(#{allow_exts.join('|')})\Z/i path.chop! if path =~ %r{/\Z} if base.nil? - @contents.push(EPUBMaker::Content.new('file' => "#{path}/#{f}")) + @contents.push(EPUBMaker::Content.new(file: "#{path}/#{f}")) else - @contents.push(EPUBMaker::Content.new('file' => "#{path.sub(base + '/', '')}/#{f}")) + @contents.push(EPUBMaker::Content.new(file: "#{path.sub(base + '/', '')}/#{f}")) end end if FileTest.directory?("#{path}/#{f}") diff --git a/lib/review/epubmaker.rb b/lib/review/epubmaker.rb index 6935a9f40..8afa80bc0 100644 --- a/lib/review/epubmaker.rb +++ b/lib/review/epubmaker.rb @@ -482,20 +482,20 @@ def push_contents(_basetmpdir) next if level.to_i > @config['toclevel'] && args[:force_include].nil? log("Push #{file} to ePUB contents.") - hash = { 'file' => file, - 'level' => level.to_i, - 'title' => title, - 'chaptype' => args[:chaptype] } + params = { file: file, + level: level.to_i, + title: title, + chaptype: args[:chaptype] } if args[:id].present? - hash['id'] = args[:id] + params[:id] = args[:id] end if args[:properties].present? - hash['properties'] = args[:properties].split(' ') # rubocop:disable Style/RedundantArgument + params[:properties] = args[:properties].split(' ') # rubocop:disable Style/RedundantArgument end if args[:notoc].present? - hash['notoc'] = args[:notoc] + params[:notoc] = args[:notoc] end - @producer.contents.push(Content.new(hash)) + @producer.contents.push(Content.new(params)) end end @@ -506,7 +506,7 @@ def copy_stylesheet(basetmpdir) error "#{sfile} is not found." end FileUtils.cp(sfile, basetmpdir) - @producer.contents.push(Content.new('file' => sfile)) + @producer.contents.push(Content.new(file: sfile)) end end diff --git a/test/test_epub3maker.rb b/test/test_epub3maker.rb index c026ce636..710aa4d80 100644 --- a/test/test_epub3maker.rb +++ b/test/test_epub3maker.rb @@ -181,16 +181,16 @@ def test_stage1_ncx def stage2 # add one item - @producer.contents << Content.new({ 'file' => 'ch01.html', 'title' => 'CH01', 'level' => 1 }) + @producer.contents << Content.new({ file: 'ch01.html', title: 'CH01', level: 1 }) end def test_stage2_add_l1item stage2 - expect = EPUBMaker::Content.new({ 'file' => 'ch01.html', - 'id' => 'ch01-html', - 'media' => 'application/xhtml+xml', - 'title' => 'CH01', - 'level' => 1 }) + expect = EPUBMaker::Content.new({ file: 'ch01.html', + id: 'ch01-html', + media: 'application/xhtml+xml', + title: 'CH01', + level: 1 }) assert_equal expect, @producer.contents[0] end @@ -251,49 +251,49 @@ def test_stage2_ncx 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 << 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' }) end def test_stage3_add_various_items stage3 expect = [ - Content.new({ 'file' => 'ch01.html', 'id' => 'ch01-html', 'media' => 'application/xhtml+xml', 'title' => %Q(CH01<>&"), 'level' => 1 }), - Content.new({ 'file' => 'ch02.html', 'id' => 'ch02-html', 'media' => 'application/xhtml+xml', 'title' => 'CH02', 'level' => 1 }), - Content.new({ 'file' => 'ch02.html#S1', 'id' => 'ch02-html#S1', 'media' => 'html#s1', 'title' => 'CH02.1', 'level' => 2 }), - Content.new({ 'file' => 'ch02.html#S1.1', 'id' => 'ch02-html#S1-1', 'media' => '1', 'title' => 'CH02.1.1', 'level' => 3 }), - Content.new({ 'file' => 'ch02.html#S1.1.1', 'id' => 'ch02-html#S1-1-1', 'media' => '1', 'title' => 'CH02.1.1.1', 'level' => 4 }), - 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 }), - Content.new({ 'file' => 'ch02.html#S1.1.2', 'id' => 'ch02-html#S1-1-2', 'media' => '2', 'title' => 'CH02.1.1.2', 'level' => 4 }), - Content.new({ 'file' => 'ch02.html#S2', 'id' => 'ch02-html#S2', 'media' => 'html#s2', 'title' => 'CH02.2', 'level' => 2 }), - Content.new({ 'file' => 'ch02.html#S2.1', 'id' => 'ch02-html#S2-1', 'media' => '1', 'title' => 'CH02.2.1', 'level' => 3 }), - Content.new({ 'file' => 'ch03.html', 'id' => 'ch03-html', 'media' => 'application/xhtml+xml', 'title' => 'CH03', 'level' => 1, 'properties' => ['mathml'] }), - Content.new({ 'file' => 'ch03.html#S1', 'id' => 'ch03-html#S1', 'media' => 'html#s1', 'title' => 'CH03.1', 'level' => 2 }), - Content.new({ 'file' => 'ch03.html#S1.1', 'id' => 'ch03-html#S1-1', 'media' => '1', 'title' => 'CH03.1.1', 'level' => 3 }), - Content.new({ 'file' => 'ch04.html', 'id' => 'ch04-html', 'media' => 'application/xhtml+xml', 'title' => 'CH04', 'level' => 1 }), - Content.new({ 'file' => 'sample.png', 'id' => 'sample-png', 'media' => 'image/png' }), - Content.new({ 'file' => 'sample.jpg', 'id' => 'sample-jpg', 'media' => 'image/jpeg' }), - Content.new({ 'file' => 'sample.JPEG', 'id' => 'sample-JPEG', 'media' => 'image/jpeg' }), - Content.new({ 'file' => 'sample.SvG', 'id' => 'sample-SvG', 'media' => 'image/svg+xml' }), - Content.new({ 'file' => 'sample.GIF', 'id' => 'sample-GIF', 'media' => 'image/gif' }), - Content.new({ 'file' => 'sample.css', 'id' => 'sample-css', 'media' => 'text/css' }) + Content.new({ file: 'ch01.html', id: 'ch01-html', media: 'application/xhtml+xml', title: %Q(CH01<>&"), level: 1 }), + Content.new({ file: 'ch02.html', id: 'ch02-html', media: 'application/xhtml+xml', title: 'CH02', level: 1 }), + Content.new({ file: 'ch02.html#S1', id: 'ch02-html#S1', media: 'html#s1', title: 'CH02.1', level: 2 }), + Content.new({ file: 'ch02.html#S1.1', id: 'ch02-html#S1-1', media: '1', title: 'CH02.1.1', level: 3 }), + Content.new({ file: 'ch02.html#S1.1.1', id: 'ch02-html#S1-1-1', media: '1', title: 'CH02.1.1.1', level: 4 }), + 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 }), + Content.new({ file: 'ch02.html#S1.1.2', id: 'ch02-html#S1-1-2', media: '2', title: 'CH02.1.1.2', level: 4 }), + Content.new({ file: 'ch02.html#S2', id: 'ch02-html#S2', media: 'html#s2', title: 'CH02.2', level: 2 }), + Content.new({ file: 'ch02.html#S2.1', id: 'ch02-html#S2-1', media: '1', title: 'CH02.2.1', level: 3 }), + Content.new({ file: 'ch03.html', id: 'ch03-html', media: 'application/xhtml+xml', title: 'CH03', level: 1, properties: ['mathml'] }), + Content.new({ file: 'ch03.html#S1', id: 'ch03-html#S1', media: 'html#s1', title: 'CH03.1', level: 2 }), + Content.new({ file: 'ch03.html#S1.1', id: 'ch03-html#S1-1', media: '1', title: 'CH03.1.1', level: 3 }), + Content.new({ file: 'ch04.html', id: 'ch04-html', media: 'application/xhtml+xml', title: 'CH04', level: 1 }), + Content.new({ file: 'sample.png', id: 'sample-png', media: 'image/png' }), + Content.new({ file: 'sample.jpg', id: 'sample-jpg', media: 'image/jpeg' }), + Content.new({ file: 'sample.JPEG', id: 'sample-JPEG', media: 'image/jpeg' }), + Content.new({ file: 'sample.SvG', id: 'sample-SvG', media: 'image/svg+xml' }), + Content.new({ file: 'sample.GIF', id: 'sample-GIF', media: 'image/gif' }), + Content.new({ file: 'sample.css', id: 'sample-css', media: 'text/css' }) ] assert_equal expect, @producer.contents diff --git a/test/test_epubmaker.rb b/test/test_epubmaker.rb index 1e159d3f6..4670ce1ad 100644 --- a/test/test_epubmaker.rb +++ b/test/test_epubmaker.rb @@ -167,16 +167,16 @@ def test_stage1_ncx_escape def stage2 # add one item - @producer.contents << Content.new({ 'file' => 'ch01.html', 'title' => 'CH01', 'level' => 1 }) + @producer.contents << Content.new({ file: 'ch01.html', title: 'CH01', level: 1 }) end def test_stage2_add_l1item stage2 - expect = EPUBMaker::Content.new({ 'file' => 'ch01.html', - 'id' => 'ch01-html', - 'media' => 'application/xhtml+xml', - 'title' => 'CH01', - 'level' => 1 }) + expect = EPUBMaker::Content.new({ file: 'ch01.html', + id: 'ch01-html', + media: 'application/xhtml+xml', + title: 'CH01', + level: 1 }) assert_equal expect, @producer.contents[0] end @@ -248,49 +248,49 @@ def test_stage2_ncx 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 }) - @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 << 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 }) + @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' }) end def test_stage3_add_various_items stage3 expect = [ - Content.new({ 'file' => 'ch01.html', 'id' => 'ch01-html', 'media' => 'application/xhtml+xml', 'title' => %Q(CH01<>&"), 'level' => 1 }), - Content.new({ 'file' => 'ch02.html', 'id' => 'ch02-html', 'media' => 'application/xhtml+xml', 'title' => 'CH02', 'level' => 1 }), - Content.new({ 'file' => 'ch02.html#S1', 'id' => 'ch02-html#S1', 'media' => 'html#s1', 'title' => 'CH02.1', 'level' => 2 }), - Content.new({ 'file' => 'ch02.html#S1.1', 'id' => 'ch02-html#S1-1', 'media' => '1', 'title' => 'CH02.1.1', 'level' => 3 }), - Content.new({ 'file' => 'ch02.html#S1.1.1', 'id' => 'ch02-html#S1-1-1', 'media' => '1', 'title' => 'CH02.1.1.1', 'level' => 4 }), - 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 }), - Content.new({ 'file' => 'ch02.html#S1.1.2', 'id' => 'ch02-html#S1-1-2', 'media' => '2', 'title' => 'CH02.1.1.2', 'level' => 4 }), - Content.new({ 'file' => 'ch02.html#S2', 'id' => 'ch02-html#S2', 'media' => 'html#s2', 'title' => 'CH02.2', 'level' => 2 }), - Content.new({ 'file' => 'ch02.html#S2.1', 'id' => 'ch02-html#S2-1', 'media' => '1', 'title' => 'CH02.2.1', 'level' => 3 }), - Content.new({ 'file' => 'ch03.html', 'id' => 'ch03-html', 'media' => 'application/xhtml+xml', 'title' => 'CH03', 'level' => 1 }), - Content.new({ 'file' => 'ch03.html#S1', 'id' => 'ch03-html#S1', 'media' => 'html#s1', 'title' => 'CH03.1', 'level' => 2 }), - Content.new({ 'file' => 'ch03.html#S1.1', 'id' => 'ch03-html#S1-1', 'media' => '1', 'title' => 'CH03.1.1', 'level' => 3 }), - Content.new({ 'file' => 'ch04.html', 'id' => 'ch04-html', 'media' => 'application/xhtml+xml', 'title' => 'CH04', 'level' => 1 }), - Content.new({ 'file' => 'sample.png', 'id' => 'sample-png', 'media' => 'image/png' }), - Content.new({ 'file' => 'sample.jpg', 'id' => 'sample-jpg', 'media' => 'image/jpeg' }), - Content.new({ 'file' => 'sample.JPEG', 'id' => 'sample-JPEG', 'media' => 'image/jpeg' }), - Content.new({ 'file' => 'sample.SvG', 'id' => 'sample-SvG', 'media' => 'image/svg+xml' }), - Content.new({ 'file' => 'sample.GIF', 'id' => 'sample-GIF', 'media' => 'image/gif' }), - Content.new({ 'file' => 'sample.css', 'id' => 'sample-css', 'media' => 'text/css' }) + Content.new({ file: 'ch01.html', id: 'ch01-html', media: 'application/xhtml+xml', title: %Q(CH01<>&"), level: 1 }), + Content.new({ file: 'ch02.html', id: 'ch02-html', media: 'application/xhtml+xml', title: 'CH02', level: 1 }), + Content.new({ file: 'ch02.html#S1', id: 'ch02-html#S1', media: 'html#s1', title: 'CH02.1', level: 2 }), + Content.new({ file: 'ch02.html#S1.1', id: 'ch02-html#S1-1', media: '1', title: 'CH02.1.1', level: 3 }), + Content.new({ file: 'ch02.html#S1.1.1', id: 'ch02-html#S1-1-1', media: '1', title: 'CH02.1.1.1', level: 4 }), + 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 }), + Content.new({ file: 'ch02.html#S1.1.2', id: 'ch02-html#S1-1-2', media: '2', title: 'CH02.1.1.2', level: 4 }), + Content.new({ file: 'ch02.html#S2', id: 'ch02-html#S2', media: 'html#s2', title: 'CH02.2', level: 2 }), + Content.new({ file: 'ch02.html#S2.1', id: 'ch02-html#S2-1', media: '1', title: 'CH02.2.1', level: 3 }), + Content.new({ file: 'ch03.html', id: 'ch03-html', media: 'application/xhtml+xml', title: 'CH03', level: 1 }), + Content.new({ file: 'ch03.html#S1', id: 'ch03-html#S1', media: 'html#s1', title: 'CH03.1', level: 2 }), + Content.new({ file: 'ch03.html#S1.1', id: 'ch03-html#S1-1', media: '1', title: 'CH03.1.1', level: 3 }), + Content.new({ file: 'ch04.html', id: 'ch04-html', media: 'application/xhtml+xml', title: 'CH04', level: 1 }), + Content.new({ file: 'sample.png', id: 'sample-png', media: 'image/png' }), + Content.new({ file: 'sample.jpg', id: 'sample-jpg', media: 'image/jpeg' }), + Content.new({ file: 'sample.JPEG', id: 'sample-JPEG', media: 'image/jpeg' }), + Content.new({ file: 'sample.SvG', id: 'sample-SvG', media: 'image/svg+xml' }), + Content.new({ file: 'sample.GIF', id: 'sample-GIF', media: 'image/gif' }), + Content.new({ file: 'sample.css', id: 'sample-css', media: 'text/css' }) ] assert_equal expect, @producer.contents @@ -821,9 +821,9 @@ def test_title_single_value_param end def test_epub_unsafe_id - content = Content.new({ 'file' => 'sample.png' }) + content = Content.new({ file: 'sample.png' }) assert_equal 'sample-png', content.id - content = Content.new({ 'file' => 'sample-&()-=+@:,漢字.png' }) + content = Content.new({ file: 'sample-&()-=+@:,漢字.png' }) assert_equal 'sample-_25_26_25_28_25_29-_25_3D_25_2B_25_40_25_3A_25_2C_25_E6_25_BC_25_A2_25_E5_25_AD_25_97-png', content.id end end From c61b23a1b3dc679581e08c367e6021997227c77c Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Mon, 21 Dec 2020 18:27:05 +0900 Subject: [PATCH 3/6] remove unnecessary curley brace --- lib/epubmaker.rb | 10 ++--- lib/epubmaker/content.rb | 18 ++++---- test/test_epub3maker.rb | 82 +++++++++++++++++------------------ test/test_epubmaker.rb | 92 ++++++++++++++++++++-------------------- 4 files changed, 101 insertions(+), 101 deletions(-) diff --git a/lib/epubmaker.rb b/lib/epubmaker.rb index 145ce0469..e8102f1df 100644 --- a/lib/epubmaker.rb +++ b/lib/epubmaker.rb @@ -1,6 +1,6 @@ # = epubmaker.rb -- EPUB production set. # -# Copyright (c) 2010-2017 Kenshi Muto +# Copyright (c) 2010-2020 Kenshi Muto # # This program is free software. # You can distribute or modify this program under the terms of @@ -10,11 +10,11 @@ # == Quick usage # require 'epubmaker' # producer = EPUBMaker::Producer.new -# config = producer.load("config.yml") -# producer.contents.push(EPUBMaker::Content.new({file: "ch01.xhtml"})) -# producer.contents.push(EPUBMaker::Content.new({file: "ch02.xhtml"})) +# config = producer.load('config.yml') +# producer.contents.push(EPUBMaker::Content.new(file: 'ch01.xhtml')) +# producer.contents.push(EPUBMaker::Content.new(file: 'ch02.xhtml')) # ... -# producer.import_imageinfo("images") +# producer.import_imageinfo('images') # producer.produce require 'epubmaker/producer' diff --git a/lib/epubmaker/content.rb b/lib/epubmaker/content.rb index 4bfa98276..d87d2b8e2 100644 --- a/lib/epubmaker/content.rb +++ b/lib/epubmaker/content.rb @@ -37,15 +37,15 @@ def inspect # initialize(params) # Construct Content object by passing named parameters. # +params+[:file] is required. Others are optional. - def initialize(params) - @id = params[:id] - @file = params[:file] - @media = params[:media] - @title = params[:title] - @level = params[:level] - @notoc = params[:notoc] - @properties = params[:properties] || [] - @chaptype = params[:chaptype] + def initialize(file:, id: nil, media: nil, title: nil, level: nil, notoc: nil, properties: nil, chaptype: nil) + @id = id + @file = file + @media = media + @title = title + @level = level + @notoc = notoc + @properties = properties || [] + @chaptype = chaptype complement end diff --git a/test/test_epub3maker.rb b/test/test_epub3maker.rb index 710aa4d80..69ff20fa2 100644 --- a/test/test_epub3maker.rb +++ b/test/test_epub3maker.rb @@ -181,16 +181,16 @@ def test_stage1_ncx def stage2 # add one item - @producer.contents << Content.new({ file: 'ch01.html', title: 'CH01', level: 1 }) + @producer.contents << Content.new(file: 'ch01.html', title: 'CH01', level: 1) end def test_stage2_add_l1item stage2 - expect = EPUBMaker::Content.new({ file: 'ch01.html', + expect = EPUBMaker::Content.new(file: 'ch01.html', id: 'ch01-html', media: 'application/xhtml+xml', title: 'CH01', - level: 1 }) + level: 1) assert_equal expect, @producer.contents[0] end @@ -251,49 +251,49 @@ def test_stage2_ncx 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 << 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') end def test_stage3_add_various_items stage3 expect = [ - Content.new({ file: 'ch01.html', id: 'ch01-html', media: 'application/xhtml+xml', title: %Q(CH01<>&"), level: 1 }), - Content.new({ file: 'ch02.html', id: 'ch02-html', media: 'application/xhtml+xml', title: 'CH02', level: 1 }), - Content.new({ file: 'ch02.html#S1', id: 'ch02-html#S1', media: 'html#s1', title: 'CH02.1', level: 2 }), - Content.new({ file: 'ch02.html#S1.1', id: 'ch02-html#S1-1', media: '1', title: 'CH02.1.1', level: 3 }), - Content.new({ file: 'ch02.html#S1.1.1', id: 'ch02-html#S1-1-1', media: '1', title: 'CH02.1.1.1', level: 4 }), - 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 }), - Content.new({ file: 'ch02.html#S1.1.2', id: 'ch02-html#S1-1-2', media: '2', title: 'CH02.1.1.2', level: 4 }), - Content.new({ file: 'ch02.html#S2', id: 'ch02-html#S2', media: 'html#s2', title: 'CH02.2', level: 2 }), - Content.new({ file: 'ch02.html#S2.1', id: 'ch02-html#S2-1', media: '1', title: 'CH02.2.1', level: 3 }), - Content.new({ file: 'ch03.html', id: 'ch03-html', media: 'application/xhtml+xml', title: 'CH03', level: 1, properties: ['mathml'] }), - Content.new({ file: 'ch03.html#S1', id: 'ch03-html#S1', media: 'html#s1', title: 'CH03.1', level: 2 }), - Content.new({ file: 'ch03.html#S1.1', id: 'ch03-html#S1-1', media: '1', title: 'CH03.1.1', level: 3 }), - Content.new({ file: 'ch04.html', id: 'ch04-html', media: 'application/xhtml+xml', title: 'CH04', level: 1 }), - Content.new({ file: 'sample.png', id: 'sample-png', media: 'image/png' }), - Content.new({ file: 'sample.jpg', id: 'sample-jpg', media: 'image/jpeg' }), - Content.new({ file: 'sample.JPEG', id: 'sample-JPEG', media: 'image/jpeg' }), - Content.new({ file: 'sample.SvG', id: 'sample-SvG', media: 'image/svg+xml' }), - Content.new({ file: 'sample.GIF', id: 'sample-GIF', media: 'image/gif' }), - Content.new({ file: 'sample.css', id: 'sample-css', media: 'text/css' }) + Content.new(file: 'ch01.html', id: 'ch01-html', media: 'application/xhtml+xml', title: %Q(CH01<>&"), level: 1), + Content.new(file: 'ch02.html', id: 'ch02-html', media: 'application/xhtml+xml', title: 'CH02', level: 1), + Content.new(file: 'ch02.html#S1', id: 'ch02-html#S1', media: 'html#s1', title: 'CH02.1', level: 2), + Content.new(file: 'ch02.html#S1.1', id: 'ch02-html#S1-1', media: '1', title: 'CH02.1.1', level: 3), + Content.new(file: 'ch02.html#S1.1.1', id: 'ch02-html#S1-1-1', media: '1', title: 'CH02.1.1.1', level: 4), + 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), + Content.new(file: 'ch02.html#S1.1.2', id: 'ch02-html#S1-1-2', media: '2', title: 'CH02.1.1.2', level: 4), + Content.new(file: 'ch02.html#S2', id: 'ch02-html#S2', media: 'html#s2', title: 'CH02.2', level: 2), + Content.new(file: 'ch02.html#S2.1', id: 'ch02-html#S2-1', media: '1', title: 'CH02.2.1', level: 3), + Content.new(file: 'ch03.html', id: 'ch03-html', media: 'application/xhtml+xml', title: 'CH03', level: 1, properties: ['mathml']), + Content.new(file: 'ch03.html#S1', id: 'ch03-html#S1', media: 'html#s1', title: 'CH03.1', level: 2), + Content.new(file: 'ch03.html#S1.1', id: 'ch03-html#S1-1', media: '1', title: 'CH03.1.1', level: 3), + Content.new(file: 'ch04.html', id: 'ch04-html', media: 'application/xhtml+xml', title: 'CH04', level: 1), + Content.new(file: 'sample.png', id: 'sample-png', media: 'image/png'), + Content.new(file: 'sample.jpg', id: 'sample-jpg', media: 'image/jpeg'), + Content.new(file: 'sample.JPEG', id: 'sample-JPEG', media: 'image/jpeg'), + Content.new(file: 'sample.SvG', id: 'sample-SvG', media: 'image/svg+xml'), + Content.new(file: 'sample.GIF', id: 'sample-GIF', media: 'image/gif'), + Content.new(file: 'sample.css', id: 'sample-css', media: 'text/css') ] assert_equal expect, @producer.contents diff --git a/test/test_epubmaker.rb b/test/test_epubmaker.rb index 4670ce1ad..ad51ac60f 100644 --- a/test/test_epubmaker.rb +++ b/test/test_epubmaker.rb @@ -167,16 +167,16 @@ def test_stage1_ncx_escape def stage2 # add one item - @producer.contents << Content.new({ file: 'ch01.html', title: 'CH01', level: 1 }) + @producer.contents << Content.new(file: 'ch01.html', title: 'CH01', level: 1) end def test_stage2_add_l1item stage2 - expect = EPUBMaker::Content.new({ file: 'ch01.html', - id: 'ch01-html', - media: 'application/xhtml+xml', - title: 'CH01', - level: 1 }) + expect = EPUBMaker::Content.new(file: 'ch01.html', + id: 'ch01-html', + media: 'application/xhtml+xml', + title: 'CH01', + level: 1) assert_equal expect, @producer.contents[0] end @@ -248,49 +248,49 @@ def test_stage2_ncx 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 }) - @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 << 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) + @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') end def test_stage3_add_various_items stage3 expect = [ - Content.new({ file: 'ch01.html', id: 'ch01-html', media: 'application/xhtml+xml', title: %Q(CH01<>&"), level: 1 }), - Content.new({ file: 'ch02.html', id: 'ch02-html', media: 'application/xhtml+xml', title: 'CH02', level: 1 }), - Content.new({ file: 'ch02.html#S1', id: 'ch02-html#S1', media: 'html#s1', title: 'CH02.1', level: 2 }), - Content.new({ file: 'ch02.html#S1.1', id: 'ch02-html#S1-1', media: '1', title: 'CH02.1.1', level: 3 }), - Content.new({ file: 'ch02.html#S1.1.1', id: 'ch02-html#S1-1-1', media: '1', title: 'CH02.1.1.1', level: 4 }), - 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 }), - Content.new({ file: 'ch02.html#S1.1.2', id: 'ch02-html#S1-1-2', media: '2', title: 'CH02.1.1.2', level: 4 }), - Content.new({ file: 'ch02.html#S2', id: 'ch02-html#S2', media: 'html#s2', title: 'CH02.2', level: 2 }), - Content.new({ file: 'ch02.html#S2.1', id: 'ch02-html#S2-1', media: '1', title: 'CH02.2.1', level: 3 }), - Content.new({ file: 'ch03.html', id: 'ch03-html', media: 'application/xhtml+xml', title: 'CH03', level: 1 }), - Content.new({ file: 'ch03.html#S1', id: 'ch03-html#S1', media: 'html#s1', title: 'CH03.1', level: 2 }), - Content.new({ file: 'ch03.html#S1.1', id: 'ch03-html#S1-1', media: '1', title: 'CH03.1.1', level: 3 }), - Content.new({ file: 'ch04.html', id: 'ch04-html', media: 'application/xhtml+xml', title: 'CH04', level: 1 }), - Content.new({ file: 'sample.png', id: 'sample-png', media: 'image/png' }), - Content.new({ file: 'sample.jpg', id: 'sample-jpg', media: 'image/jpeg' }), - Content.new({ file: 'sample.JPEG', id: 'sample-JPEG', media: 'image/jpeg' }), - Content.new({ file: 'sample.SvG', id: 'sample-SvG', media: 'image/svg+xml' }), - Content.new({ file: 'sample.GIF', id: 'sample-GIF', media: 'image/gif' }), - Content.new({ file: 'sample.css', id: 'sample-css', media: 'text/css' }) + Content.new(file: 'ch01.html', id: 'ch01-html', media: 'application/xhtml+xml', title: %Q(CH01<>&"), level: 1), + Content.new(file: 'ch02.html', id: 'ch02-html', media: 'application/xhtml+xml', title: 'CH02', level: 1), + Content.new(file: 'ch02.html#S1', id: 'ch02-html#S1', media: 'html#s1', title: 'CH02.1', level: 2), + Content.new(file: 'ch02.html#S1.1', id: 'ch02-html#S1-1', media: '1', title: 'CH02.1.1', level: 3), + Content.new(file: 'ch02.html#S1.1.1', id: 'ch02-html#S1-1-1', media: '1', title: 'CH02.1.1.1', level: 4), + 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), + Content.new(file: 'ch02.html#S1.1.2', id: 'ch02-html#S1-1-2', media: '2', title: 'CH02.1.1.2', level: 4), + Content.new(file: 'ch02.html#S2', id: 'ch02-html#S2', media: 'html#s2', title: 'CH02.2', level: 2), + Content.new(file: 'ch02.html#S2.1', id: 'ch02-html#S2-1', media: '1', title: 'CH02.2.1', level: 3), + Content.new(file: 'ch03.html', id: 'ch03-html', media: 'application/xhtml+xml', title: 'CH03', level: 1), + Content.new(file: 'ch03.html#S1', id: 'ch03-html#S1', media: 'html#s1', title: 'CH03.1', level: 2), + Content.new(file: 'ch03.html#S1.1', id: 'ch03-html#S1-1', media: '1', title: 'CH03.1.1', level: 3), + Content.new(file: 'ch04.html', id: 'ch04-html', media: 'application/xhtml+xml', title: 'CH04', level: 1), + Content.new(file: 'sample.png', id: 'sample-png', media: 'image/png'), + Content.new(file: 'sample.jpg', id: 'sample-jpg', media: 'image/jpeg'), + Content.new(file: 'sample.JPEG', id: 'sample-JPEG', media: 'image/jpeg'), + Content.new(file: 'sample.SvG', id: 'sample-SvG', media: 'image/svg+xml'), + Content.new(file: 'sample.GIF', id: 'sample-GIF', media: 'image/gif'), + Content.new(file: 'sample.css', id: 'sample-css', media: 'text/css') ] assert_equal expect, @producer.contents @@ -821,9 +821,9 @@ def test_title_single_value_param end def test_epub_unsafe_id - content = Content.new({ file: 'sample.png' }) + content = Content.new(file: 'sample.png') assert_equal 'sample-png', content.id - content = Content.new({ file: 'sample-&()-=+@:,漢字.png' }) + content = Content.new(file: 'sample-&()-=+@:,漢字.png') assert_equal 'sample-_25_26_25_28_25_29-_25_3D_25_2B_25_40_25_3A_25_2C_25_E6_25_BC_25_A2_25_E5_25_AD_25_97-png', content.id end end From 22e1aa0a06eeac3f40b9d0f26aaf0f62e94b0b9a Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Mon, 21 Dec 2020 18:28:57 +0900 Subject: [PATCH 4/6] fix indent --- test/test_epub3maker.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_epub3maker.rb b/test/test_epub3maker.rb index 69ff20fa2..38475ad1b 100644 --- a/test/test_epub3maker.rb +++ b/test/test_epub3maker.rb @@ -187,10 +187,10 @@ def stage2 def test_stage2_add_l1item stage2 expect = EPUBMaker::Content.new(file: 'ch01.html', - id: 'ch01-html', - media: 'application/xhtml+xml', - title: 'CH01', - level: 1) + id: 'ch01-html', + media: 'application/xhtml+xml', + title: 'CH01', + level: 1) assert_equal expect, @producer.contents[0] end From 97a211ea53f6c33eefcf9aea1b19abcf9574584b Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Mon, 21 Dec 2020 18:37:40 +0900 Subject: [PATCH 5/6] suppress pygments --- test/test_htmlbuilder.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_htmlbuilder.rb b/test/test_htmlbuilder.rb index bc1b0539e..f0c3cad8d 100644 --- a/test/test_htmlbuilder.rb +++ b/test/test_htmlbuilder.rb @@ -21,7 +21,7 @@ def setup location = Location.new(nil, nil) @builder.bind(@compiler, @chapter, location) I18n.setup('ja') - @skip_pygments = true # temporary suspend pygments test + @skip_pygments = true # temporary suppress pygments test end def test_xmlns_ops_prefix_epub3 @@ -959,6 +959,7 @@ def test_inline_list_href end def test_list_pygments + return true if @skip_pygments def @chapter.list(_id) Book::Index::Item.new('samplelist', 1) end From 167ba4e4d11ac9d7a0724e6c1db726300eff624f Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Mon, 21 Dec 2020 20:08:49 +0900 Subject: [PATCH 6/6] use ** when extract hash to named parameters --- lib/review/epubmaker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/review/epubmaker.rb b/lib/review/epubmaker.rb index 8afa80bc0..efb5918ab 100644 --- a/lib/review/epubmaker.rb +++ b/lib/review/epubmaker.rb @@ -495,7 +495,7 @@ def push_contents(_basetmpdir) if args[:notoc].present? params[:notoc] = args[:notoc] end - @producer.contents.push(Content.new(params)) + @producer.contents.push(Content.new(**params)) end end