sc2epub 0.0.2 → 0.0.3
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/CHANGES +6 -0
- data/bin/sc2epub +1 -248
- data/lib/sc2epub/converter.rb +129 -0
- data/lib/{cover.jpg → sc2epub/cover.jpg} +0 -0
- data/lib/sc2epub/main.rb +37 -0
- data/lib/sc2epub/template/container.tmpl +6 -0
- data/lib/sc2epub/template/index.tmpl +7 -0
- data/lib/sc2epub/template/makefile.tmpl +22 -0
- data/lib/sc2epub/template/ncx.tmpl +8 -0
- data/lib/sc2epub/template/opf.tmpl +32 -0
- data/lib/sc2epub/template/xhtml.tmpl +9 -0
- data/lib/sc2epub/template.rb +56 -0
- data/lib/sc2epub.rb +4 -1
- metadata +12 -3
data/CHANGES
CHANGED
data/bin/sc2epub
CHANGED
@@ -1,251 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'kconv'
|
4
|
-
require 'optparse'
|
5
|
-
require 'fileutils'
|
6
|
-
TEMPLATE = <<EOS
|
7
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
8
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
9
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja-JP" lang="ja-JP"><head><title>%(title)</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><head/><body>
|
10
|
-
<h1>%(title)</h1>
|
11
|
-
<pre>
|
12
|
-
%(body)
|
13
|
-
</pre>
|
14
|
-
</body>
|
15
|
-
</html>
|
16
|
-
EOS
|
17
|
-
TEMPLATE_INDEX = <<EOS
|
18
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
19
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
20
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja-JP" lang="ja-JP"><head><title>%(title)</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><head/><body>
|
21
|
-
<a name='#TOC' /><h1>INDEX</h1>
|
22
|
-
%(body)
|
23
|
-
</body>
|
24
|
-
</html>
|
25
|
-
EOS
|
26
|
-
TEMPLATE_LINK = <<EOS
|
27
|
-
<a href="%(url)">%(title)</a>
|
28
|
-
EOS
|
29
|
-
TEMPLATE_OPF = <<EOS
|
30
|
-
<?xml version="1.0" encoding="utf-8"?>
|
31
|
-
<package unique-identifier="uid">
|
32
|
-
<metadata>
|
33
|
-
<meta name="cover" content="cover" />
|
34
|
-
<dc-metadata xmlns:dc="http://purl.org/metadata/dublin_core"
|
35
|
-
xmlns:oebpackage="http://openebook.org/namespaces/oeb-package/1.0/">
|
36
|
-
<dc:Title>%(title)</dc:Title>
|
37
|
-
<dc:Language>ja</dc:Language>
|
38
|
-
<dc:Creator>%(author)</dc:Creator>
|
39
|
-
<dc:Description>..</dc:Description>
|
40
|
-
<dc:Date>%(date)</dc:Date>
|
41
|
-
</dc-metadata>
|
42
|
-
<x-metadata>
|
43
|
-
<output encoding="utf-8" content-type="text/x-oeb1-document">
|
44
|
-
</output>
|
45
|
-
</x-metadata>
|
46
|
-
</metadata>
|
47
|
-
<manifest>
|
48
|
-
<item id="index" media-type-"text/x-oeb1-document" href="index.html"></item>
|
49
|
-
%(items)
|
50
|
-
<item id="toc" media-type="application/x-dtbncx+xml" href="toc.ncx"></item>
|
51
|
-
<item id="cover" href="cover.jpg" media-type="image/jpeg" />
|
52
|
-
</manifest>
|
53
|
-
<spine toc="toc">
|
54
|
-
<itemref idref="index" />
|
55
|
-
</spine>
|
56
|
-
<tours></tours>
|
57
|
-
<guide>
|
58
|
-
<reference type="toc" title="Table of Contents" href="index.html"></reference>
|
59
|
-
<reference type="start" title="Table of Contents" href="index.html"></reference>
|
60
|
-
</guide>
|
61
|
-
</package>
|
62
|
-
EOS
|
63
|
-
TEMPLATE_ITEM = <<EOS
|
64
|
-
<item id="%(id)" media-type="text/x-oeb1-document" href="%(link)"></item>
|
65
|
-
EOS
|
66
|
-
TEMPLATE_NCX = <<EOS
|
67
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
68
|
-
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
|
69
|
-
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
|
70
|
-
<docTitle><text>%(title)</text></docTitle>
|
71
|
-
<navMap>
|
72
|
-
%(navitems)
|
73
|
-
</navMap>
|
74
|
-
</ncx>
|
75
|
-
EOS
|
76
|
-
TEMPLATE_NAVITEM = <<EOS
|
77
|
-
<navPoint id="%(id)" playOrder="%(order)">
|
78
|
-
<navLabel><text>%(title)</text></navLabel><content src="%(link)"/>
|
79
|
-
</navPoint>
|
80
|
-
EOS
|
81
|
-
TEMPLATE_MAKEFILE = <<EOS
|
82
|
-
PROJECT = %(title)
|
83
|
-
EPUB = $(PROJECT).epub
|
84
|
-
MOBI = $(PROJECT).mobi
|
85
|
-
KINDLEGEN = kindlegen
|
86
|
-
|
87
|
-
.PHONY: all
|
88
|
-
all: $(EPUB)
|
89
|
-
|
90
|
-
.PHONY: kindle
|
91
|
-
kindle: $(MOBI)
|
92
|
-
|
93
|
-
.PHONY: clean
|
94
|
-
clean:
|
95
|
-
\tfind ./ -name "*.epub" -exec rm {} \\;
|
96
|
-
\tfind ./ -name "*.mobi" -exec rm {} \\;
|
97
|
-
|
98
|
-
$(EPUB):
|
99
|
-
\tzip -Xr9D $(EPUB) mimetype META-INF toc.ncx $(PROJECT).opf
|
100
|
-
\tfind ./ -name "*.html" -o -name "*.jpg" | xargs zip -Xr9D $(EPUB)
|
101
|
-
|
102
|
-
$(MOBI): $(EPUB)
|
103
|
-
\t$(KINDLEGEN) $(EPUB)
|
104
|
-
EOS
|
105
|
-
$env = {}
|
106
|
-
def local path
|
107
|
-
if path.index($root)==0
|
108
|
-
path = path[$root.size, path.size]
|
109
|
-
end
|
110
|
-
if path[0,1] == "/"
|
111
|
-
path = path[1, path.size]
|
112
|
-
end
|
113
|
-
return path
|
114
|
-
end
|
115
|
-
def title path
|
116
|
-
path.gsub(/\//, "_").gsub(/\./, '_')
|
117
|
-
end
|
118
|
-
def dogenerate output, doctitle
|
119
|
-
indexhtml = ''
|
120
|
-
items = ''; c=0;
|
121
|
-
nvitems = ''
|
122
|
-
cover = File::join(File::dirname(__FILE__), '../lib/cover.jpg')
|
123
|
-
FileUtils::cp(cover, output)
|
124
|
-
$indexes.each do |data|
|
125
|
-
title = data[:name]
|
126
|
-
link = data[:src]
|
127
|
-
if data[:type]==:dir && data[:level]+2<=4
|
128
|
-
tagname = "h" + (data[:level]+2).to_s
|
129
|
-
else
|
130
|
-
tagname = 'p'
|
131
|
-
end
|
132
|
-
indexhtml += "<#{tagname}>" + dotemplate(TEMPLATE_LINK, 'url'=>link, 'title'=>title) + "</#{tagname}>\n"
|
133
|
-
if data[:type]==:file
|
134
|
-
items += dotemplate(TEMPLATE_ITEM, 'id'=>"item#{c+=1}", 'link'=>link)
|
135
|
-
nvitems += dotemplate(TEMPLATE_NAVITEM, 'id'=>"navPoint-#{c}", 'order'=>c.to_s, 'link'=>link, 'title'=>title)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
author = $env[:author]
|
139
|
-
indexhtml = dotemplate(TEMPLATE_INDEX, 'title'=>'index', 'body'=>indexhtml)
|
140
|
-
opf = dotemplate(TEMPLATE_OPF, 'title'=>doctitle, 'date'=>Time::now.strftime("%Y/%m/%d"), 'items'=>items, 'author'=>author)
|
141
|
-
ncx = dotemplate(TEMPLATE_NCX, 'title'=>doctitle, 'navitems'=>nvitems)
|
142
|
-
open(File::join(output, 'index.html'), 'w') do |io|
|
143
|
-
io.write(indexhtml)
|
144
|
-
end
|
145
|
-
opfpath = "#{doctitle}.opf"
|
146
|
-
open(File::join(output, opfpath), 'w') do |io|
|
147
|
-
io.write(opf)
|
148
|
-
end
|
149
|
-
open(File::join(output, 'toc.ncx'), 'w') do |io|
|
150
|
-
io.write(ncx)
|
151
|
-
end
|
152
|
-
Dir::mkdir(File::join(output, 'META-INF')) unless FileTest::exists? File::join(output, 'META-INF')
|
153
|
-
open(File::join(output, 'META-INF', 'container.xml'), 'w') do |io|
|
154
|
-
io.write <<EOS
|
155
|
-
<?xml version="1.0"?>
|
156
|
-
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
|
157
|
-
<rootfiles>
|
158
|
-
<rootfile full-path="#{opfpath}" media-type="application/oebps-package+xml"/>
|
159
|
-
</rootfiles>
|
160
|
-
</container>
|
161
|
-
EOS
|
162
|
-
end
|
163
|
-
open(File::join(output, 'mimetype'), 'w') do |io|
|
164
|
-
io.puts('application/epub+zip')
|
165
|
-
end
|
166
|
-
makefile = dotemplate(TEMPLATE_MAKEFILE, 'title'=>doctitle)
|
167
|
-
open(File::join(output, 'Makefile'), 'w') do |io|
|
168
|
-
io.write(makefile)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
def dotemplate template, params
|
172
|
-
t = template
|
173
|
-
for k,v in params
|
174
|
-
t = t.gsub(/%\(#{k}\)/, v)
|
175
|
-
end
|
176
|
-
t
|
177
|
-
end
|
178
|
-
def dofile path, output
|
179
|
-
s = open(path){|io|io.read}
|
180
|
-
return nil if Kconv::guess(s)==Kconv::BINARY
|
181
|
-
title = title(local(path))
|
182
|
-
s = dotemplate(TEMPLATE, 'title'=>local(path), 'body'=>s)
|
183
|
-
npath = title+".html"
|
184
|
-
if $dirstack.last and not $dirstack.last[:src]
|
185
|
-
$dirstack.last[:src] = npath
|
186
|
-
$indexes << $dirstack.last
|
187
|
-
end
|
188
|
-
open(File::join(output, npath), "w") do |io|
|
189
|
-
io.write(s)
|
190
|
-
end
|
191
|
-
level = $dirstack.empty? ? 1 : $dirstack.last[:level]+1
|
192
|
-
$indexes << {:src => npath, :name =>local(path), :type => :file, :level => level}
|
193
|
-
title
|
194
|
-
end
|
195
|
-
$dirstack = []
|
196
|
-
$indexes = []
|
197
|
-
def dodir dir, output
|
198
|
-
return [] if File::basename(dir)=~/^\..*/
|
199
|
-
$dirstack.push({:name =>local(dir), :src =>nil, :type => :dir, :level => $dirstack.size})
|
200
|
-
Dir::foreach(dir) do |i|
|
201
|
-
next if i=="."||i==".."
|
202
|
-
path = File::join(dir, i)
|
203
|
-
if FileTest::directory? path
|
204
|
-
dodir(path, output)
|
205
|
-
elsif FileTest::file? path
|
206
|
-
dofile(path, output)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
$dirstack.pop
|
210
|
-
end
|
211
|
-
def doroot dir, output
|
212
|
-
$root = dir
|
213
|
-
Dir::foreach(dir) do |i|
|
214
|
-
next if i=="."||i==".."
|
215
|
-
path = File::join(dir, i)
|
216
|
-
if FileTest::directory? path
|
217
|
-
dodir(path, output)
|
218
|
-
elsif FileTest::file? path
|
219
|
-
dofile(path, output)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
3
|
require 'sc2epub'
|
224
|
-
|
225
|
-
input = ARGV[0]
|
226
|
-
output = ARGV[1]
|
227
|
-
user = ENV['USER']
|
228
|
-
opts = OptionParser.new("Usage: #{File::basename($0)} SOME_DIR OUTPUT_DIR PROJECT_NAME")
|
229
|
-
opts.on("-v", "--version", "show version") do
|
230
|
-
puts "%s %s" %[File.basename($0), Sc2epub::VERSION]
|
231
|
-
puts "ruby %s" % RUBY_VERSION
|
232
|
-
exit
|
233
|
-
end
|
234
|
-
opts.on("-u", "--user", "set user name") do |v|
|
235
|
-
user = v
|
236
|
-
end
|
237
|
-
opts.on_tail("-h", "--help", "show this message") do
|
238
|
-
puts opts
|
239
|
-
exit
|
240
|
-
end
|
241
|
-
if ARGV.size < 3
|
242
|
-
puts opts
|
243
|
-
exit
|
244
|
-
end
|
245
|
-
|
246
|
-
$env[:author] = user
|
247
|
-
Dir::mkdir(output) unless FileTest::exists? output
|
248
|
-
doroot(input, output)
|
249
|
-
dogenerate(output, ARGV[2])
|
250
|
-
end
|
251
|
-
main
|
4
|
+
Sc2epub::Main::new.main
|
@@ -0,0 +1,129 @@
|
|
1
|
+
class Sc2epub::Converter
|
2
|
+
require 'kconv'
|
3
|
+
require 'fileutils'
|
4
|
+
def initialize env, root, output
|
5
|
+
@root = path(root)
|
6
|
+
@output = output
|
7
|
+
@template = Sc2epub::Template::new
|
8
|
+
@dirstack = []
|
9
|
+
@indexes = []
|
10
|
+
@env = env
|
11
|
+
end
|
12
|
+
def path path
|
13
|
+
r = File::expand_path(path)
|
14
|
+
end
|
15
|
+
def local path
|
16
|
+
if path.index(@root)==0
|
17
|
+
path = path[@root.size, path.size]
|
18
|
+
end
|
19
|
+
if path[0,1] == "/"
|
20
|
+
path = path[1, path.size]
|
21
|
+
end
|
22
|
+
return path
|
23
|
+
end
|
24
|
+
def title path
|
25
|
+
path.gsub(/\//, "_").gsub(/\./, '_')
|
26
|
+
end
|
27
|
+
def dogenerate doctitle
|
28
|
+
output = @output
|
29
|
+
indexhtml = ''
|
30
|
+
items = ''; c=0;
|
31
|
+
nvitems = ''
|
32
|
+
cover = File::join(File::dirname(__FILE__), 'cover.jpg')
|
33
|
+
FileUtils::cp(cover, output)
|
34
|
+
@indexes.each do |data|
|
35
|
+
title = data[:name]
|
36
|
+
link = data[:src]
|
37
|
+
if data[:type]==:dir && data[:level]+2<=4
|
38
|
+
tagname = "h" + (data[:level]+2).to_s
|
39
|
+
else
|
40
|
+
tagname = 'p'
|
41
|
+
end
|
42
|
+
indexhtml += "<#{tagname}>" + @template.link('url'=>link, 'title'=>title) + "</#{tagname}>\n"
|
43
|
+
if data[:type]==:file
|
44
|
+
items += @template.item('id'=>"item#{c+=1}", 'link'=>link)
|
45
|
+
nvitems += @template.navi('id'=>"navPoint-#{c}", 'order'=>c.to_s, 'link'=>link, 'title'=>title)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
indexhtml = @template.index('title'=>'index', 'body'=>indexhtml)
|
49
|
+
opf = @template.opf('title'=>doctitle, 'date'=>Time::now.strftime("%Y/%m/%d"),
|
50
|
+
'lang' => @env[:lang],
|
51
|
+
'items'=>items, 'author'=>@env[:author])
|
52
|
+
ncx = @template.ncx('title'=>doctitle, 'navitems'=>nvitems)
|
53
|
+
open(File::join(output, 'index.html'), 'w') do |io|
|
54
|
+
io.write(indexhtml)
|
55
|
+
end
|
56
|
+
opfpath = "#{doctitle}.opf"
|
57
|
+
open(File::join(output, opfpath), 'w') do |io|
|
58
|
+
io.write(opf)
|
59
|
+
end
|
60
|
+
open(File::join(output, 'toc.ncx'), 'w') do |io|
|
61
|
+
io.write(ncx)
|
62
|
+
end
|
63
|
+
Dir::mkdir(File::join(output, 'META-INF')) unless FileTest::exists? File::join(output, 'META-INF')
|
64
|
+
open(File::join(output, 'META-INF', 'container.xml'), 'w') do |io|
|
65
|
+
io.write(@template.container('opfpath'=>opfpath))
|
66
|
+
end
|
67
|
+
open(File::join(output, 'mimetype'), 'w') do |io|
|
68
|
+
io.puts('application/epub+zip')
|
69
|
+
end
|
70
|
+
makefile = @template.makefile('title'=>doctitle)
|
71
|
+
open(File::join(output, 'Makefile'), 'w') do |io|
|
72
|
+
io.write(makefile)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
def dofile path
|
76
|
+
if File::extname(path) == '.html' or File::extname(path) == '.xhtml'
|
77
|
+
FileUtils::cp(path, @output)
|
78
|
+
return
|
79
|
+
end
|
80
|
+
output = @output
|
81
|
+
s = open(path){|io|io.read}
|
82
|
+
enc = Kconv::guess(s)
|
83
|
+
if enc==Kconv::BINARY
|
84
|
+
return nil
|
85
|
+
elsif enc!=Kconv::UTF8
|
86
|
+
s = s.toutf8
|
87
|
+
end
|
88
|
+
title = title(local(path))
|
89
|
+
s = @template.xhtml('title'=>local(path), 'body'=>s)
|
90
|
+
npath = title+".html"
|
91
|
+
if @dirstack.last and not @dirstack.last[:src]
|
92
|
+
@dirstack.last[:src] = npath
|
93
|
+
@indexes << @dirstack.last
|
94
|
+
end
|
95
|
+
open(File::join(output, npath), "w") do |io|
|
96
|
+
io.write(s)
|
97
|
+
end
|
98
|
+
level = @dirstack.empty? ? 1 : @dirstack.last[:level]+1
|
99
|
+
@indexes << {:src => npath, :name =>local(path), :type => :file, :level => level}
|
100
|
+
title
|
101
|
+
end
|
102
|
+
def dodir dir
|
103
|
+
return [] if File::basename(dir)=~/^\..*/
|
104
|
+
@dirstack.push({:name =>local(dir), :src =>nil,
|
105
|
+
:type => :dir, :level => @dirstack.size})
|
106
|
+
Dir::foreach(dir) do |i|
|
107
|
+
next if i=="."||i==".."
|
108
|
+
path = File::join(dir, i)
|
109
|
+
if FileTest::directory? path
|
110
|
+
dodir(path)
|
111
|
+
elsif FileTest::file? path
|
112
|
+
dofile(path)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
@dirstack.pop
|
116
|
+
end
|
117
|
+
def doroot dir
|
118
|
+
dir = path(dir)
|
119
|
+
Dir::foreach(dir) do |i|
|
120
|
+
next if i=="."||i==".."
|
121
|
+
path = File::join(dir, i)
|
122
|
+
if FileTest::directory? path
|
123
|
+
dodir(path)
|
124
|
+
elsif FileTest::file? path
|
125
|
+
dofile(path)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
File without changes
|
data/lib/sc2epub/main.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
class Sc2epub::Main
|
2
|
+
require 'optparse'
|
3
|
+
def main
|
4
|
+
input = ARGV[0]
|
5
|
+
output = ARGV[1]
|
6
|
+
opts = OptionParser.new("Usage: #{File::basename($0)} SOME_DIR OUTPUT_DIR PROJECT_NAME")
|
7
|
+
opts.on("-v", "--version", "show version") do
|
8
|
+
puts "%s %s" %[File.basename($0), Sc2epub::VERSION]
|
9
|
+
puts "ruby %s" % RUBY_VERSION
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
opts.on("-u", "--user", "set user name") do |v|
|
13
|
+
user = v
|
14
|
+
end
|
15
|
+
lang = 'ja'
|
16
|
+
opts.on('-l', '--lang', 'set language') do |v|
|
17
|
+
lang = v
|
18
|
+
end
|
19
|
+
opts.on_tail("-h", "--help", "show this message") do
|
20
|
+
puts opts
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
if ARGV.size < 3
|
24
|
+
puts opts
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
user = ENV['USER']
|
28
|
+
env = {
|
29
|
+
:author => user,
|
30
|
+
:lang => lang
|
31
|
+
}
|
32
|
+
Dir::mkdir(output) unless FileTest::exists? output
|
33
|
+
@converter = Sc2epub::Converter::new(env, input, output)
|
34
|
+
@converter.doroot(input)
|
35
|
+
@converter.dogenerate(ARGV[2])
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja-JP" lang="ja-JP"><head><title>%(title)</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><head/><body>
|
4
|
+
<a name='#TOC' /><h1>INDEX</h1>
|
5
|
+
%(body)
|
6
|
+
</body>
|
7
|
+
</html>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
PROJECT = %(title)
|
2
|
+
EPUB = $(PROJECT).epub
|
3
|
+
MOBI = $(PROJECT).mobi
|
4
|
+
KINDLEGEN = kindlegen
|
5
|
+
|
6
|
+
.PHONY: all
|
7
|
+
all: $(EPUB)
|
8
|
+
|
9
|
+
.PHONY: kindle
|
10
|
+
kindle: $(MOBI)
|
11
|
+
|
12
|
+
.PHONY: clean
|
13
|
+
clean:
|
14
|
+
find ./ -name "*.epub" -exec rm {} \\;
|
15
|
+
find ./ -name "*.mobi" -exec rm {} \\;
|
16
|
+
|
17
|
+
$(EPUB):
|
18
|
+
zip -Xr9D $(EPUB) mimetype META-INF toc.ncx $(PROJECT).opf
|
19
|
+
find ./ -name "*.html" -o -name "*.jpg" | xargs zip -Xr9D $(EPUB)
|
20
|
+
|
21
|
+
$(MOBI): $(EPUB)
|
22
|
+
$(KINDLEGEN) $(EPUB)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
|
3
|
+
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
|
4
|
+
<docTitle><text>%(title)</text></docTitle>
|
5
|
+
<navMap>
|
6
|
+
%(navitems)
|
7
|
+
</navMap>
|
8
|
+
</ncx>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<package unique-identifier="uid">
|
3
|
+
<metadata>
|
4
|
+
<meta name="cover" content="cover" />
|
5
|
+
<dc-metadata xmlns:dc="http://purl.org/metadata/dublin_core"
|
6
|
+
xmlns:oebpackage="http://openebook.org/namespaces/oeb-package/1.0/">
|
7
|
+
<dc:Title>%(title)</dc:Title>
|
8
|
+
<dc:Language>%(lang)</dc:Language>
|
9
|
+
<dc:Creator>%(author)</dc:Creator>
|
10
|
+
<dc:Description>..</dc:Description>
|
11
|
+
<dc:Date>%(date)</dc:Date>
|
12
|
+
</dc-metadata>
|
13
|
+
<x-metadata>
|
14
|
+
<output encoding="utf-8" content-type="text/x-oeb1-document">
|
15
|
+
</output>
|
16
|
+
</x-metadata>
|
17
|
+
</metadata>
|
18
|
+
<manifest>
|
19
|
+
<item id="index" media-type-"text/x-oeb1-document" href="index.html"></item>
|
20
|
+
%(items)
|
21
|
+
<item id="toc" media-type="application/x-dtbncx+xml" href="toc.ncx"></item>
|
22
|
+
<item id="cover" href="cover.jpg" media-type="image/jpeg" />
|
23
|
+
</manifest>
|
24
|
+
<spine toc="toc">
|
25
|
+
<itemref idref="index" />
|
26
|
+
</spine>
|
27
|
+
<tours></tours>
|
28
|
+
<guide>
|
29
|
+
<reference type="toc" title="Table of Contents" href="index.html"></reference>
|
30
|
+
<reference type="start" title="Table of Contents" href="index.html"></reference>
|
31
|
+
</guide>
|
32
|
+
</package>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja-JP" lang="ja-JP"><head><title>%(title)</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><head/><body>
|
4
|
+
<h1>%(title)</h1>
|
5
|
+
<pre>
|
6
|
+
%(body)
|
7
|
+
</pre>
|
8
|
+
</body>
|
9
|
+
</html>
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class Sc2epub::Template
|
2
|
+
TEMPLATE_MAKEFILE = 'makefile.tmpl'
|
3
|
+
TEMPLATE_OPF = 'opf.tmpl'
|
4
|
+
TEMPLATE_NCX = 'ncx.tmpl'
|
5
|
+
TEMPLATE_XHTML = 'xhtml.tmpl'
|
6
|
+
TEMPLATE_INDEX = 'index.tmpl'
|
7
|
+
TEMPLATE_LINK = "<a href=\"%(url)\">%(title)</a>"
|
8
|
+
TEMPLATE_NAVITEM = <<EOS
|
9
|
+
<navPoint id="%(id)" playOrder="%(order)">
|
10
|
+
<navLabel><text>%(title)</text></navLabel><content src="%(link)"/>
|
11
|
+
</navPoint>
|
12
|
+
EOS
|
13
|
+
TEMPLATE_ITEM = "<item id=\"%(id)\" media-type=\"text/x-oeb1-document\" href=\"%(link)\"></item>"
|
14
|
+
TEMPLATE_CONTAINER = 'container.tmpl'
|
15
|
+
def initialize
|
16
|
+
@dir = File::join(File::dirname(__FILE__), 'template')
|
17
|
+
end
|
18
|
+
def container params
|
19
|
+
dotemplate TEMPLATE_CONTAINER, params
|
20
|
+
end
|
21
|
+
def link params
|
22
|
+
dotemplate TEMPLATE_LINK, params
|
23
|
+
end
|
24
|
+
def item params
|
25
|
+
dotemplate TEMPLATE_ITEM, params
|
26
|
+
end
|
27
|
+
def navi params
|
28
|
+
dotemplate TEMPLATE_NAVITEM, params
|
29
|
+
end
|
30
|
+
def index params
|
31
|
+
dotemplate TEMPLATE_INDEX, params
|
32
|
+
end
|
33
|
+
def opf params
|
34
|
+
dotemplate TEMPLATE_OPF, params
|
35
|
+
end
|
36
|
+
def ncx params
|
37
|
+
dotemplate TEMPLATE_NCX, params
|
38
|
+
end
|
39
|
+
def makefile params
|
40
|
+
dotemplate TEMPLATE_MAKEFILE, params
|
41
|
+
end
|
42
|
+
def xhtml params
|
43
|
+
dotemplate TEMPLATE_XHTML, params
|
44
|
+
end
|
45
|
+
def dotemplate template, params
|
46
|
+
if template.rindex('.tmpl')
|
47
|
+
t = open(File::join(@dir, template)){|io|io.read}
|
48
|
+
else
|
49
|
+
t = template
|
50
|
+
end
|
51
|
+
for k,v in params
|
52
|
+
t = t.gsub(/%\(#{k}\)/, v)
|
53
|
+
end
|
54
|
+
t
|
55
|
+
end
|
56
|
+
end
|
data/lib/sc2epub.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- takada-at
|
@@ -29,8 +29,17 @@ extensions: []
|
|
29
29
|
extra_rdoc_files: []
|
30
30
|
|
31
31
|
files:
|
32
|
-
- lib/cover.jpg
|
33
32
|
- lib/sc2epub.rb
|
33
|
+
- lib/sc2epub/template/makefile.tmpl
|
34
|
+
- lib/sc2epub/template/xhtml.tmpl
|
35
|
+
- lib/sc2epub/template/opf.tmpl
|
36
|
+
- lib/sc2epub/template/ncx.tmpl
|
37
|
+
- lib/sc2epub/template/index.tmpl
|
38
|
+
- lib/sc2epub/template/container.tmpl
|
39
|
+
- lib/sc2epub/cover.jpg
|
40
|
+
- lib/sc2epub/template.rb
|
41
|
+
- lib/sc2epub/converter.rb
|
42
|
+
- lib/sc2epub/main.rb
|
34
43
|
- bin/sc2epub
|
35
44
|
- sc2epub.gemspec
|
36
45
|
- README
|