epub-parser 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +7 -0
- data/README.markdown +5 -0
- data/bin/epub-open +3 -1
- data/bin/epubinfo +1 -0
- data/docs/FixedLayout.markdown +1 -1
- data/docs/Home.markdown +3 -0
- data/docs/UnpackedArchive.markdown +113 -0
- data/epub-parser.gemspec +0 -1
- data/lib/epub/book/features.rb +8 -0
- data/lib/epub/content_document/navigation.rb +3 -0
- data/lib/epub/ocf/physical_container.rb +50 -0
- data/lib/epub/ocf/physical_container/file.rb +15 -0
- data/lib/epub/ocf/physical_container/zipruby.rb +28 -0
- data/lib/epub/parser.rb +13 -7
- data/lib/epub/parser/ocf.rb +7 -7
- data/lib/epub/parser/publication.rb +2 -2
- data/lib/epub/parser/version.rb +1 -1
- data/lib/epub/publication/package/manifest.rb +1 -3
- data/lib/epub/searcher/xhtml.rb +5 -0
- data/test/test_ocf_physical_container.rb +73 -0
- data/test/test_parser.rb +22 -0
- data/test/test_parser_ocf.rb +6 -7
- metadata +8 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0da9ce97158d8bd76d740d45a8df755f7016c32c
|
4
|
+
data.tar.gz: 79c264c87d61cf10c2cf3f3bd9fd6dd316756b98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba7491533f29d1cbf2350b23e24c5a786eda2db6d51f0f07b002b94103a52dc4322e0c265bc83cdc2b85054f582f1e977d94f7aa3c2b7fa43138781821f493a2
|
7
|
+
data.tar.gz: a3d50715ac0c54fbd0093507651fbd22da5448d4bb28c62bb9adc15c6c9c80a4a40c793c42adaba8f2d53e81561ca739cd5ebf2f2c6d7989e2d9a5c44d045536
|
data/CHANGELOG.markdown
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
+
0.2.0
|
5
|
+
-----
|
6
|
+
|
7
|
+
* Introduce abstraction layer for OCF physical container
|
8
|
+
* Add `EPUB::OCF::PhysicalContainer::File` and make it possible to parse file system directory an EPUB file. See {file:docs/UnpackedArchive.markdown} for details.
|
9
|
+
* Remove `EPUB::Parser::OCF::CONTAINER_FILE` and other constants
|
10
|
+
|
4
11
|
0.1.9
|
5
12
|
-----
|
6
13
|
|
data/README.markdown
CHANGED
@@ -110,6 +110,10 @@ If you find other gems, please tell me or request a pull request.
|
|
110
110
|
RECENT CHANGES
|
111
111
|
--------------
|
112
112
|
|
113
|
+
### 0.2.0
|
114
|
+
|
115
|
+
* Make it possible to parse file system directory an EPUB file. See {file:docs/UnpackedArchive.markdown} for details.
|
116
|
+
|
113
117
|
### 0.1.9
|
114
118
|
|
115
119
|
* Introduce [Nokogumbo][] for XHTML Content Documents
|
@@ -160,6 +164,7 @@ DONE
|
|
160
164
|
* Content Document(only for Navigation Documents)
|
161
165
|
* Fixed Layout
|
162
166
|
* Vocabulary Association Mechanisms(only for itemref)
|
167
|
+
* Archive library abstraction
|
163
168
|
|
164
169
|
LICENSE
|
165
170
|
-------
|
data/bin/epub-open
CHANGED
@@ -20,6 +20,8 @@ EOB
|
|
20
20
|
|
21
21
|
$0 = File.basename($PROGRAM_NAME)
|
22
22
|
include EPUB::Book::Features
|
23
|
-
|
23
|
+
file = ARGV.shift
|
24
|
+
EPUB::OCF::PhysicalContainer.adapter = :File if File.directory? file
|
25
|
+
EPUB::Parser.parse(file, :book => self)
|
24
26
|
$stderr.puts "Enter \"exit\" to exit #{shell}"
|
25
27
|
shell.start
|
data/bin/epubinfo
CHANGED
data/docs/FixedLayout.markdown
CHANGED
data/docs/Home.markdown
CHANGED
@@ -95,6 +95,9 @@ More documentations are avaiable in:
|
|
95
95
|
* {file:docs/Publication.markdown}
|
96
96
|
* {file:docs/Item.markdown}
|
97
97
|
* {file:docs/FixedLayout.markdown}
|
98
|
+
* {file:docs/Navigation.markdown}
|
99
|
+
* {file:docs/Searcher.markdown}
|
100
|
+
* {file:docs/UnpackedArchive.markdown}
|
98
101
|
|
99
102
|
Requirements
|
100
103
|
------------
|
@@ -0,0 +1,113 @@
|
|
1
|
+
{file:docs/Home.markdown} > **{file:docs/UnpackedArchive.markdown}**
|
2
|
+
|
3
|
+
Unpacked Archive
|
4
|
+
================
|
5
|
+
|
6
|
+
From version 0.2.0, EPUB Parser can parse EPUB books from unpacked archive, or file system directory.
|
7
|
+
|
8
|
+
Let's parse pretty comic Page Blanche:
|
9
|
+
|
10
|
+
% tree page-blanche
|
11
|
+
page-blanche
|
12
|
+
├── EPUB
|
13
|
+
│ ├── Content
|
14
|
+
│ │ ├── PageBlanche_Page_000.xhtml
|
15
|
+
│ │ ├── PageBlanche_Page_001.xhtml
|
16
|
+
│ │ ├── PageBlanche_Page_002.xhtml
|
17
|
+
│ │ ├── PageBlanche_Page_003.xhtml
|
18
|
+
│ │ ├── PageBlanche_Page_004.xhtml
|
19
|
+
│ │ ├── PageBlanche_Page_005.xhtml
|
20
|
+
│ │ ├── PageBlanche_Page_006.xhtml
|
21
|
+
│ │ ├── PageBlanche_Page_007.xhtml
|
22
|
+
│ │ ├── PageBlanche_Page_008.xhtml
|
23
|
+
│ │ └── cover.xhtml
|
24
|
+
│ ├── Image
|
25
|
+
│ │ ├── PageBlanche_Page_001.jpg
|
26
|
+
│ │ ├── PageBlanche_Page_002.jpg
|
27
|
+
│ │ ├── PageBlanche_Page_003.jpg
|
28
|
+
│ │ ├── PageBlanche_Page_004.jpg
|
29
|
+
│ │ ├── PageBlanche_Page_005.jpg
|
30
|
+
│ │ ├── PageBlanche_Page_006.jpg
|
31
|
+
│ │ ├── PageBlanche_Page_007.jpg
|
32
|
+
│ │ ├── PageBlanche_Page_008.jpg
|
33
|
+
│ │ └── cover.jpg
|
34
|
+
│ ├── Navigation
|
35
|
+
│ │ ├── nav.xhtml
|
36
|
+
│ │ └── toc.ncx
|
37
|
+
│ ├── Style
|
38
|
+
│ │ └── style.css
|
39
|
+
│ └── package.opf
|
40
|
+
├── META-INF
|
41
|
+
│ └── container.xml
|
42
|
+
└── mimetype
|
43
|
+
|
44
|
+
To load EPUB books from directory, you need specify file adapter via {EPUB::OCF::PhysicalContainer} at first:
|
45
|
+
|
46
|
+
require 'epub/parser'
|
47
|
+
|
48
|
+
EPUB::OCF::PhysicalContainer.adapter = :File
|
49
|
+
|
50
|
+
And then, directory path as EPUB path:
|
51
|
+
|
52
|
+
epub = EPUB::Parser.parse('./page-blanche')
|
53
|
+
|
54
|
+
Now you can handle the EPUB book as always.
|
55
|
+
|
56
|
+
epub.title # => "Page Blache"
|
57
|
+
epub.each_page_on_spine.to_a.length # => 10
|
58
|
+
puts epub.nav.content_document.contents.map {|content| "#{File.basename(content.href.to_s)} ... #{content.text}"}
|
59
|
+
# PageBlanche_Page_002.xhtml ... Dédicace
|
60
|
+
# PageBlanche_Page_005.xhtml ... Commencer la lecture
|
61
|
+
# => nil
|
62
|
+
|
63
|
+
If set {EPUB::OCF::PhysicalContainer.adapter}, it is used every time EPUB Parser parses books even when it's packaged EPUB file. Instead of setting adapter globally, you can also specify adapter for parsing individually by passing keyword argument `container_adapter` to `.parse` method:
|
64
|
+
|
65
|
+
# From packaged file
|
66
|
+
File.ftype './page-blanche.epub' # => "file"
|
67
|
+
archived_book = EPUB::Parser.parse('./page-blanche.epub') # => EPUB::Book
|
68
|
+
# From directory
|
69
|
+
File.ftype './page-blanche' # => "directory"
|
70
|
+
unpacked_book = EPUB::Parser.parse('./page-blanche', container_adapter: :File) # => EPUB::Book
|
71
|
+
|
72
|
+
Command-line tools
|
73
|
+
------------------
|
74
|
+
|
75
|
+
Command-line tools `epubinfo` and `epub-open` may also handle with directory as EPUB books.
|
76
|
+
|
77
|
+
Executing `epubinfo`:
|
78
|
+
|
79
|
+
$ epubinfo page-blanche
|
80
|
+
Title: Page Blanche
|
81
|
+
Identifiers: code.google.com.epub-samples.page-blanche
|
82
|
+
Titles: Page Blanche
|
83
|
+
Languages: fr
|
84
|
+
Contributors: Vincent Gros
|
85
|
+
Coverages:
|
86
|
+
Creators: Boulet, Bagieu Pénélope
|
87
|
+
Dates: 2012-01-18
|
88
|
+
Descriptions:
|
89
|
+
Formats:
|
90
|
+
Publishers: éditions Delcourt
|
91
|
+
Relations:
|
92
|
+
Rights: This work is shared with the public using the Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license.
|
93
|
+
Sources:
|
94
|
+
Subjects:
|
95
|
+
Types:
|
96
|
+
Unique identifier: code.google.com.epub-samples.page-blanche
|
97
|
+
Epub version: 3.0
|
98
|
+
|
99
|
+
Executing `epub-open`:
|
100
|
+
|
101
|
+
$ epub-open page-blanche
|
102
|
+
Enter "exit" to exit IRB
|
103
|
+
irb: warn: can't alias bindings from irb_workspaces.
|
104
|
+
irb(main):001:0> title
|
105
|
+
=> "Page Blanche"
|
106
|
+
irb(main):002:0> exit
|
107
|
+
|
108
|
+
Note
|
109
|
+
----
|
110
|
+
|
111
|
+
Actually loading EPUB books from unpacked directory is not recommended. The reason why is it's too complex to handle with files properly because of character encoding of file names such as Unicode normalization matters like UTF-8 NFD, NFC, NFKD, NFKC and OS X-specific custom NFD, IRI normalization like percent-encoding, case sensitivity or so on. And, you know, this is not standardized way to load EPUB books. So, at least in the near future, there's not plan to support various environment.
|
112
|
+
|
113
|
+
Of course, always pathces are welcome.
|
data/epub-parser.gemspec
CHANGED
@@ -32,7 +32,6 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.add_development_dependency 'test-unit-rr'
|
33
33
|
s.add_development_dependency 'test-unit-notify'
|
34
34
|
s.add_development_dependency 'simplecov'
|
35
|
-
s.add_development_dependency 'thin'
|
36
35
|
s.add_development_dependency 'yard'
|
37
36
|
s.add_development_dependency 'gem-man'
|
38
37
|
s.add_development_dependency 'ronn'
|
data/lib/epub/book/features.rb
CHANGED
@@ -29,6 +29,14 @@ module EPUB
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
def container_adapter
|
33
|
+
@adapter || OCF::PhysicalContainer.adapter
|
34
|
+
end
|
35
|
+
|
36
|
+
def container_adapter=(adapter)
|
37
|
+
@adapter = adapter.instance_of?(Class) ? adapter : OCF::PhysicalContainer.const_get(adapter)
|
38
|
+
end
|
39
|
+
|
32
40
|
# @overload each_page_on_spine(&blk)
|
33
41
|
# iterate over items in order of spine when block given
|
34
42
|
# @yieldparam item [Publication::Package::Manifest::Item]
|
@@ -28,6 +28,7 @@ module EPUB
|
|
28
28
|
# Enumerator version of page_list
|
29
29
|
# Usage: navigation.enum_for(:pages)
|
30
30
|
def pages
|
31
|
+
raise NotImplementedError
|
31
32
|
end
|
32
33
|
|
33
34
|
# @todo Enumerator version of landmarks
|
@@ -41,10 +42,12 @@ module EPUB
|
|
41
42
|
|
42
43
|
# iterator for #page_list
|
43
44
|
def each_page
|
45
|
+
raise NotImplementedError
|
44
46
|
end
|
45
47
|
|
46
48
|
# iterator for #landmark
|
47
49
|
def each_landmark
|
50
|
+
raise NotImplementedError
|
48
51
|
end
|
49
52
|
|
50
53
|
def navigation
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'epub/ocf/physical_container/zipruby'
|
2
|
+
require 'epub/ocf/physical_container/file'
|
3
|
+
|
4
|
+
module EPUB
|
5
|
+
class OCF
|
6
|
+
class PhysicalContainer
|
7
|
+
@adapter = Zipruby
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def adapter
|
11
|
+
if self == PhysicalContainer
|
12
|
+
@adapter
|
13
|
+
else
|
14
|
+
raise NoMethodError.new("undefined method `#{__method__}' for #{self}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def adapter=(adapter)
|
19
|
+
if self == PhysicalContainer
|
20
|
+
@adapter = adapter.instance_of?(Class) ? adapter : const_get(adapter)
|
21
|
+
else
|
22
|
+
raise NoMethodError.new("undefined method `#{__method__}' for #{self}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def open(container_path)
|
27
|
+
_adapter.new(container_path).open do |container|
|
28
|
+
yield container
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def read(container_path, path_name)
|
33
|
+
open(container_path) {|container|
|
34
|
+
container.read(path_name)
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def _adapter
|
41
|
+
(self == PhysicalContainer) ? @adapter : self
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize(container_path)
|
46
|
+
@container_path = container_path
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'zipruby'
|
2
|
+
|
3
|
+
module EPUB
|
4
|
+
class OCF
|
5
|
+
class PhysicalContainer
|
6
|
+
class Zipruby < self
|
7
|
+
def open
|
8
|
+
Zip::Archive.open @container_path do |archive|
|
9
|
+
@archive = archive
|
10
|
+
result = yield self
|
11
|
+
@archive = nil
|
12
|
+
result
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def read(path_name)
|
17
|
+
if @archive
|
18
|
+
@archive.fopen(path_name) {|entry| entry.read}
|
19
|
+
else
|
20
|
+
Zip::Archive.open(@container_path) {|archive|
|
21
|
+
archive.fopen(path_name) {|entry| entry.read}
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/epub/parser.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'epub'
|
2
2
|
require 'epub/constants'
|
3
|
-
require '
|
3
|
+
require 'epub/book'
|
4
4
|
require 'nokogiri'
|
5
5
|
|
6
6
|
module EPUB
|
@@ -29,27 +29,34 @@ module EPUB
|
|
29
29
|
# For details of options, see below.
|
30
30
|
# @option options [EPUB] :book instance of class which includes {EPUB} module
|
31
31
|
# @option options [Class] :class class which includes {EPUB} module
|
32
|
+
# @option options [EPUB::OCF::PhysicalContainer, Symbol] :container_adapter OCF physical container adapter to use when parsing EPUB container
|
33
|
+
# When class passed, it is used. When symbol passed, it is considered as subclass name of {EPUB::OCF::PhysicalContainer}.
|
34
|
+
# If omitted, {EPUB::OCF::PhysicalContainer.adapter} is used.
|
32
35
|
# @return [EPUB] object which is an instance of class including {EPUB} module.
|
33
36
|
# When option :book passed, returns the same object whose attributes about EPUB are set.
|
34
37
|
# When option :class passed, returns the instance of the class.
|
35
38
|
# Otherwise returns {EPUB::Book} object.
|
36
|
-
def parse(filepath, options
|
39
|
+
def parse(filepath, **options)
|
37
40
|
new(filepath, options).parse
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
41
|
-
def initialize(filepath, options
|
44
|
+
def initialize(filepath, **options)
|
42
45
|
raise "File #{filepath} not readable" unless File.readable_real? filepath
|
43
46
|
|
44
47
|
@filepath = File.realpath filepath
|
45
48
|
@book = create_book options
|
46
49
|
@book.epub_file = @filepath
|
50
|
+
if options[:container_adapter]
|
51
|
+
adapter = options[:container_adapter]
|
52
|
+
@book.container_adapter = adapter
|
53
|
+
end
|
47
54
|
end
|
48
55
|
|
49
56
|
def parse
|
50
|
-
|
51
|
-
@book.ocf = OCF.parse(
|
52
|
-
@book.package = Publication.parse(
|
57
|
+
@book.container_adapter.open @filepath do |container|
|
58
|
+
@book.ocf = OCF.parse(container)
|
59
|
+
@book.package = Publication.parse(container, @book.rootfile_path)
|
53
60
|
end
|
54
61
|
|
55
62
|
@book
|
@@ -64,7 +71,6 @@ module EPUB
|
|
64
71
|
when params[:class]
|
65
72
|
params[:class].new
|
66
73
|
else
|
67
|
-
require 'epub/book'
|
68
74
|
Book.new
|
69
75
|
end
|
70
76
|
end
|
data/lib/epub/parser/ocf.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'epub/constants'
|
2
2
|
require 'epub/ocf'
|
3
|
+
require 'epub/ocf/physical_container'
|
3
4
|
require 'zipruby'
|
4
5
|
require 'nokogiri'
|
5
6
|
|
@@ -9,25 +10,24 @@ module EPUB
|
|
9
10
|
include Utils
|
10
11
|
|
11
12
|
DIRECTORY = 'META-INF'
|
12
|
-
EPUB::OCF::MODULES.each {|m| self.const_set "#{m.upcase}_FILE", "#{m}.xml"} # Deprecated
|
13
13
|
|
14
14
|
class << self
|
15
|
-
def parse(
|
16
|
-
new(
|
15
|
+
def parse(container)
|
16
|
+
new(container).parse
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def initialize(
|
21
|
-
@
|
20
|
+
def initialize(container)
|
21
|
+
@container = container
|
22
22
|
@ocf = EPUB::OCF.new
|
23
23
|
end
|
24
24
|
|
25
25
|
def parse
|
26
26
|
EPUB::OCF::MODULES.each do |m|
|
27
27
|
begin
|
28
|
-
data = @
|
28
|
+
data = @container.read(File.join(DIRECTORY, "#{m}.xml"))
|
29
29
|
@ocf.__send__ "#{m}=", __send__("parse_#{m}", data)
|
30
|
-
rescue Zip::Error
|
30
|
+
rescue ::Zip::Error, ::Errno::ENOENT
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -11,8 +11,8 @@ module EPUB
|
|
11
11
|
include Utils
|
12
12
|
|
13
13
|
class << self
|
14
|
-
def parse(
|
15
|
-
opf =
|
14
|
+
def parse(container, file)
|
15
|
+
opf = container.read(Addressable::URI.unencode(file))
|
16
16
|
|
17
17
|
new(opf, file).parse
|
18
18
|
end
|
data/lib/epub/parser/version.rb
CHANGED
@@ -105,9 +105,7 @@ module EPUB
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def read
|
108
|
-
raw_content =
|
109
|
-
zip.fopen(entry_name) {|member| member.read}
|
110
|
-
}
|
108
|
+
raw_content = manifest.package.book.container_adapter.read(manifest.package.book.epub_file, entry_name)
|
111
109
|
|
112
110
|
unless media_type.start_with?('text/') or
|
113
111
|
media_type.end_with?('xml') or
|
data/lib/epub/searcher/xhtml.rb
CHANGED
@@ -0,0 +1,73 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative 'helper'
|
3
|
+
require 'epub/ocf/physical_container'
|
4
|
+
|
5
|
+
class TestOCFPhysicalContainer < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@container_path = 'test/fixtures/book.epub'
|
8
|
+
@path = 'OPS/nav.xhtml'
|
9
|
+
@content = File.read(File.join('test/fixtures/book', @path))
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_read
|
13
|
+
assert_equal @content, EPUB::OCF::PhysicalContainer.read(@container_path, @path).force_encoding('UTF-8')
|
14
|
+
end
|
15
|
+
|
16
|
+
module ConcreteContainer
|
17
|
+
def test_class_method_open
|
18
|
+
@class.open @container_path do |container|
|
19
|
+
assert_instance_of @class, container
|
20
|
+
assert_equal @content, container.read(@path).force_encoding('UTF-8')
|
21
|
+
assert_equal File.read('test/fixtures/book/OPS/日本語.xhtml'), container.read('OPS/日本語.xhtml').force_encoding('UTF-8')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_class_method_read
|
26
|
+
assert_equal @content, @class.read(@container_path, @path).force_encoding('UTF-8')
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_open_yields_over_container_with_opened_archive
|
30
|
+
@container.open do |container|
|
31
|
+
assert_instance_of @class, container
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_container_in_open_block_can_readable
|
36
|
+
@container.open do |container|
|
37
|
+
assert_equal @content, container.read(@path).force_encoding('UTF-8')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_read
|
42
|
+
assert_equal @content, @container.read(@path).force_encoding('UTF-8')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class TestZipruby < self
|
47
|
+
include ConcreteContainer
|
48
|
+
|
49
|
+
def setup
|
50
|
+
super
|
51
|
+
@class = EPUB::OCF::PhysicalContainer::Zipruby
|
52
|
+
@container = @class.new(@container_path)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class TestFile < self
|
57
|
+
include ConcreteContainer
|
58
|
+
|
59
|
+
def setup
|
60
|
+
super
|
61
|
+
@container_path = @container_path[0..-'.epub'.length-1]
|
62
|
+
@class = EPUB::OCF::PhysicalContainer::File
|
63
|
+
@container = @class.new(@container_path)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_adapter_can_changable
|
67
|
+
adapter = EPUB::OCF::PhysicalContainer.adapter
|
68
|
+
EPUB::OCF::PhysicalContainer.adapter = @class
|
69
|
+
assert_equal @content, EPUB::OCF::PhysicalContainer.read(@container_path, @path).force_encoding('UTF-8')
|
70
|
+
EPUB::OCF::PhysicalContainer.adapter = adapter
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/test/test_parser.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require File.expand_path 'helper', File.dirname(__FILE__)
|
2
3
|
|
3
4
|
class MyBook
|
@@ -25,6 +26,27 @@ class TestParser < Test::Unit::TestCase
|
|
25
26
|
assert_kind_of EPUB::Book::Features, EPUB::Parser.parse('test/fixtures/book.epub', class: MyBook)
|
26
27
|
end
|
27
28
|
|
29
|
+
def test_parse_from_file_system
|
30
|
+
adapter = EPUB::OCF::PhysicalContainer.adapter
|
31
|
+
begin
|
32
|
+
EPUB::OCF::PhysicalContainer.adapter = :File
|
33
|
+
epub = EPUB::Parser.parse('test/fixtures/book')
|
34
|
+
assert_instance_of EPUB::Book, epub
|
35
|
+
assert_equal 'Mon premier guide de cuisson, un Mémoire', epub.main_title
|
36
|
+
ensure
|
37
|
+
EPUB::OCF::PhysicalContainer.adapter = adapter
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_can_specify_container_adapter_when_parsing_individually
|
42
|
+
epub = EPUB::Parser.parse('test/fixtures/book', container_adapter: :File)
|
43
|
+
|
44
|
+
assert_equal 'Mon premier guide de cuisson, un Mémoire', epub.main_title
|
45
|
+
assert_equal File.read('test/fixtures/book/OPS/nav.xhtml'), epub.nav.read
|
46
|
+
assert_equal EPUB::OCF::PhysicalContainer::File, epub.container_adapter
|
47
|
+
assert_equal EPUB::OCF::PhysicalContainer::Zipruby, EPUB::OCF::PhysicalContainer.adapter
|
48
|
+
end
|
49
|
+
|
28
50
|
class TestBook < TestParser
|
29
51
|
def setup
|
30
52
|
super
|
data/test/test_parser_ocf.rb
CHANGED
@@ -4,13 +4,12 @@ require File.expand_path 'helper', File.dirname(__FILE__)
|
|
4
4
|
class TestParserOCF < Test::Unit::TestCase
|
5
5
|
def setup
|
6
6
|
file = 'test/fixtures/book.epub'
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@zip.close
|
7
|
+
EPUB::OCF::PhysicalContainer.open(file) {|container|
|
8
|
+
@parser = EPUB::Parser::OCF.new(container)
|
9
|
+
}
|
10
|
+
@container_xml = Zip::Archive.open(file) {|archive|
|
11
|
+
archive.fopen('META-INF/container.xml').read
|
12
|
+
}
|
14
13
|
end
|
15
14
|
|
16
15
|
def test_parsed_container_has_one_rootfile
|
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.2.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: 2015-06-
|
11
|
+
date: 2015-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -108,20 +108,6 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: thin
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: yard
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -291,6 +277,7 @@ files:
|
|
291
277
|
- docs/Navigation.markdown
|
292
278
|
- docs/Publication.markdown
|
293
279
|
- docs/Searcher.markdown
|
280
|
+
- docs/UnpackedArchive.markdown
|
294
281
|
- epub-parser.gemspec
|
295
282
|
- features/epubinfo.feature
|
296
283
|
- features/step_definitions/epubinfo_steps.rb
|
@@ -308,6 +295,9 @@ files:
|
|
308
295
|
- lib/epub/ocf/encryption.rb
|
309
296
|
- lib/epub/ocf/manifest.rb
|
310
297
|
- lib/epub/ocf/metadata.rb
|
298
|
+
- lib/epub/ocf/physical_container.rb
|
299
|
+
- lib/epub/ocf/physical_container/file.rb
|
300
|
+
- lib/epub/ocf/physical_container/zipruby.rb
|
311
301
|
- lib/epub/ocf/rights.rb
|
312
302
|
- lib/epub/ocf/signatures.rb
|
313
303
|
- lib/epub/parser.rb
|
@@ -350,6 +340,7 @@ files:
|
|
350
340
|
- test/test_epub.rb
|
351
341
|
- test/test_fixed_layout.rb
|
352
342
|
- test/test_inspect.rb
|
343
|
+
- test/test_ocf_physical_container.rb
|
353
344
|
- test/test_parser.rb
|
354
345
|
- test/test_parser_content_document.rb
|
355
346
|
- test/test_parser_fixed_layout.rb
|
@@ -390,6 +381,7 @@ test_files:
|
|
390
381
|
- test/test_epub.rb
|
391
382
|
- test/test_fixed_layout.rb
|
392
383
|
- test/test_inspect.rb
|
384
|
+
- test/test_ocf_physical_container.rb
|
393
385
|
- test/test_parser.rb
|
394
386
|
- test/test_parser_content_document.rb
|
395
387
|
- test/test_parser_fixed_layout.rb
|