gepub 1.0.0 → 1.0.1
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/.travis.yml +2 -2
- data/README.md +1 -1
- data/gepub.gemspec +1 -1
- data/lib/gepub/book.rb +6 -11
- data/lib/gepub/builder.rb +3 -1
- data/lib/gepub/datemeta.rb +1 -1
- data/lib/gepub/item.rb +2 -2
- data/lib/gepub/manifest.rb +1 -1
- data/lib/gepub/meta.rb +2 -2
- data/lib/gepub/metadata.rb +1 -1
- data/lib/gepub/mime.rb +1 -1
- data/lib/gepub/package.rb +1 -1
- data/lib/gepub/resource_builder.rb +4 -4
- data/lib/gepub/sorted_array.rb +1 -1
- data/lib/gepub/spine.rb +2 -2
- data/lib/gepub/version.rb +2 -2
- data/spec/package_spec.rb +4 -4
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88666fd75b90a68e50f920648d1a459b2beb59bc47aa9a1ca3ef9fb39dc7b746
|
4
|
+
data.tar.gz: c455873460659bc89b70f725129bf462ae5478beb68fb8be99de2ba04c49e4dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d121c4ea9dbabaa8e61ddebf98c79a63d6358e25c49c46d3692a36a1f97c2e0adeba226ae1e7455dddc1aaa9ef2c674336991d38d8a04d3cca3fa931a0892973
|
7
|
+
data.tar.gz: 8a4ffe1aa6c98483f9cd64637145802911326a7ef5d766d9526cbbcfb7a62835eefc2d52fa6ac51421f39b8d4f12a7fdf0f2b221bcc2678c5dac058072aec1cd
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/gepub.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_runtime_dependency "nokogiri", ">= 1.8.2", "< 1.
|
21
|
+
s.add_runtime_dependency "nokogiri", ">= 1.8.2", "< 1.11"
|
22
22
|
s.add_development_dependency "rake"
|
23
23
|
s.add_development_dependency "rspec"
|
24
24
|
s.add_runtime_dependency "rubyzip", ">= 1.1.1"
|
data/lib/gepub/book.rb
CHANGED
@@ -9,7 +9,6 @@ require 'fileutils'
|
|
9
9
|
# namespace for gepub library.
|
10
10
|
# The core class is GEPUB::Book. It holds metadata and contents of EPUB file. metadata and contents can be accessed
|
11
11
|
# through GEPUB::Meta and GEPUB::Item.
|
12
|
-
# For generating EPUB file, use GEPUB::Builder.
|
13
12
|
# GEPUB::Item holds information and data of resources like xhtml text, css, scripts, images, videos, etc.
|
14
13
|
# GEPUB::Meta holds metadata(title, creator, publisher, etc.) with its information (alternate script, display sequence, etc.)
|
15
14
|
|
@@ -18,10 +17,6 @@ module GEPUB
|
|
18
17
|
#
|
19
18
|
# It can generate and parse EPUB2/EPUB3 files.
|
20
19
|
#
|
21
|
-
# If you want to generate a new EPUB file, consider using GEPUB::Builder instead
|
22
|
-
# of using Book directly.
|
23
|
-
# Builder is a wrapper class of Book specialized for generating EPUB.
|
24
|
-
#
|
25
20
|
# Book delegates many methods to objects in other class, so you can't find
|
26
21
|
# them in Book#methods or in ri/rdoc documentation. Their descriptions are below.
|
27
22
|
#
|
@@ -93,7 +88,7 @@ module GEPUB
|
|
93
88
|
def self.rootfile_from_container(rootfile)
|
94
89
|
doc = Nokogiri::XML::Document.parse(rootfile)
|
95
90
|
ns = doc.root.namespaces
|
96
|
-
defaultns = ns.select{ |
|
91
|
+
defaultns = ns.select{ |_name, value| value == CONTAINER_NS }.to_a[0][0]
|
97
92
|
doc.css("#{defaultns}|rootfiles > #{defaultns}|rootfile")[0]['full-path']
|
98
93
|
end
|
99
94
|
|
@@ -200,13 +195,13 @@ module GEPUB
|
|
200
195
|
entries['META-INF/container.xml'] = container_xml
|
201
196
|
entries[@package.path] = opf_xml
|
202
197
|
@package.manifest.item_list.each {
|
203
|
-
|
|
198
|
+
|_k, item|
|
204
199
|
if item.content != nil
|
205
200
|
entries[@package.contents_prefix + item.href] = item.content
|
206
201
|
end
|
207
202
|
}
|
208
203
|
|
209
|
-
entries.sort_by { |k,
|
204
|
+
entries.sort_by { |k,_v| k }.each {
|
210
205
|
|k,v|
|
211
206
|
epub.put_next_entry(k)
|
212
207
|
epub << v.force_encoding('us-ascii')
|
@@ -411,7 +406,7 @@ EOF
|
|
411
406
|
def cleanup_for_epub2
|
412
407
|
if version.to_f < 3.0 || @package.epub_backward_compat
|
413
408
|
if @package.manifest.item_list.select {
|
414
|
-
|
|
409
|
+
|_x,item|
|
415
410
|
item.media_type == 'application/x-dtbncx+xml'
|
416
411
|
}.size == 0
|
417
412
|
if (@toc.size == 0)
|
@@ -426,14 +421,14 @@ EOF
|
|
426
421
|
@package.metadata.modified_now
|
427
422
|
|
428
423
|
if @package.manifest.item_list.select {
|
429
|
-
|
|
424
|
+
|_href, item|
|
430
425
|
(item.properties||[]).member? 'nav'
|
431
426
|
}.size == 0
|
432
427
|
generate_nav_doc
|
433
428
|
end
|
434
429
|
|
435
430
|
@package.spine.remove_with_idlist @package.manifest.item_list.map {
|
436
|
-
|
|
431
|
+
|_href, item|
|
437
432
|
item.fallback
|
438
433
|
}.reject(&:nil?)
|
439
434
|
end
|
data/lib/gepub/builder.rb
CHANGED
@@ -3,6 +3,8 @@ module GEPUB
|
|
3
3
|
#
|
4
4
|
# Builder is a wrapper class of Book. It provides DSL to create new EPUB file.
|
5
5
|
#
|
6
|
+
# * Builder is obsolete on v0.7 and after. We will continue to support GEPUB::Builder works fine on version 1.x, but Builder will not be updated any more. For example, landmarks are not supported with Builder.
|
7
|
+
#
|
6
8
|
# = Synopsys
|
7
9
|
# # -*- coding: utf-8 -*-
|
8
10
|
# # GEPUB::Builder example.
|
@@ -179,7 +181,7 @@ module GEPUB
|
|
179
181
|
end
|
180
182
|
end
|
181
183
|
|
182
|
-
def initialize(
|
184
|
+
def initialize(_attributes = {}, &block)
|
183
185
|
@last_defined_item = nil
|
184
186
|
@book = Book.new
|
185
187
|
instance_eval(&block)
|
data/lib/gepub/datemeta.rb
CHANGED
data/lib/gepub/item.rb
CHANGED
@@ -9,7 +9,7 @@ module GEPUB
|
|
9
9
|
attr_accessor :content
|
10
10
|
def self.create(parent, attributes = {})
|
11
11
|
Item.new(attributes['id'], attributes['href'], attributes['media-type'], parent,
|
12
|
-
attributes.reject { |k,
|
12
|
+
attributes.reject { |k,_v| ['id','href','media-type'].member?(k) })
|
13
13
|
end
|
14
14
|
|
15
15
|
#
|
@@ -152,7 +152,7 @@ module GEPUB
|
|
152
152
|
def to_xml(builder, opf_version = '3.0')
|
153
153
|
attr = @attributes.dup
|
154
154
|
if opf_version.to_f < 3.0
|
155
|
-
attr.reject!{ |k,
|
155
|
+
attr.reject!{ |k,_v| k == 'properties' }
|
156
156
|
end
|
157
157
|
if !attr['properties'].nil?
|
158
158
|
attr['properties'] = attr['properties'].uniq.join(' ')
|
data/lib/gepub/manifest.rb
CHANGED
data/lib/gepub/meta.rb
CHANGED
@@ -116,7 +116,7 @@ module GEPUB
|
|
116
116
|
|
117
117
|
# using __send__ to parametarize Namespace and content.
|
118
118
|
target = ns.nil? || @name == 'meta' ? builder : builder[ns]
|
119
|
-
attr = @attributes.reject{|
|
119
|
+
attr = @attributes.reject{|_k,v| v.nil?}.merge(additional_attr)
|
120
120
|
if @content.nil?
|
121
121
|
target.__send__(@name, attr)
|
122
122
|
else
|
@@ -126,7 +126,7 @@ module GEPUB
|
|
126
126
|
if @refiners.size > 0 && opf_version.to_f >= 3.0
|
127
127
|
additional_attr['refines'] = "##{@attributes['id']}"
|
128
128
|
@refiners.each {
|
129
|
-
|
|
129
|
+
|_k, ref_list|
|
130
130
|
ref_list.each {
|
131
131
|
|ref|
|
132
132
|
ref.to_xml(builder, id_pool, nil, additional_attr)
|
data/lib/gepub/metadata.rb
CHANGED
data/lib/gepub/mime.rb
CHANGED
@@ -42,7 +42,7 @@ module GEPUB
|
|
42
42
|
#guess mediatype by mime type mask
|
43
43
|
def self.guess_mediatype(href)
|
44
44
|
ext = File.extname(href)
|
45
|
-
@@mime_types_compiled.select { |pattern,
|
45
|
+
@@mime_types_compiled.select { |pattern, _mime| ext =~ pattern }.values[0]
|
46
46
|
end
|
47
47
|
|
48
48
|
end
|
data/lib/gepub/package.rb
CHANGED
@@ -45,12 +45,12 @@ module GEPUB
|
|
45
45
|
raise "can't specify multiple files on file keyword" if Hash === val && val.length > 1
|
46
46
|
|
47
47
|
@file_preprocess.each {
|
48
|
-
|
|
48
|
+
|_k,p|
|
49
49
|
p.call
|
50
50
|
}
|
51
51
|
@last_defined_item = ResourceItem.new(create_one_file(val))
|
52
52
|
@file_postprocess.each {
|
53
|
-
|
|
53
|
+
|_k,p|
|
54
54
|
p.call
|
55
55
|
}
|
56
56
|
end
|
@@ -58,7 +58,7 @@ module GEPUB
|
|
58
58
|
def files(*arg)
|
59
59
|
arg = arg[0] if arg.size == 1 && Hash === arg[0]
|
60
60
|
@files_preprocess.each {
|
61
|
-
|
|
61
|
+
|_k,p|
|
62
62
|
p.call
|
63
63
|
}
|
64
64
|
@last_defined_item = arg.map {
|
@@ -66,7 +66,7 @@ module GEPUB
|
|
66
66
|
ResourceItem.new(create_one_file(val))
|
67
67
|
}
|
68
68
|
@files_postprocess.each {
|
69
|
-
|
|
69
|
+
|_k,p|
|
70
70
|
p.call
|
71
71
|
}
|
72
72
|
end
|
data/lib/gepub/sorted_array.rb
CHANGED
data/lib/gepub/spine.rb
CHANGED
@@ -6,7 +6,7 @@ module GEPUB
|
|
6
6
|
attr_accessor :opf_version
|
7
7
|
class Itemref
|
8
8
|
def self.create(parent, attributes = {})
|
9
|
-
Itemref.new(attributes['idref'], parent, attributes.reject{|k,
|
9
|
+
Itemref.new(attributes['idref'], parent, attributes.reject{|k,_v| k == 'idref'})
|
10
10
|
end
|
11
11
|
|
12
12
|
def initialize(idref, parent = nil, attributes = {})
|
@@ -70,7 +70,7 @@ module GEPUB
|
|
70
70
|
def to_xml(builder, opf_version)
|
71
71
|
attr = @attributes.dup
|
72
72
|
if opf_version.to_f < 3.0
|
73
|
-
attr.reject!{ |k,
|
73
|
+
attr.reject!{ |k,_v| k == 'properties' }
|
74
74
|
end
|
75
75
|
if !attr['properties'].nil?
|
76
76
|
attr['properties'] = attr['properties'].join(' ')
|
data/lib/gepub/version.rb
CHANGED
data/spec/package_spec.rb
CHANGED
@@ -43,7 +43,7 @@ describe GEPUB::Package do
|
|
43
43
|
package['xml:lang'] = 'ja'
|
44
44
|
|
45
45
|
# metadata add: style 1
|
46
|
-
package.metadata.add_title('EPUB3 Sample',
|
46
|
+
package.metadata.add_title('EPUB3 Sample', title_type: GEPUB::TITLE_TYPE::MAIN) {
|
47
47
|
|title|
|
48
48
|
title.display_seq = 1
|
49
49
|
title.file_as = 'Sample EPUB3'
|
@@ -53,7 +53,7 @@ describe GEPUB::Package do
|
|
53
53
|
'th' => 'EPUB3 ตัวอย่าง (ญี่ปุ่น)')
|
54
54
|
}
|
55
55
|
# metadata add: style2
|
56
|
-
package.metadata.add_title('これでEPUB3もばっちり',
|
56
|
+
package.metadata.add_title('これでEPUB3もばっちり', title_type: GEPUB::TITLE_TYPE::SUBTITLE).display_seq(2).add_alternates('en' => 'you need nothing but this book!')
|
57
57
|
package.metadata.add_creator('小嶋智').display_seq(1).add_alternates('en' => 'KOJIMA Satoshi')
|
58
58
|
package.metadata.add_contributor('電書部').display_seq(1).add_alternates('en' => 'Denshobu')
|
59
59
|
package.metadata.add_contributor('アサガヤデンショ').display_seq(2).add_alternates('en' => 'Asagaya Densho')
|
@@ -117,7 +117,7 @@ describe GEPUB::Package do
|
|
117
117
|
package['xml:lang'] = 'ja'
|
118
118
|
|
119
119
|
# metadata add: style 1
|
120
|
-
package.metadata.add_title('EPUB3 Sample',
|
120
|
+
package.metadata.add_title('EPUB3 Sample', title_type: GEPUB::TITLE_TYPE::MAIN) {
|
121
121
|
|title|
|
122
122
|
title.display_seq = 1
|
123
123
|
title.file_as = 'Sample EPUB3'
|
@@ -127,7 +127,7 @@ describe GEPUB::Package do
|
|
127
127
|
'th' => 'EPUB3 ตัวอย่าง (ญี่ปุ่น)')
|
128
128
|
}
|
129
129
|
# metadata add: style2
|
130
|
-
package.metadata.add_title('これでEPUB3もばっちり',
|
130
|
+
package.metadata.add_title('これでEPUB3もばっちり', title_type: GEPUB::TITLE_TYPE::SUBTITLE).display_seq(2).add_alternates('en' => 'you need nothing but this book!')
|
131
131
|
package.metadata.add_creator('小嶋智').display_seq(1).add_alternates('en' => 'KOJIMA Satoshi')
|
132
132
|
package.metadata.add_contributor('電書部').display_seq(1).add_alternates('en' => 'Denshobu')
|
133
133
|
package.metadata.add_contributor('アサガヤデンショ').display_seq(2).add_alternates('en' => 'Asagaya Densho')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gepub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KOJIMA Satoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 1.8.2
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '1.
|
22
|
+
version: '1.11'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 1.8.2
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '1.
|
32
|
+
version: '1.11'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rake
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,8 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
|
-
|
189
|
-
rubygems_version: 2.7.6
|
188
|
+
rubygems_version: 3.0.1
|
190
189
|
signing_key:
|
191
190
|
specification_version: 4
|
192
191
|
summary: a generic EPUB library for Ruby.
|