epubforge 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/config/actions/kindle.rb +1 -1
- data/lib/core_extensions/string.rb +0 -1
- data/lib/epub/assets/asset.rb +4 -0
- data/lib/epub/assets/font.rb +21 -0
- data/lib/epub/assets/image.rb +9 -1
- data/lib/epub/assets/page.rb +6 -12
- data/lib/epub/assets/stylesheet.rb +4 -0
- data/lib/epub/builder.rb +34 -28
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.9
|
data/config/actions/kindle.rb
CHANGED
@@ -23,7 +23,7 @@ module EpubForge
|
|
23
23
|
return false unless fulfill_requirements
|
24
24
|
|
25
25
|
say "converting from #{@src_epub} to #{@dst_mobi}"
|
26
|
-
cmd = "ebook-convert #{@src_epub} #{@dst_mobi}"
|
26
|
+
cmd = "ebook-convert --no-default-epub-cover #{@src_epub} #{@dst_mobi}"
|
27
27
|
say "executing: #{cmd}"
|
28
28
|
`#{cmd}`
|
29
29
|
|
@@ -15,7 +15,6 @@ class String
|
|
15
15
|
def epf_titlecap_words
|
16
16
|
nocaps = %w(a and at be but in is nor of or so teh the to with)
|
17
17
|
upcase = %w(Ii Ii: Iii M.d.) # TODO: ick
|
18
|
-
debugger if self.match( /ii/i )
|
19
18
|
|
20
19
|
words = self.downcase.gsub(/\u00a0/, ' ').split(/(\s|\n)+/).map(&:strip).delete_if(&:epf_blank?)
|
21
20
|
first_word = true
|
data/lib/epub/assets/asset.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
module EpubForge
|
2
|
+
module Epub
|
3
|
+
module Assets
|
4
|
+
class Font < Asset
|
5
|
+
attr_reader :ext, :filename, :name
|
6
|
+
def initialize( filename, options = {} )
|
7
|
+
@filename = filename.fwf_filepath
|
8
|
+
@name, @ext = @filename.basename_and_ext
|
9
|
+
end
|
10
|
+
|
11
|
+
def link
|
12
|
+
FONT_DIR.join( @filename.basename.to_s )
|
13
|
+
end
|
14
|
+
|
15
|
+
def item_id
|
16
|
+
@filename.basename.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/epub/assets/image.rb
CHANGED
@@ -9,7 +9,15 @@ module EpubForge
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def link
|
12
|
-
|
12
|
+
IMAGE_DIR.join( "#{@name}.#{@ext}" )
|
13
|
+
end
|
14
|
+
|
15
|
+
def item_id
|
16
|
+
cover? ? "cover-image" : self.link.basename
|
17
|
+
end
|
18
|
+
|
19
|
+
def cover?
|
20
|
+
self.name == "cover"
|
13
21
|
end
|
14
22
|
end
|
15
23
|
end
|
data/lib/epub/assets/page.rb
CHANGED
@@ -44,22 +44,16 @@ module EpubForge
|
|
44
44
|
TEXT_DIR.join( "#{@section_id}.#{@dest_extension}" )
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
48
|
-
|
47
|
+
def item_id
|
48
|
+
cover? ? "cover" : self.link.basename
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
52
|
-
|
53
|
-
@cover = val
|
54
|
-
end
|
55
|
-
@cover
|
51
|
+
def media_type
|
52
|
+
MEDIA_TYPES[@dest_extension]
|
56
53
|
end
|
57
54
|
|
58
|
-
def
|
59
|
-
|
60
|
-
@cover = val
|
61
|
-
end
|
62
|
-
@cover
|
55
|
+
def cover?
|
56
|
+
@section_id == "cover"
|
63
57
|
end
|
64
58
|
end
|
65
59
|
end
|
data/lib/epub/builder.rb
CHANGED
@@ -5,16 +5,18 @@ module EpubForge
|
|
5
5
|
module Epub
|
6
6
|
PAGE_FILE_EXTENSIONS = %w(html markdown textile xhtml)
|
7
7
|
IMAGE_FILE_EXTENSIONS = %w(jpg png gif)
|
8
|
+
FONT_FILE_EXTENSION = %w(ttf otf)
|
8
9
|
|
9
10
|
MEDIA_TYPES = { "gif" => "image/gif", "jpg" => "image/jpeg", "png" => "image/png",
|
10
11
|
"css" => "text/css", "js" => "application/javascript", "pdf" => "application/pdf",
|
11
|
-
"txt" => "text/plain", "xhtml" => "application/xhtml+xml"
|
12
|
+
"txt" => "text/plain", "xhtml" => "application/xhtml+xml",
|
13
|
+
"ttf" => "application/x-font-ttf", "otf" => "application/x-font-opentype"
|
12
14
|
}
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
IMAGE_DIR, STYLE_DIR, TEXT_DIR, FONT_DIR = %w(Images Styles Text Fonts).map{ |dir|
|
17
|
+
"/".fwf_filepath.join("OEBPS", dir)
|
18
|
+
}
|
19
|
+
|
18
20
|
class Builder
|
19
21
|
attr_reader :stylesheets
|
20
22
|
|
@@ -56,6 +58,10 @@ module EpubForge
|
|
56
58
|
@stylesheets = @book_dir.glob( "stylesheets", "*.css" ).map do |sheet|
|
57
59
|
Assets::Stylesheet.new( sheet )
|
58
60
|
end
|
61
|
+
|
62
|
+
@fonts = @book_dir.glob( "fonts", ext: FONT_FILE_EXTENSION ).map do |font|
|
63
|
+
Assets::Font.new( font )
|
64
|
+
end
|
59
65
|
|
60
66
|
install_cover
|
61
67
|
|
@@ -64,15 +70,15 @@ module EpubForge
|
|
64
70
|
|
65
71
|
def install_cover
|
66
72
|
# Existing cover is moved to the very front
|
67
|
-
if cover_section = @sections.detect
|
68
|
-
|
69
|
-
elsif cover_image = @images.
|
73
|
+
if @cover_section = @sections.detect(&:cover?)
|
74
|
+
# no need to do anything
|
75
|
+
elsif @cover_image = @images.detect(&:cover?)
|
70
76
|
# actually install cover
|
71
|
-
contents = "<div id='cover'><img class='cover' src='#{cover_image.link.relative_path_from(TEXT_DIR)}' alt='#{@metadata.name}, by #{@metadata.author}'/></div>"
|
77
|
+
contents = "<div id='cover'><img class='cover' src='#{@cover_image.link.relative_path_from(TEXT_DIR)}' alt='#{@metadata.name}, by #{@metadata.author}'/></div>"
|
72
78
|
cover_file = @project.book_dir.join( "cover.xhtml" )
|
73
79
|
cover_file.write( wrap_page( contents ) )
|
74
|
-
cover_section = Assets::Page.new( cover_file, @metadata, @project )
|
75
|
-
@sections.unshift( cover_section )
|
80
|
+
@cover_section = Assets::Page.new( cover_file, @metadata, @project )
|
81
|
+
@sections.unshift( @cover_section )
|
76
82
|
puts "cover page generated"
|
77
83
|
else
|
78
84
|
return false
|
@@ -181,8 +187,8 @@ module EpubForge
|
|
181
187
|
b.dc :date, {:"opf:event" => "epub-publication"}, @metadata["epub-publication"] || Time.now.year
|
182
188
|
|
183
189
|
|
184
|
-
if @
|
185
|
-
b.meta :name => "cover", :content =>
|
190
|
+
if @cover_section
|
191
|
+
b.meta :name => "cover", :content => "cover"
|
186
192
|
end
|
187
193
|
end
|
188
194
|
|
@@ -190,24 +196,16 @@ module EpubForge
|
|
190
196
|
b.manifest do
|
191
197
|
# <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
|
192
198
|
b.item :id => "ncx", :href => "toc.ncx", :"media-type" => "application/x-dtbncx+xml"
|
193
|
-
|
194
|
-
@sections.each_with_index do |section, i|
|
195
|
-
b.item :id => section.link.basename, :href => section.link.relative_path_from("/OEBPS"), :"media-type" => section.media_type
|
196
|
-
end
|
197
|
-
|
198
|
-
@images.each do |image|
|
199
|
-
b.item :id => image.filename.basename, :href => image.link.relative_path_from("/OEBPS"), :"media-type" => image.media_type
|
200
|
-
end
|
201
199
|
|
202
|
-
@stylesheets.each do |
|
203
|
-
b.item :id =>
|
200
|
+
[@sections, @images, @stylesheets, @fonts].flatten.each do |asset|
|
201
|
+
b.item :id => asset.item_id, :href => asset.link.relative_path_from("/OEBPS"), :"media-type" => asset.media_type
|
204
202
|
end
|
205
203
|
end
|
206
204
|
|
207
205
|
# <spine toc="ncx">
|
208
206
|
b.spine :toc => "ncx" do
|
209
207
|
@sections.each do |section|
|
210
|
-
b.itemref :idref => section.
|
208
|
+
b.itemref :idref => section.item_id
|
211
209
|
end
|
212
210
|
end
|
213
211
|
|
@@ -246,7 +244,7 @@ module EpubForge
|
|
246
244
|
end
|
247
245
|
end
|
248
246
|
|
249
|
-
|
247
|
+
unless @images.epf_blank?
|
250
248
|
build.dir "Images" do
|
251
249
|
for img in @images
|
252
250
|
build.copy( img.filename )
|
@@ -261,6 +259,14 @@ module EpubForge
|
|
261
259
|
end
|
262
260
|
end
|
263
261
|
end
|
262
|
+
|
263
|
+
unless @fonts.epf_blank?
|
264
|
+
build.dir "Fonts" do
|
265
|
+
for font in @fonts
|
266
|
+
build.copy( font.filename )
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
264
270
|
end
|
265
271
|
end
|
266
272
|
end
|
@@ -268,11 +274,11 @@ module EpubForge
|
|
268
274
|
def package epub_filename
|
269
275
|
Packager.new( @scratch_dir, epub_filename ).package
|
270
276
|
end
|
271
|
-
|
277
|
+
|
272
278
|
def clean
|
273
|
-
#
|
279
|
+
# do nothing
|
274
280
|
end
|
275
|
-
|
281
|
+
|
276
282
|
protected
|
277
283
|
def wrap_page content = ""
|
278
284
|
b = XmlBuilder::XmlMarkup.new( :indent => 2)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epubforge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -244,6 +244,7 @@ files:
|
|
244
244
|
- ./lib/core_extensions/string.rb
|
245
245
|
- ./lib/custom_helpers.rb
|
246
246
|
- ./lib/epub/assets/asset.rb
|
247
|
+
- ./lib/epub/assets/font.rb
|
247
248
|
- ./lib/epub/assets/html.rb
|
248
249
|
- ./lib/epub/assets/image.rb
|
249
250
|
- ./lib/epub/assets/markdown.rb
|
@@ -316,7 +317,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
316
317
|
version: '0'
|
317
318
|
segments:
|
318
319
|
- 0
|
319
|
-
hash:
|
320
|
+
hash: -2032858985098992460
|
320
321
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
321
322
|
none: false
|
322
323
|
requirements:
|