epub-parser 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e95e303cf2c03479fdc655b8c4ea3c0b668b421f9d63082c40d984542312804b
4
- data.tar.gz: 680b503b44bf23e82374da6afc18439762289eeaf87d58c6b0db5588d6ad59b5
3
+ metadata.gz: 0d7e6e2104c4c77f435607cc2b05936b405dad9e18d29d316c98633f9e7df35e
4
+ data.tar.gz: 03b8c36a39101d777fa0e6026436898f4136df2bd4acfa83f173da7baa750ca1
5
5
  SHA512:
6
- metadata.gz: dc201c61dc61f7f56e4690c4b669bf0bee8e098f6025ceea17bc8604fb8b0b4a49a9937a4c34972d5b4584c83064fdf78d9b1831c75706c7f94ad01eebb23a8f
7
- data.tar.gz: 7d08504f668f371dbef455f1498214b3f7bec305f3095638986441a2d6d8800932c329b65c7c62913f4ec126b02db892bbe10a3c22e0a316933f613d5cf7a8d7
6
+ metadata.gz: 2f3d5ce0f4d7847cb0e171dfc7741bb0b1899e9e4300746b8e447f0ba2cc5be2eb6700ace854aac6b39b7cddab069e4f83d14f1a930dcb0becbcb5b32c955105
7
+ data.tar.gz: 96a793271073777e2ae68666018d0e627b7b59edc108a8ed08c085bd0d09cfe4a808f5cc787bdbc8dba28d978e29af92d2e2bd222b2b049d6b4a28b1747f10dc
@@ -1,6 +1,14 @@
1
1
  CHANGELOG
2
2
  =========
3
3
 
4
+ 0.3.4
5
+ -----
6
+
7
+ * Add {EPUB::Publication::Package#full_path} and {EPUB::Publication::Package#rootfile}
8
+ * [BUG FIX]Fix a bug that {EPUB::ContentDocument::Navigation::Item#item} doesn't return correct {EPUB::Publication::Package::Manifest::Item Item}(Thanks [aelkiss][]!)
9
+
10
+ [aelkiss]: https://gitlab.com/aelkiss
11
+
4
12
  0.3.3
5
13
  -----
6
14
 
@@ -5,6 +5,12 @@ EPUB Parser
5
5
  [![Gem Version](https://badge.fury.io/rb/epub-parser.svg)](http://badge.fury.io/rb/epub-parser)
6
6
  [![coverage report](https://gitlab.com/KitaitiMakoto/epub-parser/badges/master/coverage.svg)](https://gitlab.com/KitaitiMakoto/epub-parser/commits/master)
7
7
 
8
+ * [Homepage][homepage]
9
+ * [Documentation][rubydoc]
10
+ * [Source Code][]
11
+
12
+ [Source Code]: https://gitlab.com/KitaitiMakoto/epub-parser
13
+
8
14
  INSTALLATION
9
15
  -------
10
16
 
@@ -153,6 +159,13 @@ If you find other gems, please tell me or request a pull request.
153
159
  RECENT CHANGES
154
160
  --------------
155
161
 
162
+ ### 0.3.4
163
+
164
+ * Add {EPUB::Publication::Package#full_path} and {EPUB::Publication::Package#rootfile}
165
+ * [BUG FIX]Fix a bug that {EPUB::ContentDocument::Navigation::Item#item} doesn't return correct {EPUB::Publication::Package::Manifest::Item Item}(Thanks [aelkiss][]!)
166
+
167
+ [aelkiss]: https://gitlab.com/aelkiss
168
+
156
169
  ### 0.3.3
157
170
 
158
171
  * [BUG FIX]Use UnpackedURI adapter for URI
@@ -163,25 +176,12 @@ RECENT CHANGES
163
176
 
164
177
  * Use epub-cfi gem for EPUB CFI
165
178
 
166
- ### 0.3.1
167
-
168
- * Make `CFI` comparable. Now can call `CFI#==`
169
- * Include `Publication::Package::Spine::Itemref` in `Searcher.search_element`'s result
170
-
171
- ### 0.3.0
172
-
173
- * Wrong release. I'm sorry.
174
-
175
- ### 0.2.9
176
-
177
- * Fix a bug that `Searcher.search_element` returns wrong CFI
178
- * Add `Searcher.search_by_cfi`
179
-
180
179
  See {file:CHANGELOG.markdown} for older changelogs and details.
181
180
 
182
181
  TODOS
183
182
  -----
184
183
  * EPUB 3.0.1
184
+ * EPUB 3.1
185
185
  * Help features for `epub-open` tool
186
186
  * Vocabulary Association Mechanisms
187
187
  * Implementing navigation document and so on
@@ -82,7 +82,9 @@ module EPUB
82
82
  item.text = extract_attribute(a_or_span, 'title').to_s if item.text.nil? || item.text.empty?
83
83
  end
84
84
  item.href = extract_attribute(a_or_span, 'href')
85
- item.item = @item.manifest.items.find {|it| it.href.request_uri == item.href.request_uri}
85
+ item.item = @item.manifest.items.find {|it|
86
+ it.full_path == @item.full_path + item.href.request_uri
87
+ }
86
88
  end
87
89
  item.items = element.xpath('./xhtml:ol[1]/xhtml:li', EPUB::NAMESPACES).map {|li| parse_navigation_item(li)}
88
90
 
@@ -1,5 +1,5 @@
1
1
  module EPUB
2
2
  class Parser
3
- VERSION = "0.3.3"
3
+ VERSION = "0.3.4"
4
4
  end
5
5
  end
@@ -43,6 +43,18 @@ module EPUB
43
43
  @metadata.unique_identifier
44
44
  end
45
45
 
46
+ # Corresponding {Rootfile}
47
+ # @return [OCF::Container::Rootfile]
48
+ def rootfile
49
+ @book.ocf.container.rootfiles.find {|rf| rf.package == self}
50
+ end
51
+
52
+ # Full path in EPUB archive
53
+ # @return [Addressable::URI]
54
+ def full_path
55
+ rootfile.full_path if rootfile
56
+ end
57
+
46
58
  def inspect
47
59
  "#<%{class}:%{object_id} %{attributes} %{models}>" % {
48
60
  :class => self.class,
@@ -121,8 +121,7 @@ module EPUB
121
121
  # @return [Addressable::URI]
122
122
  def full_path
123
123
  return @full_path if @full_path
124
- rootfile = manifest.package.book.ocf.container.rootfile.full_path
125
- path = DUMMY_ROOT_IRI + rootfile + href
124
+ path = DUMMY_ROOT_IRI + manifest.package.full_path + href
126
125
  path.scheme = nil
127
126
  path.host = nil
128
127
  path.path = path.path[1..-1]
@@ -2,5 +2,6 @@
2
2
  <container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
3
3
  <rootfiles>
4
4
  <rootfile full-path="OPS/ルートファイル.opf" media-type="application/oebps-package+xml" />
5
+ <rootfile full-path="nested/dir/content.opf" media-type="application/oebps-package+xml" />
5
6
  </rootfiles>
6
7
  </container>
@@ -0,0 +1,31 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <package xmlns="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:media="http://www.idpf.org/epub/vocab/overlays/#" version="3.0" unique-identifier="BookId" xml:lang="en" prefix="ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/">
3
+ <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
4
+ <dc:identifier id="BookId">af6e04ec-ca74-4951-a5cd-f0572885a7f9</dc:identifier>
5
+ <meta refines="#BookId" property="identifier-type" scheme="onix:codelist5">22</meta>
6
+ <meta property="dcterms:identifier" id="meta-identifier">BookId</meta>
7
+ <dc:title>Test</dc:title>
8
+ <meta property="dcterms:title" id="meta-title">Test</meta>
9
+ <dc:language>en</dc:language>
10
+ <meta property="dcterms:language" id="meta-language">en</meta>
11
+ <meta property="dcterms:modified">2017-12-05T20:55:41Z</meta>
12
+ <dc:creator id="creator">anonymous</dc:creator>
13
+ <meta refines="#creator" property="file-as">anonymous</meta>
14
+ <meta property="dcterms:publisher">anonymous</meta>
15
+ <dc:publisher>anonymous</dc:publisher>
16
+ <meta property="dcterms:date">2017-12-5</meta>
17
+ <dc:date>2017-12-5</dc:date>
18
+ <meta property="dcterms:rights">see MIT-LICENSE</meta>
19
+ <dc:rights>see MIT-LICENSE</dc:rights>
20
+ <meta name="cover" content="image_cover"/>
21
+ </metadata>
22
+ <manifest>
23
+ <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
24
+ <item id="toc" href="text/toc.xhtml" media-type="application/xhtml+xml" properties="nav"/>
25
+ <item id="content_2_chapter-1" href="text/2_chapter-1.xhtml" media-type="application/xhtml+xml"/>
26
+ </manifest>
27
+ <spine toc="ncx">
28
+ <itemref idref="toc"/>
29
+ <itemref idref="content_2_chapter-1"/>
30
+ </spine>
31
+ </package>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE html>
3
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
4
+ <head>
5
+ <meta charset="UTF-8" />
6
+ <title>Chapter 1</title>
7
+ </head>
8
+ <body><div class="chapter-heading"> <h1 class="chapter-number">1</h1> <h1 class="chapter-title">Chapter 1</h1> </div> <div class="chapter-content"><p class="no-indent">This is the first sentence. This is the next sentence. This is all for Chapter 1.</p> <p><br/></p> </div> </body></html>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
3
+ <head>
4
+ <title>Test</title>
5
+ <meta charset="UTF-8"/>
6
+ </head>
7
+ <body>
8
+ <h1 class="chapter-title">Contents</h1>
9
+ <nav id="toc" epub:type="toc">
10
+ <ol class="toc">
11
+ <li class="toc-chapter">
12
+ <a href="2_chapter-1.xhtml" epub:type="bodymatter">Chapter 1</a>
13
+ <ol class="toc">
14
+
15
+ </ol>
16
+ </li>
17
+ </ol>
18
+ </nav>
19
+ </body>
20
+ </html>
@@ -62,6 +62,8 @@ class TestContentDocument < Test::Unit::TestCase
62
62
 
63
63
  def test_contents_returns_items_of_toc
64
64
  manifest = EPUB::Publication::Package::Manifest.new
65
+ manifest.package = Object.new
66
+ stub(manifest.package).full_path {Addressable::URI.parse("")}
65
67
  item = EPUB::Publication::Package::Manifest::Item.new
66
68
  item.media_type = 'application/xhtml+xml'
67
69
  item.properties = %w[nav]
@@ -109,5 +111,19 @@ class TestContentDocument < Test::Unit::TestCase
109
111
  end
110
112
  end
111
113
  end
114
+
115
+ def test_rexml_returns_rexml_document
116
+ content_doc = XHTML.new
117
+ stub(content_doc).raw_document {File.read(File.join(File.dirname(__FILE__), 'fixtures', 'book', 'OPS', '日本語.xhtml'))}
118
+ doc = content_doc.rexml
119
+ assert_instance_of REXML::Document, doc
120
+ end
121
+
122
+ def test_navigation_item
123
+ book = EPUB::Parser.parse("test/fixtures/book.epub")
124
+ package = book.packages[1]
125
+
126
+ assert_equal "nested/dir/text/2_chapter-1.xhtml", package.manifest.nav.content_document.navigation.items.first.item.full_path.path
127
+ end
112
128
  end
113
129
  end
@@ -10,6 +10,8 @@ class TestParserContentDocument < Test::Unit::TestCase
10
10
  item.href = href
11
11
  @manifest << item
12
12
  end
13
+ @manifest.package = Object.new
14
+ stub(@manifest.package).full_path {"OPS/ルートファイル.opf"}
13
15
 
14
16
  @dir = 'test/fixtures/book'
15
17
  @parser = EPUB::Parser::ContentDocument.new(@manifest.items.last)
@@ -16,8 +16,8 @@ class TestParserOCF < Test::Unit::TestCase
16
16
  }
17
17
  end
18
18
 
19
- def test_parsed_container_has_one_rootfile
20
- assert_equal 1, @parser.parse_container(@container_xml).rootfiles.length
19
+ def test_parsed_container_has_two_rootfiles
20
+ assert_equal 2, @parser.parse_container(@container_xml).rootfiles.length
21
21
  end
22
22
 
23
23
  def test_parse_container_can_find_primary_rootfile
@@ -18,6 +18,23 @@ class TestPublication < Test::Unit::TestCase
18
18
  assert_nil metadata.package
19
19
  end
20
20
 
21
+ def test_full_path_equals_to_corresponding_rootfiles_one
22
+ full_path = Addressable::URI.parse("OPS/content.opf")
23
+ ocf = EPUB::OCF.new
24
+ ocf.container = EPUB::OCF::Container.new
25
+ rootfile = EPUB::OCF::Container::Rootfile.new(full_path)
26
+ rootfile.package = @package
27
+ another_rootfile = Object.new
28
+ stub(another_rootfile).package
29
+ ocf.container.rootfiles << another_rootfile
30
+ ocf.container.rootfiles << rootfile
31
+ book = Object.new
32
+ stub(book).ocf {ocf}
33
+ @package.book = book
34
+
35
+ assert_equal full_path, @package.full_path
36
+ end
37
+
21
38
  class TestMetadata < TestPublication
22
39
  def setup
23
40
  @metadata = Package::Metadata.new
@@ -15,6 +15,7 @@ class TestSearcher < Test::Unit::TestCase
15
15
  itemref.idref == 'nav' ? File.read(nav_path) : '<html></html>'
16
16
  }
17
17
  end
18
+ stub(@package).full_path {"OPS/ルートファイル.opf"}
18
19
  end
19
20
 
20
21
  def test_no_result
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epub-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - KITAITI Makoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-02 00:00:00.000000000 Z
11
+ date: 2018-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -371,6 +371,9 @@ files:
371
371
  - test/fixtures/book/OPS/ルートファイル.opf
372
372
  - test/fixtures/book/OPS/日本語.xhtml
373
373
  - test/fixtures/book/mimetype
374
+ - test/fixtures/book/nested/dir/content.opf
375
+ - test/fixtures/book/nested/dir/text/2_chapter-1.xhtml
376
+ - test/fixtures/book/nested/dir/text/toc.xhtml
374
377
  - test/helper.rb
375
378
  - test/test_content_document.rb
376
379
  - test/test_epub.rb