gepub 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/gepuber +50 -0
- data/gepub.gemspec +7 -4
- data/lib/gepub/book.rb +17 -48
- data/lib/gepub/gepuber.rb +63 -0
- data/lib/gepub.rb +1 -0
- metadata +9 -37
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/bin/gepuber
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'gepub'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
def usage
|
5
|
+
STDERR.print "gepuber [-d destination ] <source-directory>\r\n"
|
6
|
+
exit 1
|
7
|
+
end
|
8
|
+
|
9
|
+
def srccheck(srcdir)
|
10
|
+
if !File.exist?(srcdir) || !File.directory?(srcdir)
|
11
|
+
STDERR.print "#{srcdir} is not a directory"
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
if !File.exist?(File.join(srcdir, 'gepuber.conf'))
|
15
|
+
STDERR.print "gepuber.conf does not exists in#{srcdir}."
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def destcheck(destdir)
|
21
|
+
if (File.exist?(destdir) && !File.directory?(destdir))
|
22
|
+
STDERR.print "#{destdir} is not a directory\n"
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
destbasedir = "."
|
28
|
+
|
29
|
+
opt = OptionParser.new
|
30
|
+
|
31
|
+
usage if ARGV.length < 1
|
32
|
+
|
33
|
+
opt.on('-d [directory]') { |dir|
|
34
|
+
destbasedir = dir
|
35
|
+
}
|
36
|
+
|
37
|
+
destbasedir = File.expand_path(destbasedir)
|
38
|
+
|
39
|
+
srcdir = opt.parse(ARGV)[0]
|
40
|
+
srccheck(srcdir)
|
41
|
+
|
42
|
+
Dir.chdir(srcdir)
|
43
|
+
begin
|
44
|
+
File.open('gepuber.conf', 'rb') {
|
45
|
+
|io|
|
46
|
+
gepuber = GEPUB::Gepuber.new(io.read)
|
47
|
+
gepuber.create destbasedir
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
data/gepub.gemspec
CHANGED
@@ -5,13 +5,15 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{gepub}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["KOJIMA Satoshi"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-04-15}
|
13
|
+
s.default_executable = %q{gepuber}
|
13
14
|
s.description = %q{an easy-to-use (and easy-to-implement) EPUB generator.}
|
14
15
|
s.email = %q{skoji@skoji.jp}
|
16
|
+
s.executables = ["gepuber"]
|
15
17
|
s.extra_rdoc_files = [
|
16
18
|
"README.rdoc"
|
17
19
|
]
|
@@ -21,18 +23,20 @@ Gem::Specification.new do |s|
|
|
21
23
|
"README.rdoc",
|
22
24
|
"Rakefile",
|
23
25
|
"VERSION",
|
26
|
+
"bin/gepuber",
|
24
27
|
"examples/example.rb",
|
25
28
|
"gepub.gemspec",
|
26
29
|
"lib/gepub.rb",
|
27
30
|
"lib/gepub/book.rb",
|
28
31
|
"lib/gepub/generator.rb",
|
32
|
+
"lib/gepub/gepuber.rb",
|
29
33
|
"lib/gepub/item.rb",
|
30
34
|
"spec/gepub_spec.rb",
|
31
35
|
"spec/spec_helper.rb"
|
32
36
|
]
|
33
37
|
s.homepage = %q{http://github.com/skoji/gepub}
|
34
38
|
s.require_paths = ["lib"]
|
35
|
-
s.rubygems_version = %q{1.
|
39
|
+
s.rubygems_version = %q{1.5.2}
|
36
40
|
s.summary = %q{a good-enough EPUB generator.}
|
37
41
|
s.test_files = [
|
38
42
|
"examples/example.rb",
|
@@ -41,7 +45,6 @@ Gem::Specification.new do |s|
|
|
41
45
|
]
|
42
46
|
|
43
47
|
if s.respond_to? :specification_version then
|
44
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
48
|
s.specification_version = 3
|
46
49
|
|
47
50
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/lib/gepub/book.rb
CHANGED
@@ -7,8 +7,19 @@ require 'fileutils'
|
|
7
7
|
|
8
8
|
module GEPUB
|
9
9
|
class Book
|
10
|
-
attr_accessor :spine
|
10
|
+
attr_accessor :spine, :locale
|
11
11
|
|
12
|
+
def self.def_meta(name, key = nil)
|
13
|
+
key ||= name
|
14
|
+
define_method name.to_sym do
|
15
|
+
instance_variable_get('@metadata')[key.to_sym]
|
16
|
+
end
|
17
|
+
define_method ( name.to_s + "=" ).to_sym do
|
18
|
+
|v|
|
19
|
+
instance_variable_get('@metadata')[key.to_sym] = v
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
12
23
|
def initialize(title, contents_prefix="")
|
13
24
|
@metadata = {}
|
14
25
|
@metadata[:identifier] = []
|
@@ -23,45 +34,11 @@ module GEPUB
|
|
23
34
|
@locale = 'en'
|
24
35
|
end
|
25
36
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@metadata[:title] = title
|
32
|
-
end
|
33
|
-
|
34
|
-
def author
|
35
|
-
@metadata[:creator]
|
36
|
-
end
|
37
|
-
|
38
|
-
def author=(author)
|
39
|
-
@metadata[:creator] = author
|
40
|
-
end
|
41
|
-
|
42
|
-
def contributor
|
43
|
-
@metadata[:contributor]
|
44
|
-
end
|
45
|
-
|
46
|
-
def contributor=(contributor)
|
47
|
-
@metadata[:contributor] = contributor
|
48
|
-
end
|
49
|
-
|
50
|
-
def publisher
|
51
|
-
@metadata[:publisher]
|
52
|
-
end
|
53
|
-
|
54
|
-
def publisher=(publisher)
|
55
|
-
@metadata[:publisher] = publisher
|
56
|
-
end
|
57
|
-
|
58
|
-
def date
|
59
|
-
@metadata[:date]
|
60
|
-
end
|
61
|
-
|
62
|
-
def date=(date)
|
63
|
-
@metadata[:date] = date
|
64
|
-
end
|
37
|
+
def_meta :title
|
38
|
+
def_meta :author, :creator
|
39
|
+
def_meta :contributor
|
40
|
+
def_meta :publisher
|
41
|
+
def_meta :date
|
65
42
|
|
66
43
|
def identifier
|
67
44
|
@main_identifier
|
@@ -72,14 +49,6 @@ module GEPUB
|
|
72
49
|
@main_identifier = id
|
73
50
|
end
|
74
51
|
|
75
|
-
def locale
|
76
|
-
@locale
|
77
|
-
end
|
78
|
-
|
79
|
-
def locale=(locale)
|
80
|
-
@locale = locale
|
81
|
-
end
|
82
|
-
|
83
52
|
def setIdentifier(scheme, identfier)
|
84
53
|
@metadata[:identifier] << { :scheme => scheme, :identifier => identifier }
|
85
54
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
module GEPUB
|
4
|
+
class Gepuber
|
5
|
+
|
6
|
+
def self.book_setter(*namelist)
|
7
|
+
namelist.each {
|
8
|
+
|name|
|
9
|
+
define_method (name.to_sym) {
|
10
|
+
|arg|
|
11
|
+
@book.send(name.to_s + "=" , arg)
|
12
|
+
}
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.attr_setter(*namelist)
|
17
|
+
namelist.each {
|
18
|
+
|name|
|
19
|
+
define_method (name.to_sym) {
|
20
|
+
|arg|
|
21
|
+
instance_variable_set("@" + name.to_s, arg)
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_setter :texts, :resources, :epubname, :coverimg, :book, :toc
|
27
|
+
book_setter :title, :author, :publisher, :date, :identifier, :locale
|
28
|
+
|
29
|
+
def initialize(str)
|
30
|
+
@book = GEPUB::Book.new('', 'OEBPS')
|
31
|
+
@book.locale = 'ja'
|
32
|
+
instance_eval(str)
|
33
|
+
@texts ||= Dir.glob('[0-9]*.html')
|
34
|
+
@resources ||= Dir.glob('*.css') + Dir.glob(File.join('img', '*'))
|
35
|
+
@coverimg ||= 'cover.jpg'
|
36
|
+
@toc ||= {}
|
37
|
+
@epubname ||= 'gepuber_generated'
|
38
|
+
end
|
39
|
+
|
40
|
+
def create(destbasedir = ".")
|
41
|
+
|
42
|
+
@texts.each {
|
43
|
+
|f|
|
44
|
+
File.open(f,'rb') {
|
45
|
+
|fio|
|
46
|
+
item = @book.add_item(f, fio)
|
47
|
+
@book.spine << item
|
48
|
+
@book.add_nav(item, @toc[f]) if !@toc[f].nil?
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
@resources.each {
|
53
|
+
|f|
|
54
|
+
File.open(f,'rb') {
|
55
|
+
|fio|
|
56
|
+
item = @book.add_item(f, fio)
|
57
|
+
@book.specify_cover_image(item) if File.basename(f) == @coverimg
|
58
|
+
}
|
59
|
+
}
|
60
|
+
@book.generate_epub(File.join(destbasedir, @epubname + '.epub'))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/gepub.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gepub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 2
|
9
|
-
version: 0.2.2
|
4
|
+
prerelease:
|
5
|
+
version: 0.3.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- KOJIMA Satoshi
|
@@ -14,8 +10,8 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
18
|
-
default_executable:
|
13
|
+
date: 2011-04-15 00:00:00 +09:00
|
14
|
+
default_executable: gepuber
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
21
17
|
name: libxml-ruby
|
@@ -24,10 +20,6 @@ dependencies:
|
|
24
20
|
requirements:
|
25
21
|
- - ">="
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 1
|
29
|
-
- 1
|
30
|
-
- 4
|
31
23
|
version: 1.1.4
|
32
24
|
type: :runtime
|
33
25
|
prerelease: false
|
@@ -39,10 +31,6 @@ dependencies:
|
|
39
31
|
requirements:
|
40
32
|
- - ">="
|
41
33
|
- !ruby/object:Gem::Version
|
42
|
-
segments:
|
43
|
-
- 0
|
44
|
-
- 9
|
45
|
-
- 4
|
46
34
|
version: 0.9.4
|
47
35
|
type: :runtime
|
48
36
|
prerelease: false
|
@@ -54,10 +42,6 @@ dependencies:
|
|
54
42
|
requirements:
|
55
43
|
- - ">="
|
56
44
|
- !ruby/object:Gem::Version
|
57
|
-
segments:
|
58
|
-
- 1
|
59
|
-
- 0
|
60
|
-
- 7
|
61
45
|
version: 1.0.7
|
62
46
|
type: :development
|
63
47
|
prerelease: false
|
@@ -69,8 +53,6 @@ dependencies:
|
|
69
53
|
requirements:
|
70
54
|
- - ">="
|
71
55
|
- !ruby/object:Gem::Version
|
72
|
-
segments:
|
73
|
-
- 2
|
74
56
|
version: "2"
|
75
57
|
type: :development
|
76
58
|
prerelease: false
|
@@ -82,10 +64,6 @@ dependencies:
|
|
82
64
|
requirements:
|
83
65
|
- - ">="
|
84
66
|
- !ruby/object:Gem::Version
|
85
|
-
segments:
|
86
|
-
- 0
|
87
|
-
- 1
|
88
|
-
- 0
|
89
67
|
version: 0.1.0
|
90
68
|
type: :development
|
91
69
|
prerelease: false
|
@@ -97,18 +75,14 @@ dependencies:
|
|
97
75
|
requirements:
|
98
76
|
- - ">="
|
99
77
|
- !ruby/object:Gem::Version
|
100
|
-
segments:
|
101
|
-
- 1
|
102
|
-
- 5
|
103
|
-
- 1
|
104
78
|
version: 1.5.1
|
105
79
|
type: :development
|
106
80
|
prerelease: false
|
107
81
|
version_requirements: *id006
|
108
82
|
description: an easy-to-use (and easy-to-implement) EPUB generator.
|
109
83
|
email: skoji@skoji.jp
|
110
|
-
executables:
|
111
|
-
|
84
|
+
executables:
|
85
|
+
- gepuber
|
112
86
|
extensions: []
|
113
87
|
|
114
88
|
extra_rdoc_files:
|
@@ -119,11 +93,13 @@ files:
|
|
119
93
|
- README.rdoc
|
120
94
|
- Rakefile
|
121
95
|
- VERSION
|
96
|
+
- bin/gepuber
|
122
97
|
- examples/example.rb
|
123
98
|
- gepub.gemspec
|
124
99
|
- lib/gepub.rb
|
125
100
|
- lib/gepub/book.rb
|
126
101
|
- lib/gepub/generator.rb
|
102
|
+
- lib/gepub/gepuber.rb
|
127
103
|
- lib/gepub/item.rb
|
128
104
|
- spec/gepub_spec.rb
|
129
105
|
- spec/spec_helper.rb
|
@@ -141,21 +117,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
117
|
requirements:
|
142
118
|
- - ">="
|
143
119
|
- !ruby/object:Gem::Version
|
144
|
-
segments:
|
145
|
-
- 0
|
146
120
|
version: "0"
|
147
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
122
|
none: false
|
149
123
|
requirements:
|
150
124
|
- - ">="
|
151
125
|
- !ruby/object:Gem::Version
|
152
|
-
segments:
|
153
|
-
- 0
|
154
126
|
version: "0"
|
155
127
|
requirements: []
|
156
128
|
|
157
129
|
rubyforge_project:
|
158
|
-
rubygems_version: 1.
|
130
|
+
rubygems_version: 1.5.2
|
159
131
|
signing_key:
|
160
132
|
specification_version: 3
|
161
133
|
summary: a good-enough EPUB generator.
|