gepub 1.0.7 → 1.0.12
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/.github/workflows/gempush.yml +0 -12
- data/.github/workflows/test.yml +11 -10
- data/.rubocop.yml +5 -0
- data/Gemfile +4 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/gepub.gemspec +4 -1
- data/lib/gepub/book.rb +28 -11
- data/lib/gepub/book_add_item.rb +6 -4
- data/lib/gepub/item.rb +13 -7
- data/lib/gepub/metadata.rb +11 -10
- data/lib/gepub/metadata_add.rb +36 -34
- data/lib/gepub/version.rb +1 -1
- data/tools/generate_function.rb +41 -36
- metadata +35 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb1c03b3da62d08f1ba3098494831c199f51dce6157ac83f757ae361274373ca
|
4
|
+
data.tar.gz: e7d95774470bc40930f5eac2cba5dbe7ad10c9e9c4a113cc35660cee49d7cb9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72e09291759ff4e826db2d53424bc06c60ef0b4c1b70870c64975c31b9bc09ca69974f1d3a9e01e49a93772d0036ad0ba3d4b46067444d9c731c3dddd4572112
|
7
|
+
data.tar.gz: 2d5eb3487b3db35d5a30db928bff337cafa569c64b4d5b98764fcea8275ebaf585417458ce2ff61f6a2f67356e629ca6763f92aa434b740ce5e983518d013046
|
@@ -16,18 +16,6 @@ jobs:
|
|
16
16
|
with:
|
17
17
|
ruby-version: 2.6.x
|
18
18
|
|
19
|
-
- name: Publish to GPR
|
20
|
-
run: |
|
21
|
-
mkdir -p $HOME/.gem
|
22
|
-
touch $HOME/.gem/credentials
|
23
|
-
chmod 0600 $HOME/.gem/credentials
|
24
|
-
printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
25
|
-
gem build *.gemspec
|
26
|
-
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
27
|
-
env:
|
28
|
-
GEM_HOST_API_KEY: ${{secrets.GPR_AUTH_TOKEN}}
|
29
|
-
OWNER: skoji
|
30
|
-
|
31
19
|
- name: Publish to RubyGems
|
32
20
|
run: |
|
33
21
|
mkdir -p $HOME/.gem
|
data/.github/workflows/test.yml
CHANGED
@@ -1,28 +1,29 @@
|
|
1
1
|
name: Test
|
2
|
-
on: push
|
2
|
+
on: [push, pull_request]
|
3
3
|
jobs:
|
4
4
|
test:
|
5
|
-
name: test
|
6
|
-
runs-on: ubuntu-latest
|
7
5
|
strategy:
|
8
6
|
matrix:
|
9
|
-
ruby: [2.5
|
7
|
+
ruby: [2.5, 2.6, 2.7, jruby]
|
8
|
+
platform: [ubuntu-latest, macos-latest, windows-latest]
|
9
|
+
runs-on: ${{ matrix.platform }}
|
10
10
|
env:
|
11
11
|
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
12
12
|
steps:
|
13
|
-
- uses: actions/checkout@
|
13
|
+
- uses: actions/checkout@v2
|
14
14
|
- name: Set up Ruby
|
15
|
-
uses:
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
16
|
with:
|
17
17
|
ruby-version: ${{ matrix.ruby }}
|
18
18
|
- name: setup gems
|
19
|
-
run:
|
20
|
-
gem install bundler
|
21
|
-
bundle install
|
19
|
+
run: bundle install --jobs 4 --retry 3
|
22
20
|
- name: run test and publish code coverage
|
21
|
+
if: runner.os == 'Linux' && matrix.ruby == '2.7' && env.CC_TEST_REPORTER_ID != ''
|
23
22
|
uses: paambaati/codeclimate-action@v2.3.0
|
24
23
|
env:
|
25
24
|
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
26
25
|
with:
|
27
26
|
coverageCommand: bundle exec rake spec
|
28
|
-
|
27
|
+
- name: run test
|
28
|
+
if: runner.os != 'Linux' || matrix.ruby != '2.7' || env.CC_TEST_REPORTER_ID == ''
|
29
|
+
run: bundle exec rake spec
|
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
@@ -2,4 +2,7 @@ source "http://rubygems.org"
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in gepub.gemspec
|
4
4
|
gemspec
|
5
|
-
|
5
|
+
|
6
|
+
# workarond : simplecov 0.18 with cc-reporter is broken
|
7
|
+
# https://github.com/codeclimate/test-reporter/issues/418
|
8
|
+
gem 'simplecov', '~> 0.10', '< 0.18', require: false
|
data/README.md
CHANGED
@@ -103,7 +103,7 @@ epubname = File.join(File.dirname(__FILE__), 'example_test.epub')
|
|
103
103
|
# auto-generated nav file will not appear on spine.
|
104
104
|
book.generate_epub(epubname)
|
105
105
|
```
|
106
|
-
* [examples in this repository](https://github.com/skoji/gepub/tree/
|
106
|
+
* [examples in this repository](https://github.com/skoji/gepub/tree/main/examples/)
|
107
107
|
|
108
108
|
## INSTALL:
|
109
109
|
|
data/Rakefile
CHANGED
data/gepub.gemspec
CHANGED
@@ -10,13 +10,16 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = %q{http://github.com/skoji/gepub}
|
11
11
|
s.summary = %q{a generic EPUB library for Ruby.}
|
12
12
|
s.description = %q{gepub is a generic EPUB parser/generator. Generates and parse EPUB2 and EPUB3}
|
13
|
+
s.license = "BSD-3-Clause"
|
13
14
|
|
14
15
|
s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^spec/}) }
|
15
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
17
|
s.require_paths = ["lib"]
|
17
18
|
|
18
19
|
s.add_runtime_dependency "nokogiri", ">= 1.8.2", "< 1.11"
|
19
|
-
s.add_runtime_dependency "rubyzip", "> 1.1.1", "< 2.
|
20
|
+
s.add_runtime_dependency "rubyzip", "> 1.1.1", "< 2.4"
|
21
|
+
s.add_development_dependency "epubcheck-ruby"
|
20
22
|
s.add_development_dependency "rake"
|
21
23
|
s.add_development_dependency "rspec"
|
24
|
+
s.add_development_dependency "rubocop"
|
22
25
|
end
|
data/lib/gepub/book.rb
CHANGED
@@ -68,7 +68,7 @@ module GEPUB
|
|
68
68
|
# returns contributors list by display-seq or defined order.
|
69
69
|
# the contributors without display-seq is appear after contributors with display-seq.
|
70
70
|
# === Book#lastmodified(date) (delegated to Metadata#lastmodified)
|
71
|
-
# set last modified date.
|
71
|
+
# set last modified date. date is a Time, DateTime or string that can be parsed by DateTime#parse.
|
72
72
|
# === Book#modified_now (delegated to Metadata#modified_now)
|
73
73
|
# set last modified date to current time.
|
74
74
|
# === Book#lastmodified (delegated to Metadata#lastmodified)
|
@@ -183,7 +183,14 @@ module GEPUB
|
|
183
183
|
|
184
184
|
# write EPUB to stream specified by the argument.
|
185
185
|
def write_to_epub_container(epub)
|
186
|
-
|
186
|
+
mod_time = Zip::DOSTime.now
|
187
|
+
unless (last_mod = lastmodified).nil?
|
188
|
+
tm = last_mod.content
|
189
|
+
mod_time = Zip::DOSTime.local(tm.year, tm.month, tm.day, tm.hour, tm.min, tm.sec)
|
190
|
+
end
|
191
|
+
|
192
|
+
mimetype_entry = Zip::Entry.new(nil, 'mimetype', nil, nil, nil, nil, nil, nil, mod_time)
|
193
|
+
epub.put_next_entry(mimetype_entry, nil, nil, Zip::Entry::STORED)
|
187
194
|
epub << "application/epub+zip"
|
188
195
|
|
189
196
|
entries = {}
|
@@ -203,7 +210,8 @@ module GEPUB
|
|
203
210
|
|
204
211
|
entries.sort_by { |k,_v| k }.each {
|
205
212
|
|k,v|
|
206
|
-
|
213
|
+
zip_entry = Zip::Entry.new(nil, k, nil, nil, nil, nil, nil, nil, mod_time)
|
214
|
+
epub.put_next_entry(zip_entry)
|
207
215
|
epub << v.force_encoding('us-ascii')
|
208
216
|
}
|
209
217
|
end
|
@@ -258,7 +266,7 @@ EOF
|
|
258
266
|
|
259
267
|
def nav_doc(title = 'Table of Contents')
|
260
268
|
# handle cascaded toc
|
261
|
-
start_level = @toc && @toc[0][:level] || 1
|
269
|
+
start_level = @toc && !@toc.empty? && @toc[0][:level] || 1
|
262
270
|
stacked_toc = {level: start_level, tocs: [] }
|
263
271
|
@toc.inject(stacked_toc) do |current_stack, toc_entry|
|
264
272
|
toc_entry_level = toc_entry[:level] || 1
|
@@ -299,7 +307,6 @@ EOF
|
|
299
307
|
|landmark|
|
300
308
|
id = landmark[:id].nil? ? "" : "##{x[:id]}"
|
301
309
|
landmark_title = landmark[:title]
|
302
|
-
type = landmark[:type]
|
303
310
|
xml_doc.li {
|
304
311
|
xml_doc.a({'href' => landmark[:item].href + id, 'epub:type' => landmark[:type]}, landmark_title)
|
305
312
|
}
|
@@ -309,6 +316,9 @@ EOF
|
|
309
316
|
# build nav
|
310
317
|
builder = Nokogiri::XML::Builder.new {
|
311
318
|
|doc|
|
319
|
+
unless version.to_f < 3.0
|
320
|
+
doc.doc.create_internal_subset('html', nil, nil )
|
321
|
+
end
|
312
322
|
doc.html('xmlns' => "http://www.w3.org/1999/xhtml",'xmlns:epub' => "http://www.idpf.org/2007/ops") {
|
313
323
|
doc.head {
|
314
324
|
doc.title title
|
@@ -390,6 +400,7 @@ EOF
|
|
390
400
|
end
|
391
401
|
return package, package_path
|
392
402
|
end
|
403
|
+
private_class_method :parse_container
|
393
404
|
|
394
405
|
def self.check_consistency_of_package(package, package_path)
|
395
406
|
if package.nil?
|
@@ -397,9 +408,11 @@ EOF
|
|
397
408
|
end
|
398
409
|
|
399
410
|
if package_path != package.path
|
400
|
-
warn
|
411
|
+
warn "inconsistend EPUB file: container says opf is #{package_path}, but actually #{package.path}"
|
401
412
|
end
|
402
413
|
end
|
414
|
+
private_class_method :check_consistency_of_package
|
415
|
+
|
403
416
|
def self.parse_files_into_package(files, package)
|
404
417
|
files.each {
|
405
418
|
|k, content|
|
@@ -410,13 +423,15 @@ EOF
|
|
410
423
|
end
|
411
424
|
}
|
412
425
|
end
|
426
|
+
private_class_method :parse_files_into_package
|
427
|
+
|
413
428
|
def cleanup_for_epub2
|
414
429
|
if version.to_f < 3.0 || @package.epub_backward_compat
|
415
430
|
if @package.manifest.item_list.select {
|
416
431
|
|_x,item|
|
417
432
|
item.media_type == 'application/x-dtbncx+xml'
|
418
433
|
}.size == 0
|
419
|
-
if (@toc.size == 0)
|
434
|
+
if (@toc.size == 0 && !@package.spine.itemref_list.empty?)
|
420
435
|
@toc << { :item => @package.manifest.item_list[@package.spine.itemref_list[0].idref] }
|
421
436
|
end
|
422
437
|
add_item('toc.ncx', id: 'ncx', content: StringIO.new(ncx_xml))
|
@@ -425,7 +440,7 @@ EOF
|
|
425
440
|
end
|
426
441
|
def cleanup_for_epub3
|
427
442
|
if version.to_f >=3.0
|
428
|
-
@package.metadata.modified_now
|
443
|
+
@package.metadata.modified_now unless @package.metadata.lastmodified_updated?
|
429
444
|
|
430
445
|
if @package.manifest.item_list.select {
|
431
446
|
|_href, item|
|
@@ -455,10 +470,12 @@ EOF
|
|
455
470
|
item_attributes.each do |attr, val|
|
456
471
|
next if val.nil?
|
457
472
|
method_name = if attr == :toc_text
|
458
|
-
|
473
|
+
""
|
474
|
+
elsif attr == :property
|
475
|
+
"add_"
|
459
476
|
else
|
460
|
-
"
|
461
|
-
end
|
477
|
+
"set_"
|
478
|
+
end + attr.to_s
|
462
479
|
item.send(method_name, val)
|
463
480
|
end
|
464
481
|
item
|
data/lib/gepub/book_add_item.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
+
## this file is automatically generated by tools/generate_function.rb . do not edit this code directly.
|
2
|
+
|
1
3
|
module GEPUB
|
2
4
|
class Book
|
3
5
|
# add an item(i.e. html, images, audios, etc) to Book.
|
4
6
|
# the added item will be referenced by the first argument in the EPUB container.
|
5
7
|
def add_item(href, deprecated_content = nil, deprecated_id = nil, deprecated_attributes = nil, content: nil,
|
6
|
-
id: nil,media_type: nil,fallback: nil,properties: nil,media_overlay: nil,toc_text: nil,
|
8
|
+
id: nil,media_type: nil,fallback: nil,properties: nil,media_overlay: nil,toc_text: nil,property: nil,
|
7
9
|
attributes: {})
|
8
10
|
content, id, attributes = handle_deprecated_add_item_arguments(deprecated_content, deprecated_id, deprecated_attributes, content, id, attributes)
|
9
|
-
add_item_internal(href, content: content, item_attributes: { id: id,media_type: media_type,fallback: fallback,properties: properties,media_overlay: media_overlay,toc_text: toc_text }, attributes: attributes, ordered: false)
|
11
|
+
add_item_internal(href, content: content, item_attributes: { id: id,media_type: media_type,fallback: fallback,properties: properties,media_overlay: media_overlay,toc_text: toc_text,property: property }, attributes: attributes, ordered: false)
|
10
12
|
end
|
11
13
|
|
12
14
|
# same as add_item, but the item will be added to spine of the EPUB.
|
13
15
|
def add_ordered_item(href, deprecated_content = nil, deprecated_id = nil, deprecated_attributes = nil, content:nil,
|
14
|
-
id: nil,media_type: nil,fallback: nil,properties: nil,media_overlay: nil,toc_text: nil,
|
16
|
+
id: nil,media_type: nil,fallback: nil,properties: nil,media_overlay: nil,toc_text: nil,property: nil,
|
15
17
|
attributes: {})
|
16
18
|
content, id, attributes = handle_deprecated_add_item_arguments(deprecated_content, deprecated_id, deprecated_attributes, content, id, attributes)
|
17
|
-
add_item_internal(href, content: content, item_attributes: { id: id,media_type: media_type,fallback: fallback,properties: properties,media_overlay: media_overlay,toc_text: toc_text }, attributes: attributes, ordered: true)
|
19
|
+
add_item_internal(href, content: content, item_attributes: { id: id,media_type: media_type,fallback: fallback,properties: properties,media_overlay: media_overlay,toc_text: toc_text,property: property }, attributes: attributes, ordered: true)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
data/lib/gepub/item.rb
CHANGED
@@ -97,9 +97,7 @@ module GEPUB
|
|
97
97
|
# guess and set content property from contents.
|
98
98
|
def guess_content_property
|
99
99
|
if File.extname(self.href) =~ /.x?html/ && @attributes['media-type'] === 'application/xhtml+xml'
|
100
|
-
@attributes['properties']
|
101
|
-
|x| x == 'svg' || x == 'mathml' || x == 'switch' || x == 'remote-resources'
|
102
|
-
}
|
100
|
+
@attributes['properties'] ||= []
|
103
101
|
parsed = Nokogiri::XML::Document.parse(@content)
|
104
102
|
return unless parsed.root.node_name === "html"
|
105
103
|
ns_prefix = parsed.namespaces.invert['http://www.w3.org/1999/xhtml']
|
@@ -108,9 +106,10 @@ module GEPUB
|
|
108
106
|
else
|
109
107
|
prefix = "#{ns_prefix}:"
|
110
108
|
end
|
109
|
+
images = parsed.xpath("//#{prefix}img[starts-with(@src,'http')]")
|
111
110
|
videos = parsed.xpath("//#{prefix}video[starts-with(@src,'http')]") + parsed.xpath("//#{prefix}video/#{prefix}source[starts-with(@src,'http')]")
|
112
111
|
audios = parsed.xpath("//#{prefix}audio[starts-with(@src,'http')]") + parsed.xpath("//#{prefix}audio/#{prefix}source[starts-with(@src,'http')]")
|
113
|
-
if videos.size > 0 || audios.size > 0
|
112
|
+
if images.size > 0 || videos.size > 0 || audios.size > 0
|
114
113
|
self.add_property('remote-resources')
|
115
114
|
end
|
116
115
|
if parsed.xpath("//p:math", { 'p' => 'http://www.w3.org/1998/Math/MathML' }).size > 0
|
@@ -139,12 +138,19 @@ module GEPUB
|
|
139
138
|
self
|
140
139
|
end
|
141
140
|
|
142
|
-
# add content
|
141
|
+
# add content from io or file to the item
|
143
142
|
def add_content(io_or_filename)
|
144
|
-
io = io_or_filename
|
145
143
|
if io_or_filename.class == String
|
146
|
-
|
144
|
+
File.open(io_or_filename, mode='r') do |f|
|
145
|
+
add_content_io f
|
146
|
+
end
|
147
|
+
else
|
148
|
+
add_content_io io_or_filename
|
147
149
|
end
|
150
|
+
self
|
151
|
+
end
|
152
|
+
|
153
|
+
def add_content_io(io)
|
148
154
|
io.binmode
|
149
155
|
@content = io.read
|
150
156
|
if File.extname(self.href) =~ /x?html$/
|
data/lib/gepub/metadata.rb
CHANGED
@@ -54,6 +54,7 @@ module GEPUB
|
|
54
54
|
|
55
55
|
}
|
56
56
|
}
|
57
|
+
# do not set @lastmodified_updated here
|
57
58
|
}
|
58
59
|
end
|
59
60
|
|
@@ -73,9 +74,14 @@ module GEPUB
|
|
73
74
|
@spread = NilContent
|
74
75
|
@ibooks_version = NilContent
|
75
76
|
@ibooks_scroll_axis = NilContent
|
77
|
+
@lastmodified_updated = false
|
76
78
|
yield self if block_given?
|
77
79
|
end
|
78
80
|
|
81
|
+
def lastmodified_updated?
|
82
|
+
@lastmodified_updated
|
83
|
+
end
|
84
|
+
|
79
85
|
def to_xml(builder)
|
80
86
|
builder.metadata(@namespaces) {
|
81
87
|
@content_nodes.each {
|
@@ -165,7 +171,7 @@ module GEPUB
|
|
165
171
|
end
|
166
172
|
|
167
173
|
def identifier_by_id(id)
|
168
|
-
@content_nodes['identifier'].each {
|
174
|
+
(@content_nodes['identifier'] || []).each {
|
169
175
|
|x|
|
170
176
|
return x.content if x['id'] == id
|
171
177
|
}
|
@@ -186,14 +192,16 @@ module GEPUB
|
|
186
192
|
}
|
187
193
|
ret.size == 0 ? nil : ret[0]
|
188
194
|
else
|
195
|
+
@lastmodified_updated = true
|
189
196
|
date ||= Time.now
|
197
|
+
date = DateTime.parse(date) if date.is_a? String
|
190
198
|
(@content_nodes['meta'] ||= []).each {
|
191
199
|
|meta|
|
192
200
|
if (meta['property'] == 'dcterms:modified')
|
193
201
|
@content_nodes['meta'].delete meta
|
194
202
|
end
|
195
203
|
}
|
196
|
-
add_metadata('meta', date.utc.strftime('%Y-%m-%dT%H:%M:%SZ'), itemclass: DateMeta)['property'] = 'dcterms:modified'
|
204
|
+
add_metadata('meta', date.to_time.utc.strftime('%Y-%m-%dT%H:%M:%SZ'), itemclass: DateMeta)['property'] = 'dcterms:modified'
|
197
205
|
end
|
198
206
|
end
|
199
207
|
|
@@ -207,14 +215,7 @@ module GEPUB
|
|
207
215
|
|
208
216
|
def set_lastmodified(date=nil)
|
209
217
|
warn "obsolete : set_lastmodified. use lastmodified instead."
|
210
|
-
date
|
211
|
-
(@content_nodes['meta'] ||= []).each {
|
212
|
-
|meta|
|
213
|
-
if (meta['property'] == 'dcterms:modified')
|
214
|
-
@content_nodes['meta'].delete meta
|
215
|
-
end
|
216
|
-
}
|
217
|
-
add_metadata('meta', date.utc.strftime('%Y-%m-%dT%H:%M:%SZ'), itemclass: DateMeta)['property'] = 'dcterms:modified'
|
218
|
+
lastmodified(date)
|
218
219
|
end
|
219
220
|
|
220
221
|
def add_oldstyle_meta(content, attributes = {})
|
data/lib/gepub/metadata_add.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
## this file is automatically generated by tools/generate_function.rb . do not edit this code directly.
|
2
|
+
|
1
3
|
module GEPUB
|
2
|
-
|
4
|
+
class Metadata
|
3
5
|
CONTENT_NODE_LIST = ['identifier', 'title', 'language', 'contributor', 'creator', 'coverage', 'date','description','format','publisher','relation','rights','source','subject','type'].each {
|
4
6
|
|node|
|
5
7
|
define_method(node + '_list') { @content_nodes[node].dup.sort_as_meta }
|
@@ -14,7 +16,7 @@ module GEPUB
|
|
14
16
|
|
15
17
|
define_method(node, ->(content=UNASSIGNED, deprecated_id=nil, id:nil,
|
16
18
|
title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
|
17
|
-
|
19
|
+
lang: nil, alternates: {}) {
|
18
20
|
if unassigned?(content)
|
19
21
|
get_first_node(node)
|
20
22
|
else
|
@@ -48,7 +50,7 @@ module GEPUB
|
|
48
50
|
|
49
51
|
def add_title(content, deprecated_id = nil, deprecated_title_type = nil, id: nil,
|
50
52
|
title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
|
51
|
-
|
53
|
+
lang: nil, alternates: {})
|
52
54
|
if deprecated_id
|
53
55
|
warn 'second argument for add_title is deprecated. use id: instead'
|
54
56
|
id = deprecated_id
|
@@ -58,15 +60,15 @@ module GEPUB
|
|
58
60
|
title_type = deprecated_title_type
|
59
61
|
end
|
60
62
|
meta = add_metadata('title', content, id: id,
|
61
|
-
|
62
|
-
|
63
|
+
title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
|
64
|
+
lang: lang, alternates: alternates)
|
63
65
|
yield meta if block_given?
|
64
66
|
meta
|
65
67
|
end
|
66
68
|
|
67
69
|
def add_person(name, content, deprecated_id = nil, deprecated_role = nil, id: nil,
|
68
|
-
|
69
|
-
|
70
|
+
title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
|
71
|
+
lang: nil, alternates: {})
|
70
72
|
if deprecated_id
|
71
73
|
warn 'second argument for add_person is deprecated. use id: instead'
|
72
74
|
id = deprecated_id
|
@@ -76,15 +78,15 @@ module GEPUB
|
|
76
78
|
role = deprecated_role
|
77
79
|
end
|
78
80
|
meta = add_metadata(name, content, id: id,
|
79
|
-
|
80
|
-
|
81
|
+
title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
|
82
|
+
lang: lang, alternates: alternates)
|
81
83
|
yield meta if block_given?
|
82
84
|
meta
|
83
85
|
end
|
84
86
|
|
85
87
|
def add_creator(content, deprecated_id = nil, deprecated_role = nil, id: nil,
|
86
88
|
title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
|
87
|
-
|
89
|
+
lang: nil, alternates: {})
|
88
90
|
if deprecated_id
|
89
91
|
warn 'second argument for add_creator is deprecated. use id: instead'
|
90
92
|
id = deprecated_id
|
@@ -93,17 +95,17 @@ module GEPUB
|
|
93
95
|
warn 'third argument for add_creator is deprecated. use role: instead'
|
94
96
|
role = deprecated_role
|
95
97
|
end
|
96
|
-
|
98
|
+
role = 'aut' if role.nil?
|
97
99
|
meta = add_person('creator', content, id: id,
|
98
|
-
|
99
|
-
|
100
|
+
title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
|
101
|
+
lang: lang, alternates: alternates)
|
100
102
|
yield meta if block_given?
|
101
103
|
meta
|
102
104
|
end
|
103
105
|
|
104
106
|
def add_contributor(content, deprecated_id = nil, deprecated_role = nil, id: nil,
|
105
107
|
title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
|
106
|
-
|
108
|
+
lang: nil, alternates: {})
|
107
109
|
if deprecated_id
|
108
110
|
warn 'second argument for add_contributor is deprecated. use id: instead'
|
109
111
|
id = deprecated_id
|
@@ -113,30 +115,30 @@ module GEPUB
|
|
113
115
|
role = deprecated_role
|
114
116
|
end
|
115
117
|
meta = add_person('contributor', content, id: id,
|
116
|
-
|
117
|
-
|
118
|
+
title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
|
119
|
+
lang: lang, alternates: alternates)
|
118
120
|
yield meta if block_given?
|
119
121
|
meta
|
120
122
|
end
|
121
123
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
def add_metadata(name, content, id: nil, itemclass: Meta,
|
125
|
+
title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
|
126
|
+
lang: nil, alternates: {}
|
127
|
+
)
|
128
|
+
meta = add_metadata_internal(name, content, id: id, itemclass: itemclass)
|
127
129
|
[{ value: title_type, name: 'title-type'},{ value: identifier_type, name: 'identifier-type'},{ value: display_seq, name: 'display-seq'},{ value: file_as, name: 'file-as'},{ value: group_position, name: 'group-position'},{ value: role, name: 'role'}].each do |refiner|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
130
|
+
if refiner[:value]
|
131
|
+
meta.refine(refiner[:name], refiner[:value])
|
132
|
+
end
|
133
|
+
end
|
134
|
+
if lang
|
135
|
+
meta.lang = lang
|
136
|
+
end
|
137
|
+
if alternates
|
138
|
+
meta.add_alternates alternates
|
139
|
+
end
|
138
140
|
yield meta if block_given?
|
139
|
-
|
140
|
-
|
141
|
-
|
141
|
+
meta
|
142
|
+
end
|
143
|
+
end
|
142
144
|
end
|
data/lib/gepub/version.rb
CHANGED
data/tools/generate_function.rb
CHANGED
@@ -4,10 +4,13 @@ attrs = GEPUB::Item::ATTRIBUTES.select do |attr|
|
|
4
4
|
end.map do |attr|
|
5
5
|
attr.sub('-', '_')
|
6
6
|
end
|
7
|
-
attrs << "toc_text"
|
7
|
+
attrs << "toc_text"
|
8
|
+
attrs << "property"
|
8
9
|
attrs_arguments_string = attrs.map { |attr| "#{attr}: nil" }.join(',')
|
9
10
|
attrs_internal_string = "{ " + attrs.map { |attr| "#{attr}: #{attr}"}.join(',') + " }"
|
10
11
|
File.write(File.join(File.dirname(__FILE__), "../lib/gepub/book_add_item.rb"), <<EOF)
|
12
|
+
## this file is automatically generated by tools/generate_function.rb . do not edit this code directly.
|
13
|
+
|
11
14
|
module GEPUB
|
12
15
|
class Book
|
13
16
|
# add an item(i.e. html, images, audios, etc) to Book.
|
@@ -34,7 +37,7 @@ require_relative '../lib/gepub/dsl_util.rb'
|
|
34
37
|
require_relative '../lib/gepub/meta.rb'
|
35
38
|
|
36
39
|
refiners = GEPUB::Meta::REFINERS.map do |refiner|
|
37
|
-
|
40
|
+
refiner.sub('-', '_')
|
38
41
|
end
|
39
42
|
|
40
43
|
refiners_arguments_string = refiners.map { |refiner| "#{refiner}: nil" }.join(',')
|
@@ -45,8 +48,10 @@ meta_attr_arguments_string = "lang: nil, alternates: {}"
|
|
45
48
|
meta_attr_arguments_set_string = "lang: lang, alternates: alternates"
|
46
49
|
|
47
50
|
File.write(File.join(File.dirname(__FILE__), "../lib/gepub/metadata_add.rb"), <<EOF)
|
51
|
+
## this file is automatically generated by tools/generate_function.rb . do not edit this code directly.
|
52
|
+
|
48
53
|
module GEPUB
|
49
|
-
|
54
|
+
class Metadata
|
50
55
|
CONTENT_NODE_LIST = ['identifier', 'title', 'language', 'contributor', 'creator', 'coverage', 'date','description','format','publisher','relation','rights','source','subject','type'].each {
|
51
56
|
|node|
|
52
57
|
define_method(node + '_list') { @content_nodes[node].dup.sort_as_meta }
|
@@ -61,7 +66,7 @@ module GEPUB
|
|
61
66
|
|
62
67
|
define_method(node, ->(content=UNASSIGNED, deprecated_id=nil, id:nil,
|
63
68
|
#{refiners_arguments_string},
|
64
|
-
|
69
|
+
#{meta_attr_arguments_string}) {
|
65
70
|
if unassigned?(content)
|
66
71
|
get_first_node(node)
|
67
72
|
else
|
@@ -95,7 +100,7 @@ module GEPUB
|
|
95
100
|
|
96
101
|
def add_title(content, deprecated_id = nil, deprecated_title_type = nil, id: nil,
|
97
102
|
#{refiners_arguments_string},
|
98
|
-
|
103
|
+
#{meta_attr_arguments_string})
|
99
104
|
if deprecated_id
|
100
105
|
warn 'second argument for add_title is deprecated. use id: instead'
|
101
106
|
id = deprecated_id
|
@@ -105,15 +110,15 @@ module GEPUB
|
|
105
110
|
title_type = deprecated_title_type
|
106
111
|
end
|
107
112
|
meta = add_metadata('title', content, id: id,
|
108
|
-
|
109
|
-
|
113
|
+
#{refiners_arguments_set_string},
|
114
|
+
#{meta_attr_arguments_set_string})
|
110
115
|
yield meta if block_given?
|
111
116
|
meta
|
112
117
|
end
|
113
118
|
|
114
119
|
def add_person(name, content, deprecated_id = nil, deprecated_role = nil, id: nil,
|
115
|
-
|
116
|
-
|
120
|
+
#{refiners_arguments_string},
|
121
|
+
#{meta_attr_arguments_string})
|
117
122
|
if deprecated_id
|
118
123
|
warn 'second argument for add_person is deprecated. use id: instead'
|
119
124
|
id = deprecated_id
|
@@ -123,15 +128,15 @@ module GEPUB
|
|
123
128
|
role = deprecated_role
|
124
129
|
end
|
125
130
|
meta = add_metadata(name, content, id: id,
|
126
|
-
|
127
|
-
|
131
|
+
#{refiners_arguments_set_string},
|
132
|
+
#{meta_attr_arguments_set_string})
|
128
133
|
yield meta if block_given?
|
129
134
|
meta
|
130
135
|
end
|
131
136
|
|
132
137
|
def add_creator(content, deprecated_id = nil, deprecated_role = nil, id: nil,
|
133
138
|
#{refiners_arguments_string},
|
134
|
-
|
139
|
+
#{meta_attr_arguments_string})
|
135
140
|
if deprecated_id
|
136
141
|
warn 'second argument for add_creator is deprecated. use id: instead'
|
137
142
|
id = deprecated_id
|
@@ -140,17 +145,17 @@ module GEPUB
|
|
140
145
|
warn 'third argument for add_creator is deprecated. use role: instead'
|
141
146
|
role = deprecated_role
|
142
147
|
end
|
143
|
-
|
148
|
+
role = 'aut' if role.nil?
|
144
149
|
meta = add_person('creator', content, id: id,
|
145
|
-
|
146
|
-
|
150
|
+
#{refiners_arguments_set_string},
|
151
|
+
#{meta_attr_arguments_set_string})
|
147
152
|
yield meta if block_given?
|
148
153
|
meta
|
149
154
|
end
|
150
155
|
|
151
156
|
def add_contributor(content, deprecated_id = nil, deprecated_role = nil, id: nil,
|
152
157
|
#{refiners_arguments_string},
|
153
|
-
|
158
|
+
#{meta_attr_arguments_string})
|
154
159
|
if deprecated_id
|
155
160
|
warn 'second argument for add_contributor is deprecated. use id: instead'
|
156
161
|
id = deprecated_id
|
@@ -160,32 +165,32 @@ module GEPUB
|
|
160
165
|
role = deprecated_role
|
161
166
|
end
|
162
167
|
meta = add_person('contributor', content, id: id,
|
163
|
-
|
164
|
-
|
168
|
+
#{refiners_arguments_set_string},
|
169
|
+
#{meta_attr_arguments_set_string})
|
165
170
|
yield meta if block_given?
|
166
171
|
meta
|
167
172
|
end
|
168
173
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
+
def add_metadata(name, content, id: nil, itemclass: Meta,
|
175
|
+
#{refiners_arguments_string},
|
176
|
+
#{meta_attr_arguments_string}
|
177
|
+
)
|
178
|
+
meta = add_metadata_internal(name, content, id: id, itemclass: itemclass)
|
174
179
|
#{refiners_string}.each do |refiner|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
180
|
+
if refiner[:value]
|
181
|
+
meta.refine(refiner[:name], refiner[:value])
|
182
|
+
end
|
183
|
+
end
|
184
|
+
if lang
|
185
|
+
meta.lang = lang
|
186
|
+
end
|
187
|
+
if alternates
|
188
|
+
meta.add_alternates alternates
|
189
|
+
end
|
185
190
|
yield meta if block_given?
|
186
|
-
|
187
|
-
|
188
|
-
|
191
|
+
meta
|
192
|
+
end
|
193
|
+
end
|
189
194
|
end
|
190
195
|
EOF
|
191
196
|
|
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.12
|
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: 2020-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: 1.1.1
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '2.
|
42
|
+
version: '2.4'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,21 @@ dependencies:
|
|
49
49
|
version: 1.1.1
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '2.
|
52
|
+
version: '2.4'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: epubcheck-ruby
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
53
67
|
- !ruby/object:Gem::Dependency
|
54
68
|
name: rake
|
55
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,6 +92,20 @@ dependencies:
|
|
78
92
|
- - ">="
|
79
93
|
- !ruby/object:Gem::Version
|
80
94
|
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rubocop
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
81
109
|
description: gepub is a generic EPUB parser/generator. Generates and parse EPUB2 and
|
82
110
|
EPUB3
|
83
111
|
email:
|
@@ -92,6 +120,7 @@ files:
|
|
92
120
|
- ".github/workflows/gempush.yml"
|
93
121
|
- ".github/workflows/test.yml"
|
94
122
|
- ".gitignore"
|
123
|
+
- ".rubocop.yml"
|
95
124
|
- Gemfile
|
96
125
|
- LICENSE.txt
|
97
126
|
- README.md
|
@@ -128,7 +157,8 @@ files:
|
|
128
157
|
- lib/gepub/xml_util.rb
|
129
158
|
- tools/generate_function.rb
|
130
159
|
homepage: http://github.com/skoji/gepub
|
131
|
-
licenses:
|
160
|
+
licenses:
|
161
|
+
- BSD-3-Clause
|
132
162
|
metadata: {}
|
133
163
|
post_install_message:
|
134
164
|
rdoc_options: []
|