eeepub 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/eeepub.gemspec +3 -3
- data/examples/simple_epub.rb +2 -2
- data/lib/eeepub/maker.rb +18 -4
- data/lib/eeepub/ocf.rb +13 -24
- data/spec/eeepub/maker_spec.rb +6 -4
- data/spec/eeepub/ocf_spec.rb +2 -1
- metadata +69 -85
data/eeepub.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "eeepub"
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.8.0"
|
6
6
|
s.platform = Gem::Platform::RUBY
|
7
7
|
s.authors = ["jugyo"]
|
8
8
|
s.email = ["jugyo.org@gmail.com"]
|
@@ -16,9 +16,9 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
|
18
18
|
s.add_dependency "builder"
|
19
|
-
s.add_dependency "
|
19
|
+
s.add_dependency "rubyzip"
|
20
20
|
s.add_development_dependency "rspec"
|
21
21
|
s.add_development_dependency "nokogiri"
|
22
22
|
s.add_development_dependency "rr"
|
23
|
-
s.add_development_dependency "simplecov"
|
23
|
+
s.add_development_dependency "simplecov"
|
24
24
|
end
|
data/examples/simple_epub.rb
CHANGED
@@ -9,8 +9,8 @@ epub = EeePub.make do
|
|
9
9
|
creator 'jugyo'
|
10
10
|
publisher 'jugyo.org'
|
11
11
|
date '2010-05-06'
|
12
|
-
|
13
|
-
|
12
|
+
uid 'BookId'
|
13
|
+
identifier 'http://example.com/book/foo', :scheme => 'URL', :id => 'BookId'
|
14
14
|
|
15
15
|
files [File.join(dir, 'foo.html'), File.join(dir, 'bar.html')]
|
16
16
|
nav [
|
data/lib/eeepub/maker.rb
CHANGED
@@ -4,14 +4,21 @@ require 'fileutils'
|
|
4
4
|
module EeePub
|
5
5
|
# The class to make ePub easily
|
6
6
|
#
|
7
|
+
# Note on unique identifiers:
|
8
|
+
#
|
9
|
+
# At least one 'identifier' must be the unique identifer represented by the name
|
10
|
+
# given to 'uid' and set via the hash option :id => {name}. The default name for
|
11
|
+
# uid is 'BookId' and doesn't need to be specified explicitly. If no identifier is
|
12
|
+
# marked as the unique identifier, the first one give will be chosen.
|
13
|
+
#
|
7
14
|
# @example
|
8
15
|
# epub = EeePub.make do
|
9
16
|
# title 'sample'
|
10
17
|
# creator 'jugyo'
|
11
18
|
# publisher 'jugyo.org'
|
12
19
|
# date '2010-05-06'
|
13
|
-
#
|
14
|
-
#
|
20
|
+
# uid 'BookId'
|
21
|
+
# identifier 'http://example.com/book/foo', :scheme => 'URL', :id => 'BookId'
|
15
22
|
#
|
16
23
|
# files ['/path/to/foo.html', '/path/to/bar.html']
|
17
24
|
# nav [
|
@@ -56,7 +63,7 @@ module EeePub
|
|
56
63
|
|
57
64
|
def identifier(id, options)
|
58
65
|
@identifiers ||= []
|
59
|
-
@identifiers << {:value => id, :scheme => options[:scheme]}
|
66
|
+
@identifiers << {:value => id, :scheme => options[:scheme], :id => options[:id]}
|
60
67
|
end
|
61
68
|
|
62
69
|
# @param [Proc] block the block for initialize
|
@@ -87,6 +94,12 @@ module EeePub
|
|
87
94
|
private
|
88
95
|
|
89
96
|
def create_epub
|
97
|
+
@uid ||= 'BookId'
|
98
|
+
unique_identifier = @identifiers.select{ |i| i[:id] == @uid }.first
|
99
|
+
unless unique_identifier
|
100
|
+
unique_identifier = @identifiers.first
|
101
|
+
unique_identifier[:id] = @uid
|
102
|
+
end
|
90
103
|
dir = Dir.mktmpdir
|
91
104
|
@files.each do |file|
|
92
105
|
case file
|
@@ -101,13 +114,14 @@ module EeePub
|
|
101
114
|
end
|
102
115
|
|
103
116
|
NCX.new(
|
104
|
-
:uid => @uid,
|
117
|
+
:uid => @identifiers.select{ |i| i[:id] == @uid }.first,
|
105
118
|
:title => @titles[0],
|
106
119
|
:nav => @nav
|
107
120
|
).save(File.join(dir, @ncx_file))
|
108
121
|
|
109
122
|
OPF.new(
|
110
123
|
:title => @titles,
|
124
|
+
:unique_identifier => @uid,
|
111
125
|
:identifier => @identifiers,
|
112
126
|
:creator => @creators,
|
113
127
|
:publisher => @publishers,
|
data/lib/eeepub/ocf.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'zip/zip'
|
2
2
|
|
3
3
|
module EeePub
|
4
4
|
# Class to create OCF
|
@@ -92,16 +92,17 @@ module EeePub
|
|
92
92
|
output_path = File.expand_path(output_path)
|
93
93
|
|
94
94
|
create_epub do
|
95
|
-
Zip::
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
95
|
+
mimetype = Zip::ZipOutputStream::open(output_path) do |os|
|
96
|
+
os.put_next_entry("mimetype", nil, nil, Zip::ZipEntry::STORED, Zlib::NO_COMPRESSION)
|
97
|
+
os << "application/epub+zip"
|
98
|
+
end
|
99
|
+
zipfile = Zip::ZipFile.open(output_path)
|
100
|
+
Dir.glob('**/*').each do |path|
|
101
|
+
zipfile.add(path, path)
|
103
102
|
end
|
103
|
+
zipfile.commit
|
104
104
|
end
|
105
|
+
FileUtils.remove_entry_secure dir
|
105
106
|
end
|
106
107
|
|
107
108
|
# Stream OCF
|
@@ -109,27 +110,15 @@ module EeePub
|
|
109
110
|
# @return [String] streaming output of the zip/epub file.
|
110
111
|
def render
|
111
112
|
create_epub do
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
zip.add_dir(path)
|
116
|
-
else
|
117
|
-
zip.add_file(path, path)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
return buffer
|
113
|
+
temp_file = Tempfile.new("ocf")
|
114
|
+
self.save(temp_file.path)
|
115
|
+
return temp_file.read
|
123
116
|
end
|
124
117
|
end
|
125
118
|
|
126
119
|
private
|
127
120
|
def create_epub
|
128
121
|
FileUtils.chdir(dir) do
|
129
|
-
File.open('mimetype', 'w') do |f|
|
130
|
-
f << 'application/epub+zip'
|
131
|
-
end
|
132
|
-
|
133
122
|
meta_inf = 'META-INF'
|
134
123
|
FileUtils.mkdir_p(meta_inf)
|
135
124
|
|
data/spec/eeepub/maker_spec.rb
CHANGED
@@ -28,7 +28,7 @@ describe "EeePub::Maker" do
|
|
28
28
|
it { @maker.instance_variable_get(:@creators).should == ['jugyo'] }
|
29
29
|
it { @maker.instance_variable_get(:@publishers).should == ['jugyo.org'] }
|
30
30
|
it { @maker.instance_variable_get(:@dates).should == ["2010-05-06"] }
|
31
|
-
it { @maker.instance_variable_get(:@identifiers).should == [{:value => 'http://example.com/book/foo', :scheme => 'URL'}] }
|
31
|
+
it { @maker.instance_variable_get(:@identifiers).should == [{:value => 'http://example.com/book/foo', :scheme => 'URL', :id => nil}] }
|
32
32
|
it { @maker.instance_variable_get(:@uid).should == 'http://example.com/book/foo' }
|
33
33
|
it { @maker.instance_variable_get(:@ncx_file).should == 'toc.ncx' }
|
34
34
|
it { @maker.instance_variable_get(:@opf_file).should == 'content.opf' }
|
@@ -49,7 +49,7 @@ describe "EeePub::Maker" do
|
|
49
49
|
{:label => '1. foo', :content => 'foo.html'},
|
50
50
|
{:label => '1. bar', :content => 'bar.html'}
|
51
51
|
],
|
52
|
-
:uid => "http://example.com/book/foo"
|
52
|
+
:uid=>{:value=>"http://example.com/book/foo", :scheme=>"URL", :id=>"http://example.com/book/foo"}
|
53
53
|
) { stub!.save }
|
54
54
|
mock(EeePub::OPF).new(
|
55
55
|
:title => ["sample"],
|
@@ -62,7 +62,8 @@ describe "EeePub::Maker" do
|
|
62
62
|
:relation => ['xxx'],
|
63
63
|
:ncx => "toc.ncx",
|
64
64
|
:publisher => ["jugyo.org"],
|
65
|
-
:
|
65
|
+
:unique_identifier=>"http://example.com/book/foo",
|
66
|
+
:identifier => [{:value => "http://example.com/book/foo", :scheme => "URL", :id => "http://example.com/book/foo"}],
|
66
67
|
:manifest => ['foo.html', 'bar.html']
|
67
68
|
) { stub!.save }
|
68
69
|
mock(EeePub::OCF).new(
|
@@ -113,7 +114,8 @@ describe "EeePub::Maker" do
|
|
113
114
|
:relation => ['xxx'],
|
114
115
|
:ncx => "toc.ncx",
|
115
116
|
:publisher => ["jugyo.org"],
|
116
|
-
:
|
117
|
+
:unique_identifier=>"http://example.com/book/foo",
|
118
|
+
:identifier => [{:value => "http://example.com/book/foo", :scheme => "URL", :id=>"http://example.com/book/foo"}],
|
117
119
|
:manifest => ["foo/bar/foo.html", "foo/bar/baz/bar.html"]
|
118
120
|
) { stub!.save }
|
119
121
|
mock(EeePub::OCF).new.with_any_args { stub!.save }
|
data/spec/eeepub/ocf_spec.rb
CHANGED
metadata
CHANGED
@@ -1,94 +1,89 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: eeepub
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.7.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- jugyo
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-09-19 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: builder
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &10621420 !ruby/object:Gem::Requirement
|
20
17
|
none: false
|
21
|
-
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
25
22
|
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: zipruby
|
29
23
|
prerelease: false
|
30
|
-
|
24
|
+
version_requirements: *10621420
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rubyzip
|
27
|
+
requirement: &10620300 !ruby/object:Gem::Requirement
|
31
28
|
none: false
|
32
|
-
requirements:
|
33
|
-
- -
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
36
33
|
type: :runtime
|
37
|
-
version_requirements: *id002
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: rspec
|
40
34
|
prerelease: false
|
41
|
-
|
35
|
+
version_requirements: *10620300
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &10619520 !ruby/object:Gem::Requirement
|
42
39
|
none: false
|
43
|
-
requirements:
|
44
|
-
- -
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version:
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
47
44
|
type: :development
|
48
|
-
version_requirements: *id003
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: nokogiri
|
51
45
|
prerelease: false
|
52
|
-
|
46
|
+
version_requirements: *10619520
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: nokogiri
|
49
|
+
requirement: &10618100 !ruby/object:Gem::Requirement
|
53
50
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version:
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
58
55
|
type: :development
|
59
|
-
version_requirements: *id004
|
60
|
-
- !ruby/object:Gem::Dependency
|
61
|
-
name: rr
|
62
56
|
prerelease: false
|
63
|
-
|
57
|
+
version_requirements: *10618100
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rr
|
60
|
+
requirement: &10617360 !ruby/object:Gem::Requirement
|
64
61
|
none: false
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version:
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
69
66
|
type: :development
|
70
|
-
version_requirements: *id005
|
71
|
-
- !ruby/object:Gem::Dependency
|
72
|
-
name: simplecov
|
73
67
|
prerelease: false
|
74
|
-
|
68
|
+
version_requirements: *10617360
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: &10616540 !ruby/object:Gem::Requirement
|
75
72
|
none: false
|
76
|
-
requirements:
|
77
|
-
- -
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version:
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
80
77
|
type: :development
|
81
|
-
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *10616540
|
82
80
|
description: EeePub is a Ruby ePub generator.
|
83
|
-
email:
|
81
|
+
email:
|
84
82
|
- jugyo.org@gmail.com
|
85
83
|
executables: []
|
86
|
-
|
87
84
|
extensions: []
|
88
|
-
|
89
85
|
extra_rdoc_files: []
|
90
|
-
|
91
|
-
files:
|
86
|
+
files:
|
92
87
|
- .gitignore
|
93
88
|
- Gemfile
|
94
89
|
- LICENSE
|
@@ -112,39 +107,28 @@ files:
|
|
112
107
|
- spec/eeepub/opf_spec.rb
|
113
108
|
- spec/eeepub_spec.rb
|
114
109
|
- spec/spec_helper.rb
|
115
|
-
has_rdoc: true
|
116
110
|
homepage: http://github.com/jugyo/eeepub
|
117
111
|
licenses: []
|
118
|
-
|
119
112
|
post_install_message:
|
120
113
|
rdoc_options: []
|
121
|
-
|
122
|
-
require_paths:
|
114
|
+
require_paths:
|
123
115
|
- lib
|
124
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
117
|
none: false
|
126
|
-
requirements:
|
127
|
-
- -
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
version:
|
130
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
123
|
none: false
|
132
|
-
requirements:
|
133
|
-
- -
|
134
|
-
- !ruby/object:Gem::Version
|
135
|
-
version:
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
136
128
|
requirements: []
|
137
|
-
|
138
129
|
rubyforge_project:
|
139
|
-
rubygems_version: 1.
|
130
|
+
rubygems_version: 1.8.10
|
140
131
|
signing_key:
|
141
132
|
specification_version: 3
|
142
133
|
summary: ePub generator
|
143
|
-
test_files:
|
144
|
-
- spec/eeepub/easy_spec.rb
|
145
|
-
- spec/eeepub/maker_spec.rb
|
146
|
-
- spec/eeepub/ncx_spec.rb
|
147
|
-
- spec/eeepub/ocf_spec.rb
|
148
|
-
- spec/eeepub/opf_spec.rb
|
149
|
-
- spec/eeepub_spec.rb
|
150
|
-
- spec/spec_helper.rb
|
134
|
+
test_files: []
|