epub-parser 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +5 -0
- data/README.adoc +5 -0
- data/Rakefile +4 -14
- data/docs/Home.adoc +2 -2
- data/lib/epub/constants.rb +1 -0
- data/lib/epub/parser/metadata.rb +2 -1
- data/lib/epub/parser/version.rb +1 -1
- data/lib/epub/parser/xml_document.rb +7 -4
- data/test/helper.rb +0 -1
- data/test/test_parser_xmldocument.rb +82 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5961049ade105ba54596ed40e0c6ff1f492b48fbb37957b90ce0a35bff61fda1
|
4
|
+
data.tar.gz: 1c6d046515c6dd279a113b69040eae5d713813a35561b960882571cd02356792
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d295d2df9ea39e38a52140e1c812901edc21189c98ad32c2ed25e1078372099483b4d671ca2a1a320d0c5c05f179762bf6ad9b27f960c40b3eb9548b1053239
|
7
|
+
data.tar.gz: e45a6b0d495458fa4de9b9aaff379f0d20d11723bf8d7bac30686045811387d6ee641fb759c6b5bc218c1de8f309d1d8a981db03e1e9a6b16da2bc3f62eb5d92
|
data/CHANGELOG.adoc
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
= CHANGELOG
|
2
2
|
|
3
|
+
== 0.3.9
|
4
|
+
|
5
|
+
* [BUG FIX]Set {EPUB::Metadata::DCMES#lang} properly from xml:lang attribute
|
6
|
+
* Change default XML backend from REXML to Nokogiri
|
7
|
+
|
3
8
|
== 0.3.8
|
4
9
|
|
5
10
|
* [REFACTORING]Add {EPUB::Parser::NokogiriAttributeWithPrefix} and use `Nokogiri::XML::Node#attribute_with_prefix` instead of `EPUB::Parser::Utils#extract_attribute`
|
data/README.adoc
CHANGED
@@ -174,6 +174,11 @@ If you find other gems, please tell me or request a pull request.
|
|
174
174
|
|
175
175
|
== RECENT CHANGES
|
176
176
|
|
177
|
+
=== 0.3.9
|
178
|
+
|
179
|
+
* [BUG FIX]Set {EPUB::Metadata::DCMES#lang} properly from xml:lang attribute
|
180
|
+
* Change default XML backend from REXML to Nokogiri
|
181
|
+
|
177
182
|
=== 0.3.8
|
178
183
|
|
179
184
|
* [REFACTORING]Add {EPUB::Parser::NokogiriAttributeWithPrefix} and use `Nokogiri::XML::Node#attribute_with_prefix` instead of `EPUB::Parser::Utils#extract_attribute`
|
data/Rakefile
CHANGED
@@ -39,21 +39,11 @@ namespace :test do
|
|
39
39
|
File.rename "#{input_dir}.epub.tmp", "#{input_dir}.epub"
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
task
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
Rake::TestTask.new "test_with_#{xml_backend.downcase}" do |task|
|
49
|
-
task.test_files = FileList['test/**/test_*.rb']
|
50
|
-
task.warning = true
|
51
|
-
task.options = '--no-show-detail-immediately --verbose'
|
52
|
-
EPUB::Parser::XMLDocument.backend = xml_backend
|
53
|
-
end
|
54
|
-
task "test_with_#{xml_backend.downcase}" => "set_xml_backend_#{xml_backend.downcase}"
|
42
|
+
Rake::TestTask.new do |task|
|
43
|
+
task.test_files = FileList['test/**/test_*.rb']
|
44
|
+
task.warning = true
|
45
|
+
task.options = '--no-show-detail-immediately --verbose'
|
55
46
|
end
|
56
|
-
task :test => [:test_with_rexml, :test_with_nokogiri]
|
57
47
|
end
|
58
48
|
|
59
49
|
task :doc => 'doc:default'
|
data/docs/Home.adoc
CHANGED
@@ -119,10 +119,10 @@ ret == book # => true; this API is not good I feel... Welcome suggestion!
|
|
119
119
|
|
120
120
|
==== Switching XML Library
|
121
121
|
|
122
|
-
EPUB Parser uses https://
|
122
|
+
EPUB Parser uses https://www.nokogiri.org/[Nokogiri], a Ruby bindings for http://xmlsoft.org/[Libxml2] and http://xmlsoft.org/XSLT/[Libxslt] and more if you have already installed Nokogiri gem by RubyGems or Bundler. If Nokogiri is not available, it fallbacks to https://ruby-doc.org/stdlib-2.5.3/libdoc/rexml/rdoc/index.html[REXML], a standard-bundled library. You can also specify REXML explicitly:
|
123
123
|
|
124
124
|
----
|
125
|
-
EPUB::Parser::XMLDocument.backend = :
|
125
|
+
EPUB::Parser::XMLDocument.backend = :REXML
|
126
126
|
----
|
127
127
|
|
128
128
|
==== Switching ZIP library
|
data/lib/epub/constants.rb
CHANGED
data/lib/epub/parser/metadata.rb
CHANGED
@@ -88,7 +88,8 @@ module EPUB
|
|
88
88
|
model = EPUB::Metadata.const_get(klass).new
|
89
89
|
attributes.each do |attr|
|
90
90
|
writer_name = (attr == "content") ? "meta_content=" : "#{attr.gsub('-', '_')}="
|
91
|
-
|
91
|
+
namespace = (attr == "lang") ? "xml" : nil
|
92
|
+
model.__send__ writer_name, elem.attribute_with_prefix(attr, namespace)
|
92
93
|
end
|
93
94
|
model.content = elem.content unless klass == :Link
|
94
95
|
model.content.strip! if klass == :Identifier
|
data/lib/epub/parser/version.rb
CHANGED
@@ -1,8 +1,4 @@
|
|
1
1
|
require "rexml/document"
|
2
|
-
begin
|
3
|
-
require "nokogiri"
|
4
|
-
rescue LoadError
|
5
|
-
end
|
6
2
|
|
7
3
|
module EPUB
|
8
4
|
class Parser
|
@@ -19,6 +15,13 @@ module EPUB
|
|
19
15
|
end
|
20
16
|
end
|
21
17
|
|
18
|
+
begin
|
19
|
+
require "nokogiri"
|
20
|
+
@backend = :Nokogiri
|
21
|
+
rescue LoadError
|
22
|
+
@backend = :REXML
|
23
|
+
end
|
24
|
+
|
22
25
|
module Refinements
|
23
26
|
[REXML::Element, REXML::Text].each do |klass|
|
24
27
|
refine klass do
|
data/test/helper.rb
CHANGED
@@ -0,0 +1,82 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative "helper"
|
3
|
+
|
4
|
+
class TestParserXMLDocument < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@container = File.read("test/fixtures/book/META-INF/container.xml")
|
7
|
+
@opf = File.read("test/fixtures/book/OPS/ルートファイル.opf")
|
8
|
+
@nav = File.read("test/fixtures/book/OPS/nav.xhtml")
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_parse_container
|
12
|
+
EPUB::Parser::XMLDocument.backend = :REXML
|
13
|
+
rexml_container = EPUB::Parser::OCF.new(nil).parse_container(@container)
|
14
|
+
EPUB::Parser::XMLDocument.backend = :Nokogiri
|
15
|
+
nokogiri_container = EPUB::Parser::OCF.new(nil).parse_container(@container)
|
16
|
+
|
17
|
+
assert_equal rexml_container.rootfiles.length, nokogiri_container.rootfiles.length
|
18
|
+
rexml_container.rootfiles.each do |rootfile|
|
19
|
+
rf = nokogiri_container.rootfiles.find {|rf| rf.full_path == rootfile.full_path}
|
20
|
+
assert_equal rootfile.full_path, rf.full_path
|
21
|
+
assert_equal rootfile.media_type, rf.media_type
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_parse_package_document
|
26
|
+
EPUB::Parser::XMLDocument.backend = :REXML
|
27
|
+
rexml_package = EPUB::Parser::Publication.new(@opf).parse
|
28
|
+
EPUB::Parser::XMLDocument.backend = :Nokogiri
|
29
|
+
nokogiri_package = EPUB::Parser::Publication.new(@opf).parse
|
30
|
+
|
31
|
+
%i[version prefix xml_lang dir id].each do |attr|
|
32
|
+
assert_equal rexml_package.send(attr), nokogiri_package.send(attr)
|
33
|
+
end
|
34
|
+
|
35
|
+
EPUB::Metadata::DC_ELEMS.each do |attr|
|
36
|
+
rexml_attr = rexml_package.metadata.send(attr)
|
37
|
+
nokogiri_attr = nokogiri_package.metadata.send(attr)
|
38
|
+
|
39
|
+
assert_equal rexml_attr.length, nokogiri_attr.length
|
40
|
+
|
41
|
+
rexml_attr.each_with_index do |model, index|
|
42
|
+
%i[content id lang dir].each do |a|
|
43
|
+
assert_equal model.send(a), nokogiri_attr[index].send(a)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
rexml_package.metadata.metas.each_with_index do |meta, index|
|
49
|
+
%i[property id scheme content name meta_content].each do |attr|
|
50
|
+
assert_equal meta.send(attr), nokogiri_package.metadata.metas[index].send(attr)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
rexml_package.metadata.links.each_with_index do |link, index|
|
55
|
+
%i[href rel id media_type].each do |attr|
|
56
|
+
assert_equal link.send(attr), nokogiri_package.metadata.links[index].send(attr)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_parse_navigation
|
62
|
+
EPUB::Parser::XMLDocument.backend = :REXML
|
63
|
+
rexml_nav = EPUB::Parser.parse("test/fixtures/book.epub").nav.content_document
|
64
|
+
EPUB::Parser::XMLDocument.backend = :Nokogiri
|
65
|
+
nokogiri_nav = EPUB::Parser.parse("test/fixtures/book.epub").nav.content_document
|
66
|
+
|
67
|
+
assert_equal rexml_nav.navigations.length, nokogiri_nav.navigations.length
|
68
|
+
|
69
|
+
rexml_nav.navigations.each_with_index do |item, index|
|
70
|
+
nokogiri_item = nokogiri_nav.navigations[index]
|
71
|
+
%i[text content_document type].each do |attr|
|
72
|
+
assert_equal item.send(attr), nokogiri_item.send(attr)
|
73
|
+
end
|
74
|
+
|
75
|
+
item.items.each_with_index do |i, index2|
|
76
|
+
%i[text content_document].each do |attr|
|
77
|
+
assert_equal i.send(attr), nokogiri_item.items[index2].send(attr)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
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.
|
4
|
+
version: 0.3.9
|
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-
|
11
|
+
date: 2018-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -407,6 +407,7 @@ files:
|
|
407
407
|
- test/test_parser_fixed_layout.rb
|
408
408
|
- test/test_parser_ocf.rb
|
409
409
|
- test/test_parser_publication.rb
|
410
|
+
- test/test_parser_xmldocument.rb
|
410
411
|
- test/test_publication.rb
|
411
412
|
- test/test_searcher.rb
|
412
413
|
homepage: https://kitaitimakoto.gitlab.io/epub-parser/file.Home.html
|
@@ -445,5 +446,6 @@ test_files:
|
|
445
446
|
- test/test_parser_fixed_layout.rb
|
446
447
|
- test/test_parser_ocf.rb
|
447
448
|
- test/test_parser_publication.rb
|
449
|
+
- test/test_parser_xmldocument.rb
|
448
450
|
- test/test_publication.rb
|
449
451
|
- test/test_searcher.rb
|