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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02fa97ea55de70030b58276b77bfbba26d43f5f99a77c7bffb86aec8b6afaf9e
4
- data.tar.gz: c07fe68a8715101082628bb10fee8f3869d3874467aeba8598df89e79a72e442
3
+ metadata.gz: 5961049ade105ba54596ed40e0c6ff1f492b48fbb37957b90ce0a35bff61fda1
4
+ data.tar.gz: 1c6d046515c6dd279a113b69040eae5d713813a35561b960882571cd02356792
5
5
  SHA512:
6
- metadata.gz: 7c03dcea199c65a84f1c184bbfa07c6d42583167ab26398e3159ec421e2c3205b57e39200d006f22f7f3fbf6dbb7567a7b9424d309123e724dc59ce584ee790e
7
- data.tar.gz: a04003670af41618c26ecb7acd1ec0cda0063961b40c3b5fa0c9d6de21e2c7462eaac7205d6a577df69a05056f04f85ec8cf9044262e2d6bd9c24933d2ca4c04
6
+ metadata.gz: 8d295d2df9ea39e38a52140e1c812901edc21189c98ad32c2ed25e1078372099483b4d671ca2a1a320d0c5c05f179762bf6ad9b27f960c40b3eb9548b1053239
7
+ data.tar.gz: e45a6b0d495458fa4de9b9aaff379f0d20d11723bf8d7bac30686045811387d6ee641fb759c6b5bc218c1de8f309d1d8a981db03e1e9a6b16da2bc3f62eb5d92
@@ -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`
@@ -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
- # TODO: Test with both REXML and Nokogiri in testing framework
43
- %w[REXML Nokogiri].each do |xml_backend|
44
- task "set_xml_backend_#{xml_backend.downcase}" do
45
- ENV["EPUB_PARSER_XML_BACKEND"] = xml_backend
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'
@@ -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://ruby-doc.org/stdlib-2.5.3/libdoc/rexml/rdoc/index.html[REXML], a standard-bundled library, by default. You can use 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.
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 = :Nokogiri
125
+ EPUB::Parser::XMLDocument.backend = :REXML
126
126
  ----
127
127
 
128
128
  ==== Switching ZIP library
@@ -1,5 +1,6 @@
1
1
  module EPUB
2
2
  NAMESPACES = {
3
+ 'xml' => 'http://www.w3.org/XML/1998/namespace',
3
4
  'dc' => 'http://purl.org/dc/elements/1.1/',
4
5
  'ocf' => 'urn:oasis:names:tc:opendocument:xmlns:container',
5
6
  'opf' => 'http://www.idpf.org/2007/opf',
@@ -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
- model.__send__ writer_name, elem.attribute_with_prefix(attr)
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
@@ -1,5 +1,5 @@
1
1
  module EPUB
2
2
  class Parser
3
- VERSION = "0.3.8"
3
+ VERSION = "0.3.9"
4
4
  end
5
5
  end
@@ -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
@@ -15,4 +15,3 @@ if ENV["PRETTY_BACKTRACE"]
15
15
  end
16
16
 
17
17
  require 'epub/parser'
18
- EPUB::Parser::XMLDocument.backend = ENV["EPUB_PARSER_XML_BACKEND"].to_sym
@@ -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.8
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-10-29 00:00:00.000000000 Z
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