eeepub 0.4.2 → 0.5.0
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/VERSION +1 -1
- data/examples/files/bar.html +32 -0
- data/examples/files/foo.html +32 -0
- data/lib/eeepub/easy.rb +71 -0
- data/lib/eeepub/maker.rb +10 -0
- data/lib/eeepub.rb +1 -0
- data/spec/eeepub/easy_spec.rb +64 -0
- data/spec/eeepub/maker_spec.rb +10 -0
- metadata +7 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/examples/files/bar.html
CHANGED
@@ -6,5 +6,37 @@
|
|
6
6
|
</head>
|
7
7
|
<body>
|
8
8
|
<h1>bar</h1>
|
9
|
+
|
10
|
+
<p>foo foo foo foo</p>
|
11
|
+
<p>bar bar bar bar</p>
|
12
|
+
<p>foo foo foo foo</p>
|
13
|
+
<p>bar bar bar bar</p>
|
14
|
+
<p>foo foo foo foo</p>
|
15
|
+
<p>bar bar bar bar</p>
|
16
|
+
<p>foo foo foo foo</p>
|
17
|
+
<p>bar bar bar bar</p>
|
18
|
+
<p>foo foo foo foo</p>
|
19
|
+
<p>bar bar bar bar</p>
|
20
|
+
<p>foo foo foo foo</p>
|
21
|
+
<p>bar bar bar bar</p>
|
22
|
+
<p>foo foo foo foo</p>
|
23
|
+
<p>bar bar bar bar</p>
|
24
|
+
|
25
|
+
<h2 id="bar-1">bar-1</h2>
|
26
|
+
|
27
|
+
<p>foo foo foo foo</p>
|
28
|
+
<p>bar bar bar bar</p>
|
29
|
+
<p>foo foo foo foo</p>
|
30
|
+
<p>bar bar bar bar</p>
|
31
|
+
<p>foo foo foo foo</p>
|
32
|
+
<p>bar bar bar bar</p>
|
33
|
+
<p>foo foo foo foo</p>
|
34
|
+
<p>bar bar bar bar</p>
|
35
|
+
<p>foo foo foo foo</p>
|
36
|
+
<p>bar bar bar bar</p>
|
37
|
+
<p>foo foo foo foo</p>
|
38
|
+
<p>bar bar bar bar</p>
|
39
|
+
<p>foo foo foo foo</p>
|
40
|
+
<p>bar bar bar bar</p>
|
9
41
|
</body>
|
10
42
|
</html>
|
data/examples/files/foo.html
CHANGED
@@ -6,5 +6,37 @@
|
|
6
6
|
</head>
|
7
7
|
<body>
|
8
8
|
<h1>foo</h1>
|
9
|
+
|
10
|
+
<p>foo foo foo foo</p>
|
11
|
+
<p>bar bar bar bar</p>
|
12
|
+
<p>foo foo foo foo</p>
|
13
|
+
<p>bar bar bar bar</p>
|
14
|
+
<p>foo foo foo foo</p>
|
15
|
+
<p>bar bar bar bar</p>
|
16
|
+
<p>foo foo foo foo</p>
|
17
|
+
<p>bar bar bar bar</p>
|
18
|
+
<p>foo foo foo foo</p>
|
19
|
+
<p>bar bar bar bar</p>
|
20
|
+
<p>foo foo foo foo</p>
|
21
|
+
<p>bar bar bar bar</p>
|
22
|
+
<p>foo foo foo foo</p>
|
23
|
+
<p>bar bar bar bar</p>
|
24
|
+
|
25
|
+
<h2 id="foo-1">foo-1</h2>
|
26
|
+
|
27
|
+
<p>foo foo foo foo</p>
|
28
|
+
<p>bar bar bar bar</p>
|
29
|
+
<p>foo foo foo foo</p>
|
30
|
+
<p>bar bar bar bar</p>
|
31
|
+
<p>foo foo foo foo</p>
|
32
|
+
<p>bar bar bar bar</p>
|
33
|
+
<p>foo foo foo foo</p>
|
34
|
+
<p>bar bar bar bar</p>
|
35
|
+
<p>foo foo foo foo</p>
|
36
|
+
<p>bar bar bar bar</p>
|
37
|
+
<p>foo foo foo foo</p>
|
38
|
+
<p>bar bar bar bar</p>
|
39
|
+
<p>foo foo foo foo</p>
|
40
|
+
<p>bar bar bar bar</p>
|
9
41
|
</body>
|
10
42
|
</html>
|
data/lib/eeepub/easy.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module EeePub
|
5
|
+
# The class to make ePub more easily
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# epub = EeePub::Easy.new do
|
9
|
+
# title 'sample'
|
10
|
+
# creator 'jugyo'
|
11
|
+
# identifier 'http://example.com/book/foo', :scheme => 'URL'
|
12
|
+
# uid 'http://example.com/book/foo'
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# epub.sections << ['1. foo', <<HTML]
|
16
|
+
# <?xml version="1.0" encoding="UTF-8"?>
|
17
|
+
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
18
|
+
# <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
|
19
|
+
# <head>
|
20
|
+
# <title>foo</title>
|
21
|
+
# </head>
|
22
|
+
# <body>
|
23
|
+
# <p>
|
24
|
+
# foo foo foo foo foo foo
|
25
|
+
# </p>
|
26
|
+
# </body>
|
27
|
+
# </html>
|
28
|
+
# HTML
|
29
|
+
#
|
30
|
+
# epub.assets << 'image.png'
|
31
|
+
#
|
32
|
+
# epub.save('sample.epub')
|
33
|
+
class Easy < EeePub::Maker
|
34
|
+
attr_reader :sections, :assets
|
35
|
+
|
36
|
+
# @param [Proc] block the block for initialize
|
37
|
+
def initialize(&block)
|
38
|
+
@sections = []
|
39
|
+
@assets = []
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
# Save as ePub file
|
44
|
+
#
|
45
|
+
# @param [String] filename the ePub file name to save
|
46
|
+
def save(filename)
|
47
|
+
Dir.mktmpdir do |dir|
|
48
|
+
prepare(dir)
|
49
|
+
super
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def prepare(dir)
|
56
|
+
filenames = []
|
57
|
+
sections.each_with_index do |section, index|
|
58
|
+
filename = File.join(dir, "section_#{index}.html")
|
59
|
+
File.open(filename, 'w') { |file| file.write section[1] }
|
60
|
+
filenames << filename
|
61
|
+
end
|
62
|
+
|
63
|
+
files(filenames + assets)
|
64
|
+
nav(
|
65
|
+
[sections, filenames].transpose.map do |section, filename|
|
66
|
+
{:label => section[0], :content => File.basename(filename)}
|
67
|
+
end
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/eeepub/maker.rb
CHANGED
@@ -28,6 +28,11 @@ module EeePub
|
|
28
28
|
:creator,
|
29
29
|
:publisher,
|
30
30
|
:date,
|
31
|
+
:language,
|
32
|
+
:subject,
|
33
|
+
:description,
|
34
|
+
:rights,
|
35
|
+
:relation
|
31
36
|
].each do |name|
|
32
37
|
class_eval <<-DELIM
|
33
38
|
def #{name}(value)
|
@@ -85,6 +90,11 @@ module EeePub
|
|
85
90
|
:creator => @creators,
|
86
91
|
:publisher => @publishers,
|
87
92
|
:date => @dates,
|
93
|
+
:language => @languages,
|
94
|
+
:subject => @subjects,
|
95
|
+
:description => @descriptions,
|
96
|
+
:rights => @rightss,
|
97
|
+
:relation => @relations,
|
88
98
|
:manifest => @files.map{|i| File.basename(i)},
|
89
99
|
:ncx => @ncx_file
|
90
100
|
).save(File.join(dir, @opf_file))
|
data/lib/eeepub.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "EeePub::Easy" do
|
4
|
+
before do
|
5
|
+
@easy = EeePub::Easy.new do
|
6
|
+
title 'sample'
|
7
|
+
creator 'jugyo'
|
8
|
+
identifier 'http://example.com/book/foo', :scheme => 'URL'
|
9
|
+
uid 'http://example.com/book/foo'
|
10
|
+
end
|
11
|
+
|
12
|
+
@easy.sections << ['1. foo', <<HTML]
|
13
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
14
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
15
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
|
16
|
+
<head>
|
17
|
+
<title>foo</title>
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
<p>
|
21
|
+
foo foo foo foo foo foo
|
22
|
+
</p>
|
23
|
+
</body>
|
24
|
+
</html>
|
25
|
+
HTML
|
26
|
+
|
27
|
+
@easy.sections << ['2. bar', <<HTML]
|
28
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
29
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
30
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
|
31
|
+
<head>
|
32
|
+
<title>bar</title>
|
33
|
+
</head>
|
34
|
+
<body>
|
35
|
+
<p>
|
36
|
+
bar bar bar bar bar bar
|
37
|
+
</p>
|
38
|
+
</body>
|
39
|
+
</html>
|
40
|
+
HTML
|
41
|
+
|
42
|
+
@easy.assets << 'image.png'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'spec for prepare' do
|
46
|
+
Dir.mktmpdir do |dir|
|
47
|
+
@easy.send(:prepare, dir)
|
48
|
+
|
49
|
+
file1 = File.join(dir, 'section_0.html')
|
50
|
+
file2 = File.join(dir, 'section_1.html')
|
51
|
+
File.exists?(file1).should be_true
|
52
|
+
File.exists?(file2).should be_true
|
53
|
+
File.read(file1).should == @easy.sections[0][1]
|
54
|
+
File.read(file2).should == @easy.sections[1][1]
|
55
|
+
|
56
|
+
@easy.instance_variable_get(:@nav).should == [
|
57
|
+
{:label => '1. foo', :content => 'section_0.html'},
|
58
|
+
{:label => '2. bar', :content => 'section_1.html'}
|
59
|
+
]
|
60
|
+
|
61
|
+
@easy.instance_variable_get(:@files).should == [file1, file2, 'image.png']
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/eeepub/maker_spec.rb
CHANGED
@@ -7,6 +7,11 @@ describe "EeePub::Maker" do
|
|
7
7
|
creator 'jugyo'
|
8
8
|
publisher 'jugyo.org'
|
9
9
|
date "2010-05-06"
|
10
|
+
language 'en'
|
11
|
+
subject 'epub sample'
|
12
|
+
description 'this is epub sample'
|
13
|
+
rights 'xxx'
|
14
|
+
relation 'xxx'
|
10
15
|
identifier 'http://example.com/book/foo', :scheme => 'URL'
|
11
16
|
uid 'http://example.com/book/foo'
|
12
17
|
ncx_file 'toc.ncx'
|
@@ -50,6 +55,11 @@ describe "EeePub::Maker" do
|
|
50
55
|
:title => ["sample"],
|
51
56
|
:creator => ["jugyo"],
|
52
57
|
:date => ["2010-05-06"],
|
58
|
+
:language => ['en'],
|
59
|
+
:subject => ['epub sample'],
|
60
|
+
:description => ['this is epub sample'],
|
61
|
+
:rights => ['xxx'],
|
62
|
+
:relation => ['xxx'],
|
53
63
|
:ncx => "toc.ncx",
|
54
64
|
:publisher => ["jugyo.org"],
|
55
65
|
:identifier => [{:value => "http://example.com/book/foo", :scheme => "URL"}],
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- jugyo
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-16 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -74,10 +74,12 @@ files:
|
|
74
74
|
- examples/simple_epub.rb
|
75
75
|
- lib/eeepub.rb
|
76
76
|
- lib/eeepub/container_item.rb
|
77
|
+
- lib/eeepub/easy.rb
|
77
78
|
- lib/eeepub/maker.rb
|
78
79
|
- lib/eeepub/ncx.rb
|
79
80
|
- lib/eeepub/ocf.rb
|
80
81
|
- lib/eeepub/opf.rb
|
82
|
+
- spec/eeepub/easy_spec.rb
|
81
83
|
- spec/eeepub/maker_spec.rb
|
82
84
|
- spec/eeepub/ncx_spec.rb
|
83
85
|
- spec/eeepub/ocf_spec.rb
|
@@ -116,6 +118,7 @@ signing_key:
|
|
116
118
|
specification_version: 3
|
117
119
|
summary: ePub generator
|
118
120
|
test_files:
|
121
|
+
- spec/eeepub/easy_spec.rb
|
119
122
|
- spec/eeepub/maker_spec.rb
|
120
123
|
- spec/eeepub/ncx_spec.rb
|
121
124
|
- spec/eeepub/ocf_spec.rb
|