lib/softcover/builders/epub.rb in softcover-0.9.23 vs lib/softcover/builders/epub.rb in softcover-1.0.beta1
- old
+ new
@@ -1,9 +1,37 @@
module Softcover
+
+ module EpubUtils
+
+ # Returns the name of the cover file.
+ # We support (in order) JPG/JPEG, PNG, and TIFF.
+ def cover_img
+ extensions = %w[jpg jpeg png tiff]
+ extensions.each do |ext|
+ file = Dir[path("#{images_dir}/cover.#{ext}")].first
+ return File.basename(file) if file
+ end
+ return false
+ end
+
+ def cover?
+ cover_img
+ end
+
+ def cover_img_path
+ path("#{images_dir}/#{cover_img}")
+ end
+
+ def images_dir
+ path('epub/OEBPS/images')
+ end
+ end
+
module Builders
class Epub < Builder
include Softcover::Output
+ include Softcover::EpubUtils
def build!(options={})
@preview = options[:preview]
Softcover::Builders::Html.new.build!
if manifest.markdown?
@@ -119,14 +147,10 @@
FileUtils.rm(f)
end
end
end
- def images_dir
- File.join('epub', 'OEBPS', 'images')
- end
-
# Returns HTML for HTML source that includes math.
# As a side-effect, html_with_math creates PNGs corresponding to any
# math in the given source. The technique involves using PhantomJS to
# hit the HTML source for each page containing math to create SVGs
# for every math element. Since ereader support for SVGs is spotty,
@@ -396,26 +420,11 @@
</body>
</html>
)
end
- # Returns the name of the cover file.
- # We support (in order) JPG/JPEG, PNG, and TIFF.
- def cover_img
- extensions = %w[jpg jpeg png tiff]
- extensions.each do |ext|
- file = Dir[path("#{images_dir}/cover.#{ext}")].first
- return File.basename(file) if file
- end
- return false
- end
-
def cover_id
"img-#{cover_img.sub('.', '-')}"
- end
-
- def cover?
- cover_img
end
# Returns the Table of Contents for the spine.
def toc_ncx
title = manifest.title
\ No newline at end of file