gepub 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/gepub.gemspec +1 -2
- data/lib/gepub/version.rb +1 -1
- metadata +4 -110
- data/spec/bindings_spec.rb +0 -34
- data/spec/book_spec.rb +0 -307
- data/spec/builder_spec.rb +0 -614
- data/spec/example_spec.rb +0 -192
- data/spec/fixtures/builder/img/cover.jpg +0 -0
- data/spec/fixtures/builder/resources/noise.m4 +0 -0
- data/spec/fixtures/builder/resources/noise_2.m4a +0 -0
- data/spec/fixtures/builder/text/cover.xhtml +0 -11
- data/spec/fixtures/builder/text/localresource.conf +0 -2
- data/spec/fixtures/builder/text/memo.txt +0 -1
- data/spec/fixtures/builder/text/nav.xhtml +0 -12
- data/spec/fixtures/epubcheck-4.1.1/CHANGELOG.txt +0 -92
- data/spec/fixtures/epubcheck-4.1.1/LICENSE.txt +0 -28
- data/spec/fixtures/epubcheck-4.1.1/README.txt +0 -101
- data/spec/fixtures/epubcheck-4.1.1/THIRD-PARTY.txt +0 -60
- data/spec/fixtures/epubcheck-4.1.1/epubcheck.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/Saxon-HE-9.8.0-8.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/animal-sniffer-annotations-1.14.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/checker-compat-qual-2.0.0.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/common-image-3.4.1.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/common-io-3.4.1.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/common-lang-3.4.1.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/commons-compress-1.18.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/error_prone_annotations-2.1.3.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/guava-24.0-android.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/imageio-core-3.4.1.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/imageio-jpeg-3.4.1.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/imageio-metadata-3.4.1.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/j2objc-annotations-1.1.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/jackson-core-asl-1.9.12.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/jackson-mapper-asl-1.9.12.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/jing-20120724.0.0.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/jsr305-1.3.9.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/lib/sac-1.3.jar +0 -0
- data/spec/fixtures/epubcheck-4.1.1/licenses/Apache-2.0.txt +0 -201
- data/spec/fixtures/epubcheck-4.1.1/licenses/BSD-3-Clause.txt +0 -27
- data/spec/fixtures/epubcheck-4.1.1/licenses/MPL-1.0.txt +0 -360
- data/spec/fixtures/epubcheck-4.1.1/licenses/W3C.txt +0 -16
- data/spec/fixtures/testdata/0.html +0 -12
- data/spec/fixtures/testdata/1.html +0 -10
- data/spec/fixtures/testdata/image1.jpg +0 -0
- data/spec/fixtures/testdata/package_2_0.opf +0 -23
- data/spec/fixtures/testdata/test.opf +0 -69
- data/spec/fixtures/testdata/test2.opf +0 -63
- data/spec/fixtures/testdata/test_with_bindings.opf +0 -67
- data/spec/fixtures/testdata/wasteland-20120118.epub +0 -0
- data/spec/gepub_deprectad_api_spec.rb +0 -229
- data/spec/gepub_spec.rb +0 -229
- data/spec/manifest_spec.rb +0 -36
- data/spec/metadata_spec.rb +0 -219
- data/spec/package_spec.rb +0 -150
- data/spec/spec_helper.rb +0 -57
- data/spec/spine_spec.rb +0 -55
data/spec/package_spec.rb
DELETED
@@ -1,150 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
3
|
-
require 'rubygems'
|
4
|
-
require 'nokogiri'
|
5
|
-
|
6
|
-
describe GEPUB::Package do
|
7
|
-
it 'should be initialized' do
|
8
|
-
opf = GEPUB::Package.new('/package.opf')
|
9
|
-
expect(opf.ns_prefix(GEPUB::XMLUtil::OPF_NS)).to eq('xmlns')
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'parse existing opf' do
|
13
|
-
it 'should be initialized with opf' do
|
14
|
-
opf = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test.opf'), '/package.opf')
|
15
|
-
expect(opf.ns_prefix(GEPUB::XMLUtil::OPF_NS)).to eq('xmlns')
|
16
|
-
expect(opf['version']).to eq('3.0')
|
17
|
-
expect(opf['unique-identifier']).to eq('pub-id')
|
18
|
-
expect(opf['xml:lang']).to eq('ja')
|
19
|
-
expect(opf['prefix']).to eq('foaf: http://xmlns.com/foaf/spec/ rendition: http://www.idpf.org/vocab/rendition/#')
|
20
|
-
end
|
21
|
-
it 'should parse prefix data' do
|
22
|
-
package = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test.opf'), '/package.opf')
|
23
|
-
expect(package.prefixes.size).to eq(2)
|
24
|
-
expect(package.prefixes['foaf']).to eq('http://xmlns.com/foaf/spec/')
|
25
|
-
expect(package.prefixes['rendition']).to eq('http://www.idpf.org/vocab/rendition/#')
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should parse rendition metadata' do
|
30
|
-
package = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test.opf'), '/package.opf')
|
31
|
-
expect(package.rendition_layout).to eq('pre-paginated')
|
32
|
-
expect(package.rendition_orientation).to eq('auto')
|
33
|
-
expect(package.rendition_spread).to eq('both')
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
context 'generate new opf' do
|
39
|
-
it 'should generate opf' do
|
40
|
-
opf = GEPUB::Package.new('OEBPS/package.package') {
|
41
|
-
|package|
|
42
|
-
package.primary_identifier('http://example.jp', 'BookID', 'url')
|
43
|
-
package['xml:lang'] = 'ja'
|
44
|
-
|
45
|
-
# metadata add: style 1
|
46
|
-
package.metadata.add_title('EPUB3 Sample', title_type: GEPUB::TITLE_TYPE::MAIN) {
|
47
|
-
|title|
|
48
|
-
title.display_seq = 1
|
49
|
-
title.file_as = 'Sample EPUB3'
|
50
|
-
title.add_alternates(
|
51
|
-
'en' => 'EPUB3 Sample (Japanese)',
|
52
|
-
'el' => 'EPUB3 δείγμα (Ιαπωνικά)',
|
53
|
-
'th' => 'EPUB3 ตัวอย่าง (ญี่ปุ่น)')
|
54
|
-
}
|
55
|
-
# metadata add: style2
|
56
|
-
package.metadata.add_title('これでEPUB3もばっちり', title_type: GEPUB::TITLE_TYPE::SUBTITLE).display_seq(2).add_alternates('en' => 'you need nothing but this book!')
|
57
|
-
package.metadata.add_creator('小嶋智').display_seq(1).add_alternates('en' => 'KOJIMA Satoshi')
|
58
|
-
package.metadata.add_contributor('電書部').display_seq(1).add_alternates('en' => 'Denshobu')
|
59
|
-
package.metadata.add_contributor('アサガヤデンショ').display_seq(2).add_alternates('en' => 'Asagaya Densho')
|
60
|
-
package.metadata.add_contributor('湘南電書鼎談').display_seq(3).add_alternates('en' => 'Shonan Densho Teidan')
|
61
|
-
package.metadata.add_contributor('電子雑誌トルタル').display_seq(4).add_alternates('en' => 'eMagazine Torutaru')
|
62
|
-
package.add_item('img/image1.jpg')
|
63
|
-
package.add_item('img/cover.jpg').add_property('cover-image')
|
64
|
-
package.ordered {
|
65
|
-
package.add_item('text/chapter1.xhtml')
|
66
|
-
package.add_item('text/chapter2.xhtml')
|
67
|
-
}
|
68
|
-
}
|
69
|
-
xml = Nokogiri::XML::Document.parse opf.opf_xml
|
70
|
-
expect(xml.root.name).to eq('package')
|
71
|
-
expect(xml.root.namespaces.size).to eq(1)
|
72
|
-
expect(xml.root.namespaces['xmlns']).to eq(GEPUB::XMLUtil::OPF_NS)
|
73
|
-
expect(xml.root['version']).to eq('3.0')
|
74
|
-
expect(xml.root['xml:lang']).to eq('ja')
|
75
|
-
# TODO: should check all elements
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'should generate package with prefix attribute' do
|
79
|
-
opf = GEPUB::Package.new('OEBPS/package.opf') do
|
80
|
-
|package|
|
81
|
-
package.primary_identifier('http://example.jp', 'BookID', 'url')
|
82
|
-
package['xml:lang'] = 'ja'
|
83
|
-
package.enable_rendition
|
84
|
-
end
|
85
|
-
xml = Nokogiri::XML::Document.parse opf.opf_xml
|
86
|
-
expect(xml.root['prefix']).to eq('rendition: http://www.idpf.org/vocab/rendition/#')
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should generate package with rendition attributes' do
|
90
|
-
opf = GEPUB::Package.new('OEBPS/package.opf') do
|
91
|
-
|package|
|
92
|
-
package.rendition_layout = 'pre-paginated'
|
93
|
-
package.rendition_orientation = 'portlait'
|
94
|
-
package.rendition_spread = 'landscape'
|
95
|
-
end
|
96
|
-
xml = Nokogiri::XML::Document.parse opf.opf_xml
|
97
|
-
expect(xml.root['prefix']).to eq('rendition: http://www.idpf.org/vocab/rendition/#')
|
98
|
-
expect(xml.at_xpath("//xmlns:meta[@property='rendition:layout']").content).to eq('pre-paginated')
|
99
|
-
expect(xml.at_xpath("//xmlns:meta[@property='rendition:orientation']").content).to eq('portlait')
|
100
|
-
expect(xml.at_xpath("//xmlns:meta[@property='rendition:spread']").content).to eq('landscape')
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'should handle ibooks version' do
|
104
|
-
opf = GEPUB::Package.new('OEBPS/package.opf') do
|
105
|
-
|package|
|
106
|
-
package.ibooks_version = '1.1.1'
|
107
|
-
end
|
108
|
-
xml = Nokogiri::XML::Document.parse opf.opf_xml
|
109
|
-
expect(xml.root['prefix']).to eq('ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/')
|
110
|
-
expect(xml.at_xpath("//xmlns:meta[@property='ibooks:version']").content).to eq('1.1.1')
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'should generate opf2.0' do
|
114
|
-
opf = GEPUB::Package.new('OEBPS/package.opf', { 'version' => '2.0'}) {
|
115
|
-
|package|
|
116
|
-
package.primary_identifier('http://example.jp', 'BookID', 'url')
|
117
|
-
package['xml:lang'] = 'ja'
|
118
|
-
|
119
|
-
# metadata add: style 1
|
120
|
-
package.metadata.add_title('EPUB3 Sample', title_type: GEPUB::TITLE_TYPE::MAIN) {
|
121
|
-
|title|
|
122
|
-
title.display_seq = 1
|
123
|
-
title.file_as = 'Sample EPUB3'
|
124
|
-
title.add_alternates(
|
125
|
-
'en' => 'EPUB3 Sample (Japanese)',
|
126
|
-
'el' => 'EPUB3 δείγμα (Ιαπωνικά)',
|
127
|
-
'th' => 'EPUB3 ตัวอย่าง (ญี่ปุ่น)')
|
128
|
-
}
|
129
|
-
# metadata add: style2
|
130
|
-
package.metadata.add_title('これでEPUB3もばっちり', title_type: GEPUB::TITLE_TYPE::SUBTITLE).display_seq(2).add_alternates('en' => 'you need nothing but this book!')
|
131
|
-
package.metadata.add_creator('小嶋智').display_seq(1).add_alternates('en' => 'KOJIMA Satoshi')
|
132
|
-
package.metadata.add_contributor('電書部').display_seq(1).add_alternates('en' => 'Denshobu')
|
133
|
-
package.metadata.add_contributor('アサガヤデンショ').display_seq(2).add_alternates('en' => 'Asagaya Densho')
|
134
|
-
package.metadata.add_contributor('湘南電書鼎談').display_seq(3).add_alternates('en' => 'Shonan Densho Teidan')
|
135
|
-
package.metadata.add_contributor('電子雑誌トルタル').display_seq(4).add_alternates('en' => 'eMagazine Torutaru')
|
136
|
-
package.add_item('img/image1.jpg')
|
137
|
-
package.ordered {
|
138
|
-
package.add_item('text/chapter1.xhtml')
|
139
|
-
package.add_item('text/chapter2.xhtml')
|
140
|
-
}
|
141
|
-
}
|
142
|
-
xml = Nokogiri::XML::Document.parse opf.opf_xml
|
143
|
-
expect(xml.root.name).to eq('package')
|
144
|
-
expect(xml.root.namespaces.size).to eq(1)
|
145
|
-
expect(xml.root.namespaces['xmlns']).to eq(GEPUB::XMLUtil::OPF_NS)
|
146
|
-
expect(xml.root['version']).to eq('2.0')
|
147
|
-
expect(xml.root['xml:lang']).to eq('ja')
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'coveralls'
|
2
|
-
Coveralls.wear!
|
3
|
-
|
4
|
-
require "stringio"
|
5
|
-
|
6
|
-
begin
|
7
|
-
require 'rspec'
|
8
|
-
rescue LoadError
|
9
|
-
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
10
|
-
gem 'rspec'
|
11
|
-
require 'spec'
|
12
|
-
end
|
13
|
-
|
14
|
-
RSpec.configure do |config|
|
15
|
-
# Use color in STDOUT
|
16
|
-
config.color = true
|
17
|
-
# Use color not only in STDOUT but also in pagers and files
|
18
|
-
config.tty = true
|
19
|
-
# Use the specified formatter
|
20
|
-
config.formatter = :documentation # :progress, :html, :textmate
|
21
|
-
|
22
|
-
def capture(stream)
|
23
|
-
begin
|
24
|
-
stream = stream.to_s
|
25
|
-
eval "$#{stream} = StringIO.new"
|
26
|
-
yield
|
27
|
-
result = eval("$#{stream}").string
|
28
|
-
ensure
|
29
|
-
eval "$#{stream} = #{stream.upcase}"
|
30
|
-
end
|
31
|
-
result
|
32
|
-
end
|
33
|
-
|
34
|
-
def epubcheck(epubname)
|
35
|
-
jar = File.join(File.dirname(__FILE__), 'fixtures/epubcheck-4.1.1/epubcheck.jar')
|
36
|
-
stdout = capture(:stdout) do
|
37
|
-
puts %x(java -Duser.language=en -jar #{jar} #{epubname} 2>&1)
|
38
|
-
end
|
39
|
-
expect(stdout).to include("No errors or warnings detected.")
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
require 'rspec/core/formatters/base_text_formatter'
|
45
|
-
module RSpec
|
46
|
-
module Core
|
47
|
-
module Formatters
|
48
|
-
class DocumentationFormatter < BaseTextFormatter
|
49
|
-
# def green(text); color(text, "\e[42m") end
|
50
|
-
def red(text); color(text, "\e[41m") end
|
51
|
-
# def magenta(text); color(text, "\e[45m") end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
57
|
-
require 'gepub'
|
data/spec/spine_spec.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
3
|
-
require 'rubygems'
|
4
|
-
require 'nokogiri'
|
5
|
-
|
6
|
-
describe GEPUB::Spine do
|
7
|
-
context 'parse existing opf' do
|
8
|
-
before do
|
9
|
-
@spine = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test.opf'), '/package.opf').instance_eval{ @spine }
|
10
|
-
end
|
11
|
-
it 'should be parsed' do
|
12
|
-
expect(@spine.toc).to eq('ncx')
|
13
|
-
expect(@spine.page_progression_direction).to eq('ltr')
|
14
|
-
expect(@spine.itemref_list.size).to eq(4)
|
15
|
-
expect(@spine.itemref_list[0].idref).to eq('cover')
|
16
|
-
expect(@spine.itemref_list[0].linear).to eq('no')
|
17
|
-
expect(@spine.itemref_list[1].idref).to eq('toc')
|
18
|
-
expect(@spine.itemref_list[1].linear).to eq('yes')
|
19
|
-
expect(@spine.itemref_list[2].idref).to eq('chap1')
|
20
|
-
expect(@spine.itemref_list[2].linear).to eq('yes')
|
21
|
-
expect(@spine.itemref_list[3].idref).to eq('nav')
|
22
|
-
expect(@spine.itemref_list[3].linear).to eq('no')
|
23
|
-
end
|
24
|
-
end
|
25
|
-
context 'generate new opf' do
|
26
|
-
it 'should generate xml' do
|
27
|
-
spine = GEPUB::Spine.new
|
28
|
-
spine.toc = 'ncx'
|
29
|
-
spine.push(GEPUB::Item.new('the_id', 'OEBPS/foo.xhtml')).set_linear('no')
|
30
|
-
builder = Nokogiri::XML::Builder.new { |xml|
|
31
|
-
xml.package('xmlns' => "http://www.idpf.org/2007/opf",'version' => "3.0",'unique-identifier' => "pub-id",'xml:lang' => "ja") {
|
32
|
-
spine.to_xml(xml)
|
33
|
-
}
|
34
|
-
}
|
35
|
-
xml = Nokogiri::XML::Document.parse(builder.to_xml)
|
36
|
-
expect(xml.at_xpath('//xmlns:spine')['toc']).to eq('ncx')
|
37
|
-
expect(xml.xpath("//xmlns:itemref[@idref='the_id' and @linear='no']").size).to eq(1)
|
38
|
-
end
|
39
|
-
it 'should generate xml with property' do
|
40
|
-
spine = GEPUB::Spine.new
|
41
|
-
spine.toc = 'ncx'
|
42
|
-
spine.push(GEPUB::Item.new('the_id', 'OEBPS/foo.xhtml')).page_spread_right
|
43
|
-
builder = Nokogiri::XML::Builder.new { |xml|
|
44
|
-
xml.package('xmlns' => "http://www.idpf.org/2007/opf",'version' => "3.0",'unique-identifier' => "pub-id",'xml:lang' => "ja") {
|
45
|
-
spine.to_xml(xml)
|
46
|
-
}
|
47
|
-
}
|
48
|
-
xml = Nokogiri::XML::Document.parse(builder.to_xml)
|
49
|
-
expect(xml.at_xpath('//xmlns:spine')['toc']).to eq('ncx')
|
50
|
-
expect(xml.xpath("//xmlns:itemref[@idref='the_id' and @properties='page-spread-right']").size).to eq(1)
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|