gepub 0.6.1 → 0.6.2
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.
- data/{README.rdoc → README.md} +8 -8
- data/lib/gepub/book.rb +24 -8
- data/lib/gepub/gepuber.rb +14 -13
- data/lib/gepub/version.rb +1 -1
- data/lib/gepub/xml_util.rb +4 -2
- data/spec/example_spec.rb +1 -1
- metadata +8 -8
data/{README.rdoc → README.md}
RENAMED
@@ -1,29 +1,29 @@
|
|
1
|
-
= gepub
|
2
|
-
{<img src="https://secure.travis-ci.org/skoji/gepub.png" />}[http://travis-ci.org/skoji/gepub]
|
1
|
+
# gepub [<img src="https://secure.travis-ci.org/skoji/gepub.png" />](http://travis-ci.org/skoji/gepub)
|
3
2
|
|
4
3
|
* http://github.com/skoji/gepub
|
5
4
|
|
6
|
-
|
5
|
+
## DESCRIPTION:
|
7
6
|
|
8
7
|
a generic EPUB parser/generator library.
|
9
8
|
|
10
|
-
|
9
|
+
## FEATURES/PROBLEMS:
|
11
10
|
|
12
11
|
* GEPUB::Book provides functionality to create EPUB file, and parsing EPUB file
|
13
12
|
* from version 0.6, GEPUB::Book will be able handle almost every metadata in EPUB2/EPUB3.
|
14
13
|
.. but is still beta version. Please inform me when you find bugs.
|
15
|
-
|
16
14
|
* Will provide easy to generate EPUB class, like Nokogiri::XML::Generator.
|
17
15
|
|
18
|
-
|
16
|
+
* See [issues](https://github.com/skoji/gepub/issues/) for known problems.
|
17
|
+
|
18
|
+
## SYNOPSIS:
|
19
19
|
|
20
20
|
see examples directory.
|
21
21
|
|
22
|
-
|
22
|
+
## INSTALL:
|
23
23
|
|
24
24
|
* gem install gepub
|
25
25
|
|
26
|
-
|
26
|
+
## LICENSE:
|
27
27
|
|
28
28
|
(The New BSD License)
|
29
29
|
|
data/lib/gepub/book.rb
CHANGED
@@ -31,23 +31,33 @@ module GEPUB
|
|
31
31
|
files[entry.name] = zis.read
|
32
32
|
case entry.name
|
33
33
|
when MIMETYPE then
|
34
|
-
files[MIMETYPE]
|
34
|
+
if files[MIMETYPE] != MIMETYPE_CONTENTS
|
35
|
+
warn "#{MIMETYPE} is not valid: should be #{MIMETYPE_CONTENTS} but was #{files[MIMETYPE]}"
|
36
|
+
end
|
37
|
+
files.delete(MIMETYPE)
|
35
38
|
when CONTAINER then
|
36
|
-
package_path = rootfile_from_container(files[
|
37
|
-
files
|
39
|
+
package_path = rootfile_from_container(files[CONTAINER])
|
40
|
+
files.delete(CONTAINER)
|
38
41
|
when ROOTFILE_PATTERN then
|
39
42
|
package = Package.parse_opf(files[entry.name], entry.name)
|
43
|
+
files.delete(entry.name)
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|
47
|
+
|
48
|
+
if package.nil?
|
49
|
+
raise 'this container do not cotains publication information file'
|
50
|
+
end
|
51
|
+
|
43
52
|
if package_path != package.path
|
44
53
|
warn 'inconsistend EPUB file: container says opf is #{package_path}, but actually #{package.path}'
|
45
54
|
end
|
55
|
+
|
46
56
|
files.each {
|
47
57
|
|k, content|
|
48
58
|
item = package.manifest.item_by_href(k.sub(/^#{package.contents_prefix}/,''))
|
49
59
|
if !item.nil?
|
50
|
-
files
|
60
|
+
files.delete(k)
|
51
61
|
item.add_raw_content(content)
|
52
62
|
end
|
53
63
|
}
|
@@ -102,13 +112,19 @@ module GEPUB
|
|
102
112
|
def ordered(&block)
|
103
113
|
@package.ordered(&block)
|
104
114
|
end
|
115
|
+
|
105
116
|
def generate_epub(path_to_epub)
|
106
|
-
if (@toc.size == 0)
|
107
|
-
@toc << { :item => @package.spine.itemref_list[0] }
|
108
|
-
end
|
109
117
|
|
110
118
|
if version.to_f < 3.0 || @package.epub_backward_compat
|
111
|
-
|
119
|
+
if @package.manifest.item_list.select {
|
120
|
+
|x,item|
|
121
|
+
item.media_type == 'application/x-dtbncx+xml'
|
122
|
+
}.size == 0
|
123
|
+
if (@toc.size == 0)
|
124
|
+
@toc << { :item => @package.manifest.item_list[@package.spine.itemref_list[0].idref] }
|
125
|
+
end
|
126
|
+
add_item('toc.ncx', StringIO.new(ncx_xml), 'ncx')
|
127
|
+
end
|
112
128
|
end
|
113
129
|
|
114
130
|
if version.to_f >=3.0
|
data/lib/gepub/gepuber.rb
CHANGED
@@ -22,11 +22,11 @@ module GEPUB
|
|
22
22
|
attr_accessor :texts, :resources, :epubname, :coverimg, :table_of_contents, :provider
|
23
23
|
|
24
24
|
def method_missing(name, *args)
|
25
|
-
@
|
25
|
+
@book.send(name, *args)
|
26
26
|
end
|
27
27
|
|
28
28
|
def initialize(param)
|
29
|
-
@
|
29
|
+
@book = GEPUB::Book.new()
|
30
30
|
param.each {
|
31
31
|
|k,v|
|
32
32
|
self.send "#{k}=", v
|
@@ -42,22 +42,23 @@ module GEPUB
|
|
42
42
|
def create(destbasedir = ".")
|
43
43
|
@provider.new(@texts).each {
|
44
44
|
|f, fio|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
45
|
+
@book.ordered {
|
46
|
+
item = add_item(f, fio)
|
47
|
+
if !@table_of_contents[f].nil?
|
48
|
+
item.toc_text table_of_contents[f]
|
49
|
+
@table_of_contents.each {
|
50
|
+
|k,v|
|
51
|
+
k =~ /^#{f}#(.*)$/
|
52
|
+
add_nav(item, v, $1) unless $1.nil?
|
53
|
+
}
|
54
|
+
end
|
55
|
+
}
|
55
56
|
}
|
56
57
|
|
57
58
|
@provider.new(@resources).each {
|
58
59
|
|f, fio|
|
59
60
|
item = add_item(f, fio)
|
60
|
-
|
61
|
+
item.cover_image if File.basename(f) == @coverimg
|
61
62
|
}
|
62
63
|
generate_epub(File.join(destbasedir, @epubname + '.epub'))
|
63
64
|
end
|
data/lib/gepub/version.rb
CHANGED
data/lib/gepub/xml_util.rb
CHANGED
@@ -17,8 +17,10 @@ module GEPUB
|
|
17
17
|
|k,v|
|
18
18
|
attributes[k] = v.to_s
|
19
19
|
}
|
20
|
-
|
21
|
-
|
20
|
+
if attributes['lang']
|
21
|
+
attributes['xml:lang'] = attributes['lang'];
|
22
|
+
attributes.delete('lang')
|
23
|
+
end
|
22
24
|
attributes
|
23
25
|
end
|
24
26
|
end
|
data/spec/example_spec.rb
CHANGED
@@ -21,7 +21,7 @@ describe 'GEPUB usage' do
|
|
21
21
|
'th' => 'GEPUB ตัวอย่าง (ญี่ปุ่น)')
|
22
22
|
}
|
23
23
|
# you can do the same thing using method chain
|
24
|
-
book.add_title('これはあくまでサンプルです',nil, GEPUB::TITLE_TYPE::SUBTITLE).set_display_seq(
|
24
|
+
book.add_title('これはあくまでサンプルです',nil, GEPUB::TITLE_TYPE::SUBTITLE).set_display_seq(2).add_alternates('en' => 'this book is just a sample.')
|
25
25
|
book.add_creator('小嶋智') {
|
26
26
|
|creator|
|
27
27
|
creator.display_seq = 1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gepub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-02-20 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70172284071640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70172284071640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &70172284071140 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.5.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70172284071140
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rubyzip
|
38
|
-
requirement: &
|
38
|
+
requirement: &70172284070680 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 0.9.6
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70172284070680
|
47
47
|
description: gepub is a EPUB parser/generator. Generates EPUB2 opf. will support EPUB3
|
48
48
|
parse/generation
|
49
49
|
email:
|
@@ -57,7 +57,7 @@ files:
|
|
57
57
|
- .gitignore
|
58
58
|
- .travis.yml
|
59
59
|
- Gemfile
|
60
|
-
- README.
|
60
|
+
- README.md
|
61
61
|
- Rakefile
|
62
62
|
- bin/gepuber
|
63
63
|
- examples/generate_example.rb
|