epub-parser-io 0.1.6a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gemtest +0 -0
- data/.gitignore +12 -0
- data/.gitmodules +3 -0
- data/.travis.yml +4 -0
- data/.yardopts +10 -0
- data/CHANGELOG.markdown +61 -0
- data/Gemfile +2 -0
- data/MIT-LICENSE +7 -0
- data/README.markdown +174 -0
- data/Rakefile +68 -0
- data/bin/epub-open +25 -0
- data/bin/epubinfo +64 -0
- data/docs/EpubOpen.markdown +43 -0
- data/docs/Epubinfo.markdown +37 -0
- data/docs/FixedLayout.markdown +96 -0
- data/docs/Home.markdown +128 -0
- data/docs/Item.markdown +80 -0
- data/docs/Navigation.markdown +58 -0
- data/docs/Publication.markdown +54 -0
- data/epub-parser.gemspec +49 -0
- data/features/epubinfo.feature +6 -0
- data/features/step_definitions/epubinfo_steps.rb +5 -0
- data/features/support/env.rb +1 -0
- data/lib/epub/book/features.rb +85 -0
- data/lib/epub/book.rb +7 -0
- data/lib/epub/constants.rb +48 -0
- data/lib/epub/content_document/navigation.rb +104 -0
- data/lib/epub/content_document/xhtml.rb +41 -0
- data/lib/epub/content_document.rb +2 -0
- data/lib/epub/inspector.rb +45 -0
- data/lib/epub/ocf/container.rb +28 -0
- data/lib/epub/ocf/encryption.rb +7 -0
- data/lib/epub/ocf/manifest.rb +6 -0
- data/lib/epub/ocf/metadata.rb +6 -0
- data/lib/epub/ocf/rights.rb +6 -0
- data/lib/epub/ocf/signatures.rb +6 -0
- data/lib/epub/ocf.rb +8 -0
- data/lib/epub/parser/content_document.rb +111 -0
- data/lib/epub/parser/ocf.rb +73 -0
- data/lib/epub/parser/publication.rb +200 -0
- data/lib/epub/parser/utils.rb +20 -0
- data/lib/epub/parser/version.rb +5 -0
- data/lib/epub/parser.rb +103 -0
- data/lib/epub/publication/fixed_layout.rb +208 -0
- data/lib/epub/publication/package/bindings.rb +31 -0
- data/lib/epub/publication/package/guide.rb +51 -0
- data/lib/epub/publication/package/manifest.rb +180 -0
- data/lib/epub/publication/package/metadata.rb +170 -0
- data/lib/epub/publication/package/spine.rb +106 -0
- data/lib/epub/publication/package.rb +68 -0
- data/lib/epub/publication.rb +2 -0
- data/lib/epub.rb +14 -0
- data/man/epubinfo.1.ronn +19 -0
- data/schemas/epub-nav-30.rnc +10 -0
- data/schemas/epub-nav-30.sch +72 -0
- data/schemas/epub-xhtml-30.sch +377 -0
- data/schemas/ocf-container-30.rnc +16 -0
- data/test/fixtures/book/META-INF/container.xml +6 -0
- data/test/fixtures/book/OPS/%E6%97%A5%E6%9C%AC%E8%AA%9E.xhtml +10 -0
- data/test/fixtures/book/OPS/case-sensitive.xhtml +9 -0
- data/test/fixtures/book/OPS/containing space.xhtml +10 -0
- data/test/fixtures/book/OPS/containing%20space.xhtml +10 -0
- data/test/fixtures/book/OPS/nav.xhtml +28 -0
- data/test/fixtures/book/OPS//343/203/253/343/203/274/343/203/210/343/203/225/343/202/241/343/202/244/343/203/253.opf +119 -0
- data/test/fixtures/book/OPS//346/227/245/346/234/254/350/252/236.xhtml +10 -0
- data/test/fixtures/book/mimetype +1 -0
- data/test/helper.rb +9 -0
- data/test/test_content_document.rb +92 -0
- data/test/test_epub.rb +21 -0
- data/test/test_fixed_layout.rb +257 -0
- data/test/test_inspect.rb +121 -0
- data/test/test_parser.rb +60 -0
- data/test/test_parser_content_document.rb +36 -0
- data/test/test_parser_fixed_layout.rb +16 -0
- data/test/test_parser_ocf.rb +38 -0
- data/test/test_parser_publication.rb +247 -0
- data/test/test_publication.rb +324 -0
- metadata +445 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
|
3
|
+
<head>
|
4
|
+
<title>Table of Contents for Example Book</title>
|
5
|
+
</head>
|
6
|
+
<body>
|
7
|
+
<div>
|
8
|
+
<nav epub:type="toc" id="idid" hidden="">
|
9
|
+
<hgroup>
|
10
|
+
<h2>Sub Navigation</h2>
|
11
|
+
<h1>Table of Contents</h1>
|
12
|
+
</hgroup>
|
13
|
+
<ol>
|
14
|
+
<li><a href="item-1.xhtml">一ページ目</a></li>
|
15
|
+
<li>
|
16
|
+
<span>二ページ目</span>
|
17
|
+
<ol>
|
18
|
+
<li><a href="item-2.xhtml#section1">第一節</a></li>
|
19
|
+
<li><a href="item-2.xhtml#section2">第二節</a></li>
|
20
|
+
<li><a href="item-2.xhtml#section3"><img src="image/nav-2-3.png" alt="第三節"/></a></li>
|
21
|
+
<li><a href="item-2.xhtml#section4"><iframe src="external/document.html" name="第四節"></iframe></a></li>
|
22
|
+
</ol>
|
23
|
+
</li>
|
24
|
+
</ol>
|
25
|
+
</nav>
|
26
|
+
</div>
|
27
|
+
</body>
|
28
|
+
</html>
|
@@ -0,0 +1,119 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<package version="3.0"
|
3
|
+
unique-identifier="pub-id"
|
4
|
+
xmlns="http://www.idpf.org/2007/opf"
|
5
|
+
prefix=" foaf: http://xmlns.com/foaf/spec/
|
6
|
+
dbp: http://dbpedia.org/ontology/ ">
|
7
|
+
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
|
8
|
+
<dc:identifier id="pub-id">da265185-8da8-462d-a146-17dd388f61fc</dc:identifier>
|
9
|
+
<dc:identifier opf:scheme="ISBN">0000000000000</dc:identifier>
|
10
|
+
|
11
|
+
<dc:title id="t1" xml:lang="fr">Mon premier guide de cuisson, un Mémoire</dc:title>
|
12
|
+
<meta refines="#t1" property="title-type">main</meta>
|
13
|
+
<meta refines="#t1" property="display-seq">2</meta>
|
14
|
+
|
15
|
+
<dc:title id="t2">The Great Cookbooks of the World</dc:title>
|
16
|
+
<meta refines="#t2" property="title-type">collection</meta>
|
17
|
+
<meta refines="#t2" property="display-seq">1</meta>
|
18
|
+
|
19
|
+
<dc:title id="t3">The New French Cuisine Masters</dc:title>
|
20
|
+
<meta refines="#t3" property="title-type">collection</meta>
|
21
|
+
<meta refines="#t3" property="group-position">2</meta>
|
22
|
+
<meta refines="#t3" property="display-seq">3</meta>
|
23
|
+
|
24
|
+
<dc:title id="t4">Special Anniversary Edition</dc:title>
|
25
|
+
<meta refines="#t4" property="title-type">edition</meta>
|
26
|
+
<meta refines="#t4" property="display-seq">4</meta>
|
27
|
+
|
28
|
+
<dc:title id="t5">The Great Cookbooks of the World:
|
29
|
+
Mon premier guide de cuisson, un Mémoire.
|
30
|
+
The New French Cuisine Masters, Volume Two.
|
31
|
+
Special Anniversary Edition</dc:title>
|
32
|
+
<meta refines="#t5" property="title-type">extended</meta>
|
33
|
+
|
34
|
+
<dc:language>ja</dc:language>
|
35
|
+
<meta property="dcterms:modified">2012-02-03T12:00:00Z</meta>
|
36
|
+
|
37
|
+
<dc:creator id="creator01">Lewis Carroll</dc:creator>
|
38
|
+
<meta refines="#creator01" property="role" scheme="marc:relators">aut</meta>
|
39
|
+
<meta refines="#creator01" property="display-seq">1</meta>
|
40
|
+
|
41
|
+
<dc:creator id="creator02">John Tenniel</dc:creator>
|
42
|
+
<meta refines="#creator02" property="role" scheme="marc:relators">ill</meta>
|
43
|
+
<meta refines="#creator02" property="display-seq">2</meta>
|
44
|
+
|
45
|
+
|
46
|
+
<link rel="onix-record" href="http://example.org/onix/12389347" refines="#pub-id"/>
|
47
|
+
<link rel="xmp-record" href="http://example.org/xmp/12389347"/>
|
48
|
+
<link rel="foaf:homepage" href="http://example.org/book-info/12389347" />
|
49
|
+
</metadata>
|
50
|
+
<manifest id="manifest-id">
|
51
|
+
<item id="nav"
|
52
|
+
href="nav.xhtml"
|
53
|
+
media-type="application/xhtml+xml"
|
54
|
+
properties="nav"/>
|
55
|
+
<item id="manifest-item-1"
|
56
|
+
href="item-1.xhtml"
|
57
|
+
media-type="application/pdf"
|
58
|
+
properties="property1 property2 property3"/>
|
59
|
+
<item id="manifest-item-2"
|
60
|
+
href="item-2.xhtml"
|
61
|
+
media-type="application/pdf"
|
62
|
+
fallback="manifest-item-fallback"/>
|
63
|
+
<item id="large-file-name"
|
64
|
+
href="CASE-SENSITIVE.xhtml"
|
65
|
+
media-type="application/xhtml+xml"/>
|
66
|
+
<item id="small-file-name"
|
67
|
+
href="case-sensitive.xhtml"
|
68
|
+
media-type="application/xhtml+xml"/>
|
69
|
+
<item id="impl"
|
70
|
+
href="impl.xhtml"
|
71
|
+
media-type="application/xhtml+xml"
|
72
|
+
properties="scripted"/>
|
73
|
+
<item id="slideshow"
|
74
|
+
href="slideshow.xml"
|
75
|
+
media-type="application/x-demo-slideshow"/>
|
76
|
+
<item id="manifest-item-fallback"
|
77
|
+
href="fallback.xhtml"
|
78
|
+
media-type="image/svg+xml"
|
79
|
+
fallback="manifest-item-fallback2"/>
|
80
|
+
<item id="manifest-item-fallback2"
|
81
|
+
href="fallback2.xhtml"
|
82
|
+
media-type="application/xhtml+xml"/>
|
83
|
+
<item id="cover"
|
84
|
+
href="cover.xhtml"
|
85
|
+
media-type="application/xhtml+xml"/>
|
86
|
+
<item id="internal-css"
|
87
|
+
href="special.css"
|
88
|
+
media-type="text/css"/>
|
89
|
+
<item id="external-css"
|
90
|
+
href="http://example.net/stylesheets/common.css"
|
91
|
+
media-type="text/css"/>
|
92
|
+
<item id="containing-space"
|
93
|
+
href="containing space.xhtml"
|
94
|
+
media-type="application/xhtml+xml"/>
|
95
|
+
<item id="containing-encoded-space"
|
96
|
+
href="containing%20space.xhtml"
|
97
|
+
media-type="application/xhtml+xml"/>
|
98
|
+
<item id="japanese-filename"
|
99
|
+
href="日本語.xhtml"
|
100
|
+
media-type="application/xhtml+xml"/>
|
101
|
+
<item id="encoded-japanese-filename"
|
102
|
+
href="%E6%97%A5%E6%9C%AC%E8%AA%9E.xhtml"
|
103
|
+
media-type="application/xhtml+xml"/>
|
104
|
+
</manifest>
|
105
|
+
<spine>
|
106
|
+
<itemref idref="nav"/>
|
107
|
+
<itemref idref="manifest-item-1"/>
|
108
|
+
<itemref idref="manifest-item-2"/>
|
109
|
+
<itemref idref="containing-encoded-space"/>
|
110
|
+
<itemref idref="encoded-japanese-filename"/>
|
111
|
+
</spine>
|
112
|
+
<guide>
|
113
|
+
<reference type="cover" href="cover.xhtml#start" title="カバー"/>
|
114
|
+
</guide>
|
115
|
+
<bindings>
|
116
|
+
<mediaType handler="impl"
|
117
|
+
media-type="application/x-demo-slideshow"/>
|
118
|
+
</bindings>
|
119
|
+
</package>
|
@@ -0,0 +1 @@
|
|
1
|
+
application/epub+zip
|
data/test/helper.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require_relative 'helper'
|
3
|
+
|
4
|
+
class TestContentDocument < Test::Unit::TestCase
|
5
|
+
include EPUB::ContentDocument
|
6
|
+
|
7
|
+
def test_top_level?
|
8
|
+
manifest = EPUB::Publication::Package::Manifest.new
|
9
|
+
spine = EPUB::Publication::Package::Spine.new
|
10
|
+
|
11
|
+
item1 = EPUB::Publication::Package::Manifest::Item.new
|
12
|
+
item1.id = 'item1'
|
13
|
+
item2 = EPUB::Publication::Package::Manifest::Item.new
|
14
|
+
item2.id = 'item2'
|
15
|
+
manifest << item1 << item2
|
16
|
+
|
17
|
+
itemref = EPUB::Publication::Package::Spine::Itemref.new
|
18
|
+
itemref.idref = 'item1'
|
19
|
+
spine << itemref
|
20
|
+
|
21
|
+
package = EPUB::Publication::Package.new
|
22
|
+
package.manifest = manifest
|
23
|
+
package.spine = spine
|
24
|
+
|
25
|
+
doc = XHTML.new
|
26
|
+
doc.item = item1
|
27
|
+
assert_true doc.top_level?
|
28
|
+
|
29
|
+
doc = XHTML.new
|
30
|
+
doc.item = item2
|
31
|
+
assert_false doc.top_level?
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_read_returns_content_document_as_string
|
35
|
+
item = stub
|
36
|
+
stub(item).read {'content'}
|
37
|
+
content_doc = XHTML.new
|
38
|
+
content_doc.item = item
|
39
|
+
assert_equal 'content', content_doc.read
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_title_returns_value_of_title_element
|
43
|
+
content_doc = XHTML.new
|
44
|
+
stub(content_doc).raw_document {File.read(File.join(File.dirname(__FILE__), 'fixtures', 'book', 'OPS', '日本語.xhtml'))}
|
45
|
+
assert_equal '日本語', content_doc.title
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_title_returns_empty_string_when_title_element_not_exist
|
49
|
+
content_doc = XHTML.new
|
50
|
+
stub(content_doc).raw_document {'content'}
|
51
|
+
assert_equal '', content_doc.title
|
52
|
+
end
|
53
|
+
|
54
|
+
class TestNavigationDocument < self
|
55
|
+
def test_item_hidden_returns_true_when_it_has_some_value
|
56
|
+
item = Navigation::Item.new.tap {|item| item.hidden = ''}
|
57
|
+
assert_true item.hidden?
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_item_hidden_returns_false_when_no_parent_and_no_value
|
61
|
+
item = Navigation::Item.new
|
62
|
+
assert_false item.hidden?
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_item_hidden_cascade_parent_item
|
66
|
+
parent = Navigation::Item.new.tap {|item| item.hidden = true}
|
67
|
+
child = Navigation::Item.new.tap {|item| item.hidden = nil}
|
68
|
+
parent.items << child
|
69
|
+
assert_true parent.items.hidden?
|
70
|
+
assert_true child.hidden?
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_item_is_traversable
|
74
|
+
parent = Navigation::Item.new
|
75
|
+
child = Navigation::Navigation.new
|
76
|
+
grandchild = Navigation::Item.new
|
77
|
+
parent.items << child
|
78
|
+
child.items << grandchild
|
79
|
+
|
80
|
+
parent.traverse do |item, deps|
|
81
|
+
case deps
|
82
|
+
when 0
|
83
|
+
assert_equal item, parent
|
84
|
+
when 1
|
85
|
+
assert_equal item, child
|
86
|
+
when 2
|
87
|
+
assert_equal item, grandchild
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/test/test_epub.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'epub/book'
|
3
|
+
|
4
|
+
class TestEUPB < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@file = 'test/fixtures/book.epub'
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_each_page_on_spine_returns_enumerator_when_block_not_given
|
10
|
+
book = EPUB::Parser.parse(@file)
|
11
|
+
assert_kind_of Enumerator, book.each_page_on_spine
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_enumerator_each_page_on_spine_returns_yields_item
|
15
|
+
enum = EPUB::Parser.parse(@file).each_page_on_spine
|
16
|
+
enum.each do |entry|
|
17
|
+
assert_kind_of EPUB::Publication::Package::Manifest::Item, entry
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,257 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'epub/book'
|
3
|
+
require 'epub/publication'
|
4
|
+
|
5
|
+
class EPUB::Publication::Package
|
6
|
+
include EPUB::Publication::FixedLayout
|
7
|
+
end
|
8
|
+
|
9
|
+
class TestFixedLayout < Test::Unit::TestCase
|
10
|
+
include EPUB::Publication
|
11
|
+
|
12
|
+
class TestPackage < TestFixedLayout
|
13
|
+
def test_package_dont_use_fixed_layout_by_default
|
14
|
+
assert_false Package.new.using_fixed_layout?
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_make_package_use_fixed_layout
|
18
|
+
package = Package.new
|
19
|
+
package.using_fixed_layout = true
|
20
|
+
assert_true package.using_fixed_layout?
|
21
|
+
|
22
|
+
package.using_fixed_layout = false
|
23
|
+
assert_false package.using_fixed_layout?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class TestMetadata < TestFixedLayout
|
28
|
+
def setup
|
29
|
+
@metadata = Package::Metadata.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_default_layout_is_reflowable
|
33
|
+
assert_equal 'reflowable', @metadata.rendition_layout
|
34
|
+
assert_true @metadata.reflowable?
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_deafult_layout_is_not_pre_paginated
|
38
|
+
assert_false @metadata.pre_paginated?
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_layout_is_pre_paginated_when_has_meta_with_rendition_layout
|
42
|
+
meta = Package::Metadata::Meta.new
|
43
|
+
meta.property = 'rendition:layout'
|
44
|
+
meta.content = 'pre-paginated'
|
45
|
+
@metadata.metas << meta
|
46
|
+
assert_equal 'pre-paginated', @metadata.rendition_layout
|
47
|
+
assert_true @metadata.pre_paginated?
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_layout_is_reflowable_when_has_meta_with_rendition_layout
|
51
|
+
meta = Package::Metadata::Meta.new
|
52
|
+
meta.property = 'rendition:layout'
|
53
|
+
meta.content = 'reflowable'
|
54
|
+
@metadata.metas << meta
|
55
|
+
assert_equal 'reflowable', @metadata.rendition_layout
|
56
|
+
assert_true @metadata.reflowable?
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_can_set_rendition_layout_by_method_of_metadata
|
60
|
+
@metadata.pre_paginated = true
|
61
|
+
assert_equal 'pre-paginated', @metadata.rendition_layout
|
62
|
+
assert_false @metadata.reflowable?
|
63
|
+
assert_true @metadata.pre_paginated?
|
64
|
+
|
65
|
+
@metadata.reflowable = true
|
66
|
+
assert_equal 'reflowable', @metadata.rendition_layout
|
67
|
+
assert_true @metadata.reflowable?
|
68
|
+
assert_false @metadata.pre_paginated?
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_remove_meta_for_pre_paginated_when_making_reflowable
|
72
|
+
meta = Package::Metadata::Meta.new
|
73
|
+
meta.property = 'rendition:layout'
|
74
|
+
meta.content = 'pre-paginated'
|
75
|
+
@metadata.metas << meta
|
76
|
+
|
77
|
+
@metadata.reflowable = true
|
78
|
+
assert_false @metadata.metas.any? {|m| m.property == 'rendition:layout' && m.content == 'pre-paginated'}
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_remove_meta_for_reflowable_when_making_pre_paginated
|
82
|
+
meta = Package::Metadata::Meta.new
|
83
|
+
meta.property = 'rendition:layout'
|
84
|
+
meta.content = 'pre-paginated'
|
85
|
+
@metadata.metas << meta
|
86
|
+
meta = Package::Metadata::Meta.new
|
87
|
+
meta.property = 'rendition:layout'
|
88
|
+
meta.content = 'reflowable'
|
89
|
+
@metadata.metas << meta
|
90
|
+
|
91
|
+
@metadata.pre_paginated = true
|
92
|
+
assert_false @metadata.metas.any? {|m| m.property == 'rendition:layout' && m.content == 'reflowable'}
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_layout_setter
|
96
|
+
@metadata.rendition_layout = 'reflowable'
|
97
|
+
assert_equal 'reflowable', @metadata.rendition_layout
|
98
|
+
|
99
|
+
@metadata.rendition_layout = 'pre-paginated'
|
100
|
+
assert_equal 'pre-paginated', @metadata.rendition_layout
|
101
|
+
|
102
|
+
assert_raise FixedLayout::UnsupportedRenditionValue do
|
103
|
+
@metadata.rendition_layout = 'undefined'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_utility_methods_for_rendition_layout_setter
|
108
|
+
@metadata.make_pre_paginated
|
109
|
+
assert_equal 'pre-paginated', @metadata.rendition_layout
|
110
|
+
|
111
|
+
@metadata.make_reflowable
|
112
|
+
assert_equal 'reflowable', @metadata.rendition_layout
|
113
|
+
|
114
|
+
@metadata.pre_paginated!
|
115
|
+
assert_equal 'pre-paginated', @metadata.rendition_layout
|
116
|
+
|
117
|
+
@metadata.reflowable!
|
118
|
+
assert_equal 'reflowable', @metadata.rendition_layout
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_default_orientation_is_auto
|
122
|
+
assert_equal 'auto', @metadata.rendition_orientation
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
class TestItemref < TestFixedLayout
|
127
|
+
def setup
|
128
|
+
@itemref = Package::Spine::Itemref.new
|
129
|
+
@package = Package.new
|
130
|
+
@package.metadata = Package::Metadata.new
|
131
|
+
@package.spine = Package::Spine.new
|
132
|
+
@package.spine << @itemref
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_inherits_metadatas_rendition_layout_by_default
|
136
|
+
assert_equal 'reflowable', @itemref.rendition_layout
|
137
|
+
|
138
|
+
@package.metadata.rendition_layout = 'pre-paginated'
|
139
|
+
assert_equal 'pre-paginated', @itemref.rendition_layout
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_overwrite_rendition_layout_of_metadata_when_set_explicitly
|
143
|
+
@package.metadata.rendition_layout = 'pre-paginated'
|
144
|
+
@itemref.properties << 'rendition:layout-reflowable'
|
145
|
+
assert_equal 'reflowable', @itemref.rendition_layout
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_can_set_explicitly
|
149
|
+
@itemref.rendition_layout = 'pre-paginated'
|
150
|
+
assert_equal 'pre-paginated', @itemref.rendition_layout
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_can_unset_explicitly
|
154
|
+
@itemref.rendition_layout = 'pre-paginated'
|
155
|
+
@itemref.rendition_layout = nil
|
156
|
+
assert_equal 'reflowable', @itemref.rendition_layout
|
157
|
+
assert_not_include @itemref.properties, 'rendition:layout-reflowable'
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_property_added_when_rendition_layout_set
|
161
|
+
@itemref.rendition_layout = 'pre-paginated'
|
162
|
+
assert_include @itemref.properties, 'rendition:layout-pre-paginated'
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_opposite_property_removed_if_exists_when_rendition_layout_set
|
166
|
+
@itemref.rendition_layout = 'reflowable'
|
167
|
+
@itemref.rendition_layout = 'pre-paginated'
|
168
|
+
assert_not_include @itemref.properties, 'rendition:layout-reflowable'
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_utility_methods
|
172
|
+
assert_true @itemref.reflowable?
|
173
|
+
|
174
|
+
@itemref.make_pre_paginated
|
175
|
+
assert_false @itemref.reflowable?
|
176
|
+
assert_true @itemref.pre_paginated?
|
177
|
+
assert_not_include @itemref.properties, 'rendition:layout-reflowbale'
|
178
|
+
assert_include @itemref.properties, 'rendition:layout-pre-paginated'
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_inherits_metadatas_rendition_spread_by_default
|
182
|
+
assert_equal 'auto', @itemref.rendition_spread
|
183
|
+
|
184
|
+
@package.metadata.rendition_spread = 'portrait'
|
185
|
+
assert_equal 'portrait', @itemref.rendition_spread
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_rendition_property_reader_has_alias
|
189
|
+
assert_equal 'auto', @itemref.orientation
|
190
|
+
|
191
|
+
@itemref.orientation = 'landscape'
|
192
|
+
assert_equal 'landscape', @itemref.rendition_orientation
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_page_spread_center_defined
|
196
|
+
@itemref.properties << 'rendition:page-spread-center'
|
197
|
+
assert_equal 'center', @itemref.page_spread
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_can_make_page_spread_center_explicitly
|
201
|
+
@itemref.page_spread = 'center'
|
202
|
+
assert_include @itemref.properties, 'rendition:page-spread-center'
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_page_spread_is_exclusive
|
206
|
+
@itemref.page_spread = 'right'
|
207
|
+
@itemref.page_spread = 'center'
|
208
|
+
assert_not_include @itemref.properties, 'page-spread-right'
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
class TestItem < TestFixedLayout
|
213
|
+
def setup
|
214
|
+
package = Package.new
|
215
|
+
package.manifest = Package::Manifest.new
|
216
|
+
@item = Package::Manifest::Item.new
|
217
|
+
@item.id = 'item'
|
218
|
+
package.manifest << @item
|
219
|
+
package.spine = Package::Spine.new
|
220
|
+
@itemref = Package::Spine::Itemref.new
|
221
|
+
@itemref.idref = 'item'
|
222
|
+
package.spine << @itemref
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_can_access_rendition_attributes
|
226
|
+
@itemref.rendition_layout = 'pre-paginated'
|
227
|
+
assert_true @item.pre_paginated?
|
228
|
+
|
229
|
+
@item.rendition_orientation = 'portrait'
|
230
|
+
assert_equal 'portrait', @itemref.rendition_orientation
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
class TestContentDocument < TestFixedLayout
|
235
|
+
def setup
|
236
|
+
package = Package.new
|
237
|
+
package.manifest = Package::Manifest.new
|
238
|
+
item = Package::Manifest::Item.new
|
239
|
+
item.id = 'item'
|
240
|
+
package.manifest << item
|
241
|
+
package.spine = Package::Spine.new
|
242
|
+
@itemref = Package::Spine::Itemref.new
|
243
|
+
@itemref.idref = 'item'
|
244
|
+
package.spine << @itemref
|
245
|
+
@doc = EPUB::ContentDocument::XHTML.new
|
246
|
+
@doc.item = item
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_can_access_rendition_attributes
|
250
|
+
@itemref.rendition_layout = 'pre-paginated'
|
251
|
+
assert_true @doc.pre_paginated?
|
252
|
+
|
253
|
+
@doc.rendition_spread = 'none'
|
254
|
+
assert_equal 'none', @itemref.rendition_spread
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|