spec/package_spec.rb in gepub-0.6.9.2 vs spec/package_spec.rb in gepub-0.7.0beta1

- old
+ new

@@ -35,37 +35,37 @@ end end context 'generate new opf' do it 'should generate opf' do - opf = GEPUB::Package.new('OEBPS/package.opf') { - |opf| - opf.set_main_id('http://example.jp', 'BookID', 'url') - opf['xml:lang'] = 'ja' + opf = GEPUB::Package.new('OEBPS/package.package') { + |package| + package.primary_identifier('http://example.jp', 'BookID', 'url') + package['xml:lang'] = 'ja' # metadata add: style 1 - opf.metadata.add_title('EPUB3 Sample', nil, GEPUB::TITLE_TYPE::MAIN) { + package.metadata.add_title('EPUB3 Sample', nil, GEPUB::TITLE_TYPE::MAIN) { |title| title.display_seq = 1 title.file_as = 'Sample EPUB3' title.add_alternates( 'en' => 'EPUB3 Sample (Japanese)', 'el' => 'EPUB3 δείγμα (Ιαπωνικά)', 'th' => 'EPUB3 ตัวอย่าง (ญี่ปุ่น)') } # metadata add: style2 - opf.metadata.add_title('これでEPUB3もばっちり', nil, GEPUB::TITLE_TYPE::SUBTITLE).set_display_seq(2).add_alternates('en' => 'you need nothing but this book!') - opf.metadata.add_creator('小嶋智').set_display_seq(1).add_alternates('en' => 'KOJIMA Satoshi') - opf.metadata.add_contributor('電書部').set_display_seq(1).add_alternates('en' => 'Denshobu') - opf.metadata.add_contributor('アサガヤデンショ').set_display_seq(2).add_alternates('en' => 'Asagaya Densho') - opf.metadata.add_contributor('湘南電書鼎談').set_display_seq(3).add_alternates('en' => 'Shonan Densho Teidan') - opf.metadata.add_contributor('電子雑誌トルタル').set_display_seq(4).add_alternates('en' => 'eMagazine Torutaru') - opf.add_item('img/image1.jpg') - opf.add_item('img/cover.jpg').add_property('cover-image') - opf.ordered { - opf.add_item('text/chapter1.xhtml') - opf.add_item('text/chapter2.xhtml') + package.metadata.add_title('これでEPUB3もばっちり', nil, GEPUB::TITLE_TYPE::SUBTITLE).display_seq(2).add_alternates('en' => 'you need nothing but this book!') + package.metadata.add_creator('小嶋智').display_seq(1).add_alternates('en' => 'KOJIMA Satoshi') + package.metadata.add_contributor('電書部').display_seq(1).add_alternates('en' => 'Denshobu') + package.metadata.add_contributor('アサガヤデンショ').display_seq(2).add_alternates('en' => 'Asagaya Densho') + package.metadata.add_contributor('湘南電書鼎談').display_seq(3).add_alternates('en' => 'Shonan Densho Teidan') + package.metadata.add_contributor('電子雑誌トルタル').display_seq(4).add_alternates('en' => 'eMagazine Torutaru') + package.add_item('img/image1.jpg') + package.add_item('img/cover.jpg').add_property('cover-image') + package.ordered { + package.add_item('text/chapter1.xhtml') + package.add_item('text/chapter2.xhtml') } } xml = Nokogiri::XML::Document.parse opf.opf_xml expect(xml.root.name).to eq('package') expect(xml.root.namespaces.size).to eq(1) @@ -74,70 +74,70 @@ expect(xml.root['xml:lang']).to eq('ja') # TODO: should check all elements end it 'should generate package with prefix attribute' do - package = GEPUB::Package.new('OEBPS/package.opf') do + opf = GEPUB::Package.new('OEBPS/package.opf') do |package| - package.set_primary_identifier('http://example.jp', 'BookID', 'url') + package.primary_identifier('http://example.jp', 'BookID', 'url') package['xml:lang'] = 'ja' package.enable_rendition end - xml = Nokogiri::XML::Document.parse package.opf_xml + xml = Nokogiri::XML::Document.parse opf.opf_xml expect(xml.root['prefix']).to eq('rendition: http://www.idpf.org/vocab/rendition/#') end it 'should generate package with rendition attributes' do - package = GEPUB::Package.new('OEBPS/package.opf') do + opf = GEPUB::Package.new('OEBPS/package.opf') do |package| package.rendition_layout = 'pre-paginated' package.rendition_orientation = 'portlait' package.rendition_spread = 'landscape' end - xml = Nokogiri::XML::Document.parse package.opf_xml + xml = Nokogiri::XML::Document.parse opf.opf_xml expect(xml.root['prefix']).to eq('rendition: http://www.idpf.org/vocab/rendition/#') expect(xml.at_xpath("//xmlns:meta[@property='rendition:layout']").content).to eq('pre-paginated') expect(xml.at_xpath("//xmlns:meta[@property='rendition:orientation']").content).to eq('portlait') expect(xml.at_xpath("//xmlns:meta[@property='rendition:spread']").content).to eq('landscape') end it 'should handle ibooks version' do - package = GEPUB::Package.new('OEBPS/package.opf') do + opf = GEPUB::Package.new('OEBPS/package.opf') do |package| package.ibooks_version = '1.1.1' end - xml = Nokogiri::XML::Document.parse package.opf_xml + xml = Nokogiri::XML::Document.parse opf.opf_xml expect(xml.root['prefix']).to eq('ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/') expect(xml.at_xpath("//xmlns:meta[@property='ibooks:version']").content).to eq('1.1.1') end it 'should generate opf2.0' do opf = GEPUB::Package.new('OEBPS/package.opf', { 'version' => '2.0'}) { - |opf| - opf.set_primary_identifier('http://example.jp', 'BookID', 'url') - opf['xml:lang'] = 'ja' + |package| + package.primary_identifier('http://example.jp', 'BookID', 'url') + package['xml:lang'] = 'ja' # metadata add: style 1 - opf.metadata.add_title('EPUB3 Sample', nil, GEPUB::TITLE_TYPE::MAIN) { + package.metadata.add_title('EPUB3 Sample', nil, GEPUB::TITLE_TYPE::MAIN) { |title| title.display_seq = 1 title.file_as = 'Sample EPUB3' title.add_alternates( 'en' => 'EPUB3 Sample (Japanese)', 'el' => 'EPUB3 δείγμα (Ιαπωνικά)', 'th' => 'EPUB3 ตัวอย่าง (ญี่ปุ่น)') } # metadata add: style2 - opf.metadata.add_title('これでEPUB3もばっちり', nil, GEPUB::TITLE_TYPE::SUBTITLE).set_display_seq(2).add_alternates('en' => 'you need nothing but this book!') - opf.metadata.add_creator('小嶋智').set_display_seq(1).add_alternates('en' => 'KOJIMA Satoshi') - opf.metadata.add_contributor('電書部').set_display_seq(1).add_alternates('en' => 'Denshobu') - opf.metadata.add_contributor('アサガヤデンショ').set_display_seq(2).add_alternates('en' => 'Asagaya Densho') - opf.metadata.add_contributor('湘南電書鼎談').set_display_seq(3).add_alternates('en' => 'Shonan Densho Teidan') - opf.metadata.add_contributor('電子雑誌トルタル').set_display_seq(4).add_alternates('en' => 'eMagazine Torutaru') - opf.add_item('img/image1.jpg') - opf.ordered { - opf.add_item('text/chapter1.xhtml') - opf.add_item('text/chapter2.xhtml') + package.metadata.add_title('これでEPUB3もばっちり', nil, GEPUB::TITLE_TYPE::SUBTITLE).display_seq(2).add_alternates('en' => 'you need nothing but this book!') + package.metadata.add_creator('小嶋智').display_seq(1).add_alternates('en' => 'KOJIMA Satoshi') + package.metadata.add_contributor('電書部').display_seq(1).add_alternates('en' => 'Denshobu') + package.metadata.add_contributor('アサガヤデンショ').display_seq(2).add_alternates('en' => 'Asagaya Densho') + package.metadata.add_contributor('湘南電書鼎談').display_seq(3).add_alternates('en' => 'Shonan Densho Teidan') + package.metadata.add_contributor('電子雑誌トルタル').display_seq(4).add_alternates('en' => 'eMagazine Torutaru') + package.add_item('img/image1.jpg') + package.ordered { + package.add_item('text/chapter1.xhtml') + package.add_item('text/chapter2.xhtml') } } xml = Nokogiri::XML::Document.parse opf.opf_xml expect(xml.root.name).to eq('package') expect(xml.root.namespaces.size).to eq(1)