epub-parser 0.3.9 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +4 -4
- data/CHANGELOG.adoc +5 -0
- data/README.adoc +4 -12
- data/docs/Home.adoc +0 -1
- data/epub-parser.gemspec +1 -0
- data/lib/epub/content_document/navigation.rb +24 -1
- data/lib/epub/parser/content_document.rb +1 -1
- data/lib/epub/parser/version.rb +1 -1
- data/lib/epub/parser/xml_document.rb +8 -63
- data/lib/epub/parser/xml_document/refinements/nokogiri.rb +33 -0
- data/lib/epub/parser/xml_document/refinements/rexml.rb +43 -0
- data/lib/epub/searcher/publication.rb +5 -4
- data/test/fixtures/book/OPS/nav.xhtml +1 -1
- data/test/test_parser_content_document.rb +1 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8eeea7d5a67b4f9aaa7c71088837f4bb7156090c48e5411628e960de7b24233
|
4
|
+
data.tar.gz: b4d0b181946da274c66927caea49cf59c62d5507cd9543dde59bf1d3deae43d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f9441b1dd0b6c4ac0d8acf04ff35fcdd0df4d3e880bb8a496e4a2e5127d99dc2ffc98927dd9d9907327cef08b7e8b76280f324cc1543ca38b7c80fe824fd8f1
|
7
|
+
data.tar.gz: 158ac997006c5ee7967132c294d6f4183dbb4dc29927653dca49e05399c63793929910beb9cd2673d8a9ea5b5175adff5f45bc712097e8b5055cb1e69df9565e
|
data/.gitlab-ci.yml
CHANGED
@@ -39,7 +39,7 @@ test:2.5:
|
|
39
39
|
- deps
|
40
40
|
|
41
41
|
test:2.6:
|
42
|
-
image: ruby:2.6
|
42
|
+
image: ruby:2.6
|
43
43
|
script: bundle exec rake test
|
44
44
|
except:
|
45
45
|
- tags
|
@@ -51,9 +51,9 @@ test:2.6:
|
|
51
51
|
pages:
|
52
52
|
stage: deploy
|
53
53
|
dependencies:
|
54
|
-
- test:2.
|
54
|
+
- test:2.6
|
55
55
|
script:
|
56
|
-
- bundle exec rake doc:yard
|
56
|
+
- bundle exec rake test doc:yard
|
57
57
|
- mv doc public
|
58
58
|
- mv coverage public/
|
59
59
|
artifacts:
|
@@ -62,6 +62,6 @@ pages:
|
|
62
62
|
only:
|
63
63
|
- master
|
64
64
|
cache:
|
65
|
-
key: ruby:2.
|
65
|
+
key: ruby:2.6
|
66
66
|
paths:
|
67
67
|
- deps
|
data/CHANGELOG.adoc
CHANGED
data/README.adoc
CHANGED
@@ -174,6 +174,10 @@ If you find other gems, please tell me or request a pull request.
|
|
174
174
|
|
175
175
|
== RECENT CHANGES
|
176
176
|
|
177
|
+
=== 0.4.0
|
178
|
+
|
179
|
+
* [BUG FIX]Make epub:type a Set
|
180
|
+
|
177
181
|
=== 0.3.9
|
178
182
|
|
179
183
|
* [BUG FIX]Set {EPUB::Metadata::DCMES#lang} properly from xml:lang attribute
|
@@ -186,18 +190,6 @@ If you find other gems, please tell me or request a pull request.
|
|
186
190
|
* Make XML library switchable between REXML and Nokogiri
|
187
191
|
* Make REXML a default XML backend
|
188
192
|
|
189
|
-
=== 0.3.7
|
190
|
-
|
191
|
-
* Strip leading and trailing white spaces from identifiers
|
192
|
-
* Change home page and documentation from rubydoc.info to GitLab Pages
|
193
|
-
* Make {EPUB::Book::Features#cover_image Book::Features#cover_image} return EPUB 2 cover image if EPUB 3's not available
|
194
|
-
* Add `epub-cover` command-line tool. See {file:docs/EpubCover.adoc} for details.
|
195
|
-
|
196
|
-
=== 0.3.6
|
197
|
-
|
198
|
-
* [BUG FIX]Ignore fragment when find item by relative IRI
|
199
|
-
* Disable https://github.com/ko1/pretty_backtrace[PrettyBacktrace] by default
|
200
|
-
|
201
193
|
See {file:CHANGELOG.adoc} for older changelogs and details.
|
202
194
|
|
203
195
|
== TODOS
|
data/docs/Home.adoc
CHANGED
@@ -5,7 +5,6 @@
|
|
5
5
|
EPUB Parser gem parses EPUB 3 book loosely.
|
6
6
|
|
7
7
|
image:https://gitlab.com/KitaitiMakoto/epub-parser/badges/master/build.svg[link="https://gitlab.com/KitaitiMakoto/epub-parser/commits/master", title="pipeline status"]
|
8
|
-
image:https://gemnasium.com/KitaitiMakoto/epub-parser.png[link="https://gitlab.com/KitaitiMakoto/epub-parser/commits/master",title="Dependency Status"]
|
9
8
|
image:https://badge.fury.io/rb/epub-parser.svg[link="https://gemnasium.com/KitaitiMakoto/epub-parser",title="Gem Version"]
|
10
9
|
image:https://gitlab.com/KitaitiMakoto/epub-parser/badges/master/coverage.svg[link="https://kitaitimakoto.gitlab.io/epub-parser/coverage/",title="coverage report"]
|
11
10
|
|
data/epub-parser.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.test_files = s.files & Dir['{test,spec,features}/**/*.{rb,feature}']
|
24
24
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
25
|
s.require_paths = ["lib"]
|
26
|
+
s.metadata["yard.run"] = "yard"
|
26
27
|
|
27
28
|
s.add_development_dependency 'rake'
|
28
29
|
s.add_development_dependency 'rubygems-tasks'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "set"
|
2
|
+
|
1
3
|
module EPUB
|
2
4
|
module ContentDocument
|
3
5
|
class Navigation < XHTML
|
@@ -99,12 +101,33 @@ module EPUB
|
|
99
101
|
LANDMARKS = 'landmarks'
|
100
102
|
end
|
101
103
|
|
102
|
-
|
104
|
+
attr_reader :types
|
103
105
|
alias navigations items
|
104
106
|
alias navigations= items=
|
105
107
|
alias heading text
|
106
108
|
alias heading= text=
|
107
109
|
|
110
|
+
def initialize
|
111
|
+
super
|
112
|
+
@types = Set.new
|
113
|
+
end
|
114
|
+
|
115
|
+
def types=(ts)
|
116
|
+
@types = ts.kind_of?(Set) ? ts : Set.new(ts)
|
117
|
+
end
|
118
|
+
|
119
|
+
# For backward compatibility
|
120
|
+
def type
|
121
|
+
@types.find {|t|
|
122
|
+
%w[toc page_list landmarks].include? t
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
# For backward compatibility
|
127
|
+
def type=(t)
|
128
|
+
@types << t
|
129
|
+
end
|
130
|
+
|
108
131
|
%w[toc page_list landmarks].each do |type|
|
109
132
|
define_method "#{type}?" do
|
110
133
|
type == Type.const_get(type.upcase)
|
@@ -48,7 +48,7 @@ module EPUB
|
|
48
48
|
nav.text = find_heading(element)
|
49
49
|
hidden = element.attribute_with_prefix('hidden')
|
50
50
|
nav.hidden = hidden.nil? ? nil : true
|
51
|
-
nav.
|
51
|
+
nav.types = element.attribute_with_prefix('type', 'epub')&.split(/\s+/)
|
52
52
|
element.each_element_by_xpath('./xhtml:ol/xhtml:li', EPUB::NAMESPACES).map do |elem|
|
53
53
|
nav.items << parse_navigation_item(elem)
|
54
54
|
end
|
data/lib/epub/parser/version.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require "rexml/document"
|
2
|
-
|
3
1
|
module EPUB
|
4
2
|
class Parser
|
5
3
|
class XMLDocument
|
@@ -14,67 +12,14 @@ module EPUB
|
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
17
|
-
|
18
|
-
begin
|
19
|
-
require "nokogiri"
|
20
|
-
@backend = :Nokogiri
|
21
|
-
rescue LoadError
|
22
|
-
@backend = :REXML
|
23
|
-
end
|
24
|
-
|
25
|
-
module Refinements
|
26
|
-
[REXML::Element, REXML::Text].each do |klass|
|
27
|
-
refine klass do
|
28
|
-
%i[document element text].each do |type|
|
29
|
-
define_method "#{type}?" do
|
30
|
-
node_type == type
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
refine REXML::Element do
|
37
|
-
def each_element_by_xpath(xpath, namespaces = nil, &block)
|
38
|
-
REXML::XPath.each self, xpath, namespaces, &block
|
39
|
-
end
|
40
|
-
|
41
|
-
def attribute_with_prefix(name, prefix = nil)
|
42
|
-
attribute(name, EPUB::NAMESPACES[prefix])&.value
|
43
|
-
end
|
44
|
-
|
45
|
-
alias namespace_uri namespace
|
46
|
-
|
47
|
-
def content
|
48
|
-
texts.join
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
refine REXML::Text do
|
53
|
-
alias content value
|
54
|
-
end
|
55
|
-
|
56
|
-
if const_defined? :Nokogiri
|
57
|
-
refine Nokogiri::XML::Node do
|
58
|
-
def each_element_by_xpath(xpath, namespaces = nil, &block)
|
59
|
-
xpath(xpath, namespaces).each &block
|
60
|
-
end
|
61
|
-
|
62
|
-
def attribute_with_prefix(name, prefix = nil)
|
63
|
-
attribute_with_ns(name, EPUB::NAMESPACES[prefix])&.value
|
64
|
-
end
|
65
|
-
|
66
|
-
def each_element(xpath = nil, &block)
|
67
|
-
element_children.each(&block)
|
68
|
-
end
|
69
|
-
|
70
|
-
alias elements element_children
|
71
|
-
|
72
|
-
def namespace_uri
|
73
|
-
namespace.href
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
15
|
end
|
79
16
|
end
|
80
17
|
end
|
18
|
+
|
19
|
+
require "epub/parser/xml_document/refinements/rexml"
|
20
|
+
begin
|
21
|
+
require "epub/parser/xml_document/refinements/nokogiri"
|
22
|
+
EPUB::Parser::XMLDocument.backend = :Nokogiri
|
23
|
+
rescue LoadError
|
24
|
+
EPUB::Parser::XMLDocument.backend = :REXML
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
|
3
|
+
module EPUB
|
4
|
+
class Parser
|
5
|
+
class XMLDocument
|
6
|
+
module Refinements
|
7
|
+
module Nokogiri
|
8
|
+
refine ::Nokogiri::XML::Node do
|
9
|
+
def each_element_by_xpath(xpath, namespaces = nil, &block)
|
10
|
+
xpath(xpath, namespaces).each &block
|
11
|
+
end
|
12
|
+
|
13
|
+
def attribute_with_prefix(name, prefix = nil)
|
14
|
+
attribute_with_ns(name, EPUB::NAMESPACES[prefix])&.value
|
15
|
+
end
|
16
|
+
|
17
|
+
def each_element(xpath = nil, &block)
|
18
|
+
element_children.each(&block)
|
19
|
+
end
|
20
|
+
|
21
|
+
alias elements element_children
|
22
|
+
|
23
|
+
def namespace_uri
|
24
|
+
namespace.href
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
include Nokogiri
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "rexml/document"
|
2
|
+
|
3
|
+
module EPUB
|
4
|
+
class Parser
|
5
|
+
class XMLDocument
|
6
|
+
module Refinements
|
7
|
+
module REXML
|
8
|
+
[::REXML::Element, ::REXML::Text].each do |klass|
|
9
|
+
refine klass do
|
10
|
+
%i[document element text].each do |type|
|
11
|
+
define_method "#{type}?" do
|
12
|
+
node_type == type
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
refine ::REXML::Element do
|
19
|
+
def each_element_by_xpath(xpath, namespaces = nil, &block)
|
20
|
+
::REXML::XPath.each self, xpath, namespaces, &block
|
21
|
+
end
|
22
|
+
|
23
|
+
def attribute_with_prefix(name, prefix = nil)
|
24
|
+
attribute(name, EPUB::NAMESPACES[prefix])&.value
|
25
|
+
end
|
26
|
+
|
27
|
+
alias namespace_uri namespace
|
28
|
+
|
29
|
+
def content
|
30
|
+
texts.join
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
refine ::REXML::Text do
|
35
|
+
alias content value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
include REXML
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -24,6 +24,7 @@ module EPUB
|
|
24
24
|
@package = package
|
25
25
|
end
|
26
26
|
|
27
|
+
# @return [Array<Result>]
|
27
28
|
def search_text(word, algorithm: :seamless)
|
28
29
|
results = []
|
29
30
|
|
@@ -41,10 +42,10 @@ module EPUB
|
|
41
42
|
|
42
43
|
# @todo: Refactoring
|
43
44
|
# @return [Array<Hash>] An array of rearch results. Each result is composed of:
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
45
|
+
# * +:element+: [REXML::Element, Nokogiri::XML::ELement] Found element
|
46
|
+
# * +:itemref+: [EPUB::Publication::Package::Spine::Itemref] Itemref that element's document belongs to
|
47
|
+
# * +:location+: [EPUB::CFI::Location] CFI that indicates the element
|
48
|
+
# * +:package+: [EPUB::Publication::Package] Package that the element belongs to
|
48
49
|
def search_element(css: nil, xpath: nil, namespaces: {})
|
49
50
|
raise ArgumentError, 'Both css and xpath are nil' if css.nil? && xpath.nil?
|
50
51
|
|
@@ -25,6 +25,7 @@ class TestParserContentDocument < Test::Unit::TestCase
|
|
25
25
|
assert_equal 1, navs.length
|
26
26
|
assert_equal 'Table of Contents', nav.heading
|
27
27
|
assert_equal 'toc', nav.type
|
28
|
+
assert_equal Set.new(["toc", "frontmatter"]), nav.types
|
28
29
|
|
29
30
|
assert_equal 2, nav.items.length
|
30
31
|
assert_equal @manifest.items.first, nav.items.first.item
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KITAITI Makoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -364,6 +364,8 @@ files:
|
|
364
364
|
- lib/epub/parser/publication.rb
|
365
365
|
- lib/epub/parser/version.rb
|
366
366
|
- lib/epub/parser/xml_document.rb
|
367
|
+
- lib/epub/parser/xml_document/refinements/nokogiri.rb
|
368
|
+
- lib/epub/parser/xml_document/refinements/rexml.rb
|
367
369
|
- lib/epub/publication.rb
|
368
370
|
- lib/epub/publication/fixed_layout.rb
|
369
371
|
- lib/epub/publication/package.rb
|
@@ -413,7 +415,8 @@ files:
|
|
413
415
|
homepage: https://kitaitimakoto.gitlab.io/epub-parser/file.Home.html
|
414
416
|
licenses:
|
415
417
|
- MIT
|
416
|
-
metadata:
|
418
|
+
metadata:
|
419
|
+
yard.run: yard
|
417
420
|
post_install_message:
|
418
421
|
rdoc_options: []
|
419
422
|
require_paths:
|
@@ -429,8 +432,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
429
432
|
- !ruby/object:Gem::Version
|
430
433
|
version: '0'
|
431
434
|
requirements: []
|
432
|
-
|
433
|
-
rubygems_version: 2.7.6
|
435
|
+
rubygems_version: 3.0.3
|
434
436
|
signing_key:
|
435
437
|
specification_version: 4
|
436
438
|
summary: EPUB 3 Parser
|