epub-parser 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/CHANGELOG.markdown +7 -0
- data/README.markdown +11 -6
- data/Rakefile +0 -35
- data/bin/epubinfo +12 -7
- data/docs/EpubOpen.markdown +1 -1
- data/docs/Epubinfo.markdown +94 -3
- data/docs/Home.markdown +2 -2
- data/docs/yard-forwardable_def_delegators_handler.rb +34 -0
- data/lib/epub/parser/content_document.rb +1 -7
- data/lib/epub/parser/version.rb +1 -1
- data/lib/epub/publication/package/manifest.rb +1 -0
- data/test/helper.rb +4 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f7e1c88df88ae747c9119ab1a7a5978da200d977ffa0a97b33f2c5c2d398cb8
|
4
|
+
data.tar.gz: b554ff75c8641a4f8edc3cf0a4801671440b605aa493a50d95498d278c9e49b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a102404b9a0a7257e7899f43c08002e4ce55b29ed56df6bead42d2eef0d316b9b63ee4494627777fba1aa3849389fd2754caccc5409a9d7c7a5761243ca3367
|
7
|
+
data.tar.gz: f12125b9970efaa46bd24d71f6e32b6fe9d95d7ceb07c20f0b65124be6c3832044941c28fd46ed79722408ab0a449e6431442cfd519981a786606550fd34bfde
|
data/.yardopts
CHANGED
data/CHANGELOG.markdown
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
+
0.3.6
|
5
|
+
-----
|
6
|
+
* [BUG FIX]Ignore fragment when find item by relative IRI
|
7
|
+
* Enable [PrettyBacktrace][] only when specified by env var for testing performance
|
8
|
+
|
9
|
+
[PrettyBacktrace]: https://github.com/ko1/pretty_backtrace
|
10
|
+
|
4
11
|
0.3.5
|
5
12
|
-----
|
6
13
|
* [BUG FIX]Fix a bug that {EPUB::ContentDocument::Navigation::Item#item} is `nil` when `href` includes double dots(`..`)(Thanks [aelkiss][]!)
|
data/README.markdown
CHANGED
@@ -64,7 +64,7 @@ See document's {file:docs/Home.markdown} or [API Documentation][rubydoc] for mor
|
|
64
64
|
Unique identifier: 978-1-934356-91-3
|
65
65
|
Epub version: 2.0
|
66
66
|
|
67
|
-
See {file:docs/Epubinfo} for more info.
|
67
|
+
See {file:docs/Epubinfo.markdown} for more info.
|
68
68
|
|
69
69
|
### `epub-open` command-line tool
|
70
70
|
|
@@ -96,7 +96,7 @@ IRB starts. `self` becomes the EPUB book and can access to methods of `EPUB`.
|
|
96
96
|
=> nil
|
97
97
|
exit # Enter "exit" when exit the session
|
98
98
|
|
99
|
-
See {file:docs/EpubOpen} for more info.
|
99
|
+
See {file:docs/EpubOpen.markdown} for more info.
|
100
100
|
|
101
101
|
DOCUMENTATION
|
102
102
|
-------------
|
@@ -159,6 +159,14 @@ If you find other gems, please tell me or request a pull request.
|
|
159
159
|
RECENT CHANGES
|
160
160
|
--------------
|
161
161
|
|
162
|
+
### 0.3.6
|
163
|
+
|
164
|
+
* [BUG FIX]Ignore fragment when find item by relative IRI
|
165
|
+
* Disable [PrettyBacktrace][] by default
|
166
|
+
|
167
|
+
[PrettyBacktrace]: https://github.com/ko1/pretty_backtrace
|
168
|
+
|
169
|
+
|
162
170
|
### 0.3.5
|
163
171
|
|
164
172
|
* [BUG FIX]Fix a bug that {EPUB::ContentDocument::Navigation::Item#item} is `nil` when `href` includes double dots(`..`)(Thanks [aelkiss][]!)
|
@@ -176,14 +184,11 @@ RECENT CHANGES
|
|
176
184
|
* [BREAKING CHANGE]Remove deprecated second argument from `EPUB::Parser::Publication#initialize`
|
177
185
|
* Add `detect_encoding` keyword argument to `Publication::Package::Manifest::Item#read` and `ContentDocument::XHTML#read`
|
178
186
|
|
179
|
-
### 0.3.2
|
180
|
-
|
181
|
-
* Use epub-cfi gem for EPUB CFI
|
182
|
-
|
183
187
|
See {file:CHANGELOG.markdown} for older changelogs and details.
|
184
188
|
|
185
189
|
TODOS
|
186
190
|
-----
|
191
|
+
* Consider to implement IRI feature instead of to use Addressable
|
187
192
|
* EPUB 3.0.1
|
188
193
|
* EPUB 3.1
|
189
194
|
* Help features for `epub-open` tool
|
data/Rakefile
CHANGED
@@ -51,38 +51,3 @@ Gem::Tasks.new do |tasks|
|
|
51
51
|
tasks.console.command = 'pry'
|
52
52
|
end
|
53
53
|
task :build => :clean
|
54
|
-
|
55
|
-
class ForwardableDefDelegatorsHandler < YARD::Handlers::Ruby::Base
|
56
|
-
handles method_call(:def_delegators)
|
57
|
-
namespace_only
|
58
|
-
|
59
|
-
def process
|
60
|
-
params = validated_attribute_names(statement.parameters(false))
|
61
|
-
accessor = params.shift
|
62
|
-
params.each do |param|
|
63
|
-
object = YARD::CodeObjects::MethodObject.new(namespace, param)
|
64
|
-
object.docstring = "Forwarded to +#{accessor}+"
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
protected
|
69
|
-
|
70
|
-
# Strips out any non-essential arguments from the attr statement.
|
71
|
-
#
|
72
|
-
# @param [Array<Parser::Ruby::AstNode>] params a list of the parameters
|
73
|
-
# in the attr call.
|
74
|
-
# @return [Array<String>] the validated attribute names
|
75
|
-
# @raise [Parser::UndocumentableError] if the arguments are not valid.
|
76
|
-
def validated_attribute_names(params)
|
77
|
-
params.map do |obj|
|
78
|
-
case obj.type
|
79
|
-
when :symbol_literal
|
80
|
-
obj.jump(:ident, :op, :kw, :const).source
|
81
|
-
when :string_literal
|
82
|
-
obj.jump(:string_content).source
|
83
|
-
else
|
84
|
-
raise YARD::Parser::UndocumentableError, obj.source
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
data/bin/epubinfo
CHANGED
@@ -39,11 +39,16 @@ unless File.readable? file
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
book = EPUB::Parser.parse(file)
|
42
|
-
data = {'
|
42
|
+
data = {'title' => book.title}
|
43
43
|
data.merge!(book.metadata.to_h)
|
44
|
-
data['modified'] =
|
45
|
-
data['
|
46
|
-
data['
|
44
|
+
data['modified'] = book.modified
|
45
|
+
data['unique identifier'] = book.metadata.unique_identifier
|
46
|
+
data['epub version'] = book.package.version
|
47
|
+
|
48
|
+
data.each_pair do |(key, value)|
|
49
|
+
data[key] = value.respond_to?(:join) ? value.join(", ") : value.to_s
|
50
|
+
end
|
51
|
+
|
47
52
|
counts = {:chars => 0, :words => 0}
|
48
53
|
if options[:words] or options[:chars]
|
49
54
|
book.resources.select(&:xhtml?).each do |xhtml|
|
@@ -60,12 +65,12 @@ if options[:words] or options[:chars]
|
|
60
65
|
end
|
61
66
|
end
|
62
67
|
end
|
63
|
-
data['
|
64
|
-
data['
|
68
|
+
data['words'] = counts[:words] if options[:words]
|
69
|
+
data['characters'] = counts[:chars] if options[:chars]
|
65
70
|
if options[:format] == :line
|
66
71
|
key_width = data.keys.map {|k| k.length}.max + 3
|
67
72
|
data.each_pair do |k, v|
|
68
|
-
puts (k.to_s.capitalize + ':').ljust(key_width) + v.
|
73
|
+
puts (k.to_s.capitalize + ':').ljust(key_width) + v.to_s
|
69
74
|
end
|
70
75
|
else
|
71
76
|
require options[:format].to_s
|
data/docs/EpubOpen.markdown
CHANGED
data/docs/Epubinfo.markdown
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
{file:docs/Home} > **{file:docs/Epubinfo}**
|
1
|
+
{file:docs/Home} > **{file:docs/Epubinfo.markdown}**
|
2
2
|
|
3
3
|
`epubinfo` command-line tool
|
4
4
|
============================
|
@@ -12,7 +12,7 @@ Usage
|
|
12
12
|
|
13
13
|
Example:
|
14
14
|
|
15
|
-
$ epubinfo ~/Documebts/Books/build_awesome_command_line_applications_in_ruby_fo.epub
|
15
|
+
$ epubinfo ~/Documebts/Books/build_awesome_command_line_applications_in_ruby_fo.epub
|
16
16
|
Title: Build Awesome Command-Line Applications in Ruby (for KITAITI MAKOTO)
|
17
17
|
Identifiers: 978-1-934356-91-3
|
18
18
|
Titles: Build Awesome Command-Line Applications in Ruby (for KITAITI MAKOTO)
|
@@ -34,4 +34,95 @@ Example:
|
|
34
34
|
|
35
35
|
To see help:
|
36
36
|
|
37
|
-
epubinfo -h
|
37
|
+
$ epubinfo -h
|
38
|
+
Show metadata of an EPUB file
|
39
|
+
|
40
|
+
Usage: epubinfo [options] EPUBFILE
|
41
|
+
|
42
|
+
-f, --format=FORMAT format of output(line, json or yaml), defaults to line(for console)
|
43
|
+
--words count words of content documents
|
44
|
+
--chars count charactors of content documents
|
45
|
+
|
46
|
+
Output formats
|
47
|
+
--------------
|
48
|
+
|
49
|
+
`epubinfo` can output in three formats: line, JSON and YAML. You can specify format by `--format`(`-f`) command-line option
|
50
|
+
|
51
|
+
### JSON ###
|
52
|
+
|
53
|
+
$ epubinfo --format=json ~/Documebts/Books/build_awesome_command_line_applications_in_ruby_fo.epub | jq .
|
54
|
+
{
|
55
|
+
"title": "Build Awesome Command-Line Applications in Ruby (for KITAITI MAKOTO)",
|
56
|
+
"identifiers": "978-1-934356-91-3",
|
57
|
+
"titles": "Build Awesome Command-Line Applications in Ruby (for KITAITI MAKOTO)",
|
58
|
+
"languages": "en",
|
59
|
+
"contributors": "",
|
60
|
+
"coverages": "",
|
61
|
+
"creators": "David Bryant Copeland",
|
62
|
+
"dates": "",
|
63
|
+
"descriptions": "",
|
64
|
+
"formats": "",
|
65
|
+
"publishers": "The Pragmatic Bookshelf, LLC (338304)",
|
66
|
+
"relations": "",
|
67
|
+
"rights": "Copyright © 2012 Pragmatic Programmers, LLC",
|
68
|
+
"sources": "",
|
69
|
+
"subjects": "Pragmatic Bookshelf",
|
70
|
+
"types": "",
|
71
|
+
"modified": "",
|
72
|
+
"unique identifier": "978-1-934356-91-3",
|
73
|
+
"epub version": "2.0"
|
74
|
+
}
|
75
|
+
|
76
|
+
### YAML ###
|
77
|
+
|
78
|
+
$ epubinfo --format=yaml ~/Documebts/Books/build_awesome_command_line_applications_in_ruby_fo.epub
|
79
|
+
---
|
80
|
+
title: Build Awesome Command-Line Applications in Ruby (for KITAITI MAKOTO)
|
81
|
+
:identifiers: 978-1-934356-91-3
|
82
|
+
:titles: Build Awesome Command-Line Applications in Ruby (for KITAITI MAKOTO)
|
83
|
+
:languages: en
|
84
|
+
:contributors: ''
|
85
|
+
:coverages: ''
|
86
|
+
:creators: David Bryant Copeland
|
87
|
+
:dates: ''
|
88
|
+
:descriptions: ''
|
89
|
+
:formats: ''
|
90
|
+
:publishers: The Pragmatic Bookshelf, LLC (338304)
|
91
|
+
:relations: ''
|
92
|
+
:rights: Copyright © 2012 Pragmatic Programmers, LLC
|
93
|
+
:sources: ''
|
94
|
+
:subjects: Pragmatic Bookshelf
|
95
|
+
:types: ''
|
96
|
+
modified: ''
|
97
|
+
unique identifier: 978-1-934356-91-3
|
98
|
+
epub Version: '2.0'
|
99
|
+
|
100
|
+
Character and word count
|
101
|
+
------------------------
|
102
|
+
|
103
|
+
`epubinfo` can count characters and words(space perarated) in EPUB document. Pass `--chars` and `--words` options to the command.
|
104
|
+
|
105
|
+
Note that this makes process slower because it will read all the document.
|
106
|
+
|
107
|
+
$ epubinfo --chars --words ~/Documebts/Books/build_awesome_command_line_applications_in_ruby_fo.epub
|
108
|
+
Title: Build Awesome Command-Line Applications in Ruby (for IKEDA TATSUNOBU)
|
109
|
+
Identifiers: 978-1-934356-91-3
|
110
|
+
Titles: Build Awesome Command-Line Applications in Ruby (for IKEDA TATSUNOBU)
|
111
|
+
Languages: en
|
112
|
+
Contributors:
|
113
|
+
Coverages:
|
114
|
+
Creators: David Bryant Copeland
|
115
|
+
Dates:
|
116
|
+
Descriptions:
|
117
|
+
Formats:
|
118
|
+
Publishers: The Pragmatic Bookshelf, LLC (338304)
|
119
|
+
Relations:
|
120
|
+
Rights: Copyright © 2012 Pragmatic Programmers, LLC
|
121
|
+
Sources:
|
122
|
+
Subjects: Pragmatic Bookshelf
|
123
|
+
Types:
|
124
|
+
Modified:
|
125
|
+
Unique identifier: 978-1-934356-91-3
|
126
|
+
Epub version: 2.0
|
127
|
+
Words: 65006
|
128
|
+
Characters: 445924
|
data/docs/Home.markdown
CHANGED
@@ -17,13 +17,13 @@ Usage
|
|
17
17
|
|
18
18
|
`epubinfo` tool extracts and shows the metadata of specified EPUB book.
|
19
19
|
|
20
|
-
See {file:docs/Epubinfo}.
|
20
|
+
See {file:docs/Epubinfo.markdown}.
|
21
21
|
|
22
22
|
#### epub-open
|
23
23
|
|
24
24
|
`epub-open` tool provides interactive shell(IRB) which helps you research about EPUB book.
|
25
25
|
|
26
|
-
See {file:docs/EpubOpen}.
|
26
|
+
See {file:docs/EpubOpen.markdown}.
|
27
27
|
|
28
28
|
### As a library
|
29
29
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class ForwardableDefDelegatorsHandler < YARD::Handlers::Ruby::Base
|
2
|
+
handles method_call(:def_delegators)
|
3
|
+
namespace_only
|
4
|
+
|
5
|
+
def process
|
6
|
+
params = validated_attribute_names(statement.parameters(false))
|
7
|
+
accessor = params.shift
|
8
|
+
params.each do |param|
|
9
|
+
object = YARD::CodeObjects::MethodObject.new(namespace, param)
|
10
|
+
object.docstring = "Forwarded to +#{accessor}+"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
# Strips out any non-essential arguments from the attr statement.
|
17
|
+
#
|
18
|
+
# @param [Array<Parser::Ruby::AstNode>] params a list of the parameters
|
19
|
+
# in the attr call.
|
20
|
+
# @return [Array<String>] the validated attribute names
|
21
|
+
# @raise [Parser::UndocumentableError] if the arguments are not valid.
|
22
|
+
def validated_attribute_names(params)
|
23
|
+
params.map do |obj|
|
24
|
+
case obj.type
|
25
|
+
when :symbol_literal
|
26
|
+
obj.jump(:ident, :op, :kw, :const).source
|
27
|
+
when :string_literal
|
28
|
+
obj.jump(:string_content).source
|
29
|
+
else
|
30
|
+
raise YARD::Parser::UndocumentableError, obj.source
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -82,13 +82,7 @@ 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
|
-
|
86
|
-
full_path = EPUB::Publication::Package::Manifest::Item::DUMMY_ROOT_IRI + @item.manifest.package.full_path + @item.href + item.href
|
87
|
-
full_path.scheme = nil
|
88
|
-
full_path.host = nil
|
89
|
-
full_path.path = full_path.path[1..-1]
|
90
|
-
full_path.fragment = nil
|
91
|
-
item.item = @item.manifest.items.find {|it| it.full_path == full_path}
|
85
|
+
item.item = @item.find_item_by_relative_iri(item.href)
|
92
86
|
end
|
93
87
|
item.items = element.xpath('./xhtml:ol[1]/xhtml:li', EPUB::NAMESPACES).map {|li| parse_navigation_item(li)}
|
94
88
|
|
data/lib/epub/parser/version.rb
CHANGED
@@ -227,6 +227,7 @@ module EPUB
|
|
227
227
|
segment == '..' ? clean_segments.pop : clean_segments << segment
|
228
228
|
end
|
229
229
|
target_iri = Addressable::URI.parse(clean_segments.join(Addressable::URI::SLASH))
|
230
|
+
target_iri.fragment = nil
|
230
231
|
manifest.items.find { |item| item.href == target_iri}
|
231
232
|
end
|
232
233
|
|
data/test/helper.rb
CHANGED
@@ -9,7 +9,9 @@ require 'test/unit'
|
|
9
9
|
require 'test/unit/rr'
|
10
10
|
require 'test/unit/notify'
|
11
11
|
require 'pry'
|
12
|
-
|
13
|
-
|
12
|
+
if ENV["PRETTY_BACKTRACE"]
|
13
|
+
require 'pretty_backtrace'
|
14
|
+
PrettyBacktrace.enable
|
15
|
+
end
|
14
16
|
|
15
17
|
require 'epub/parser'
|
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.6
|
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-
|
11
|
+
date: 2018-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -313,6 +313,7 @@ files:
|
|
313
313
|
- docs/Publication.markdown
|
314
314
|
- docs/Searcher.markdown
|
315
315
|
- docs/UnpackedArchive.markdown
|
316
|
+
- docs/yard-forwardable_def_delegators_handler.rb
|
316
317
|
- epub-parser.gemspec
|
317
318
|
- examples/aggregate-contents-from-web.rb
|
318
319
|
- examples/exctract-content-using-cfi.rb
|