Class: Elibrum::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/elibrum/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename, formats, template = default_template, &block) ⇒ Builder

Returns a new instance of Builder.



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/elibrum/builder.rb', line 3

def initialize(filename, formats, template=default_template, &block)
	raise "Elibrum::EBOOK_CONVERT_PATH is not defined. Put the path to ebook-convert in this constant." unless defined?(EBOOK_CONVERT_PATH)
	
	FileUtils.mkdir(".images-temp") unless File.directory?(".images-temp")
	@book = Book.new(filename, &block)
	@template = template

	[*formats].each do |format|
		build(filename, format)
	end

	FileUtils.rm_rf(".images-temp")
end

Instance Method Details

#build(filename, format) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/elibrum/builder.rb', line 17

def build(filename, format)
	# Create an HTML file to use as the source file for conversion
	File.open(".#{filename}-temp.html", "w+") {|f| f.write(html)}
	# Documentation for ebook-convert can be found here: http://manual.calibre-ebook.com/cli/ebook-convert.html
	`#{EBOOK_CONVERT_PATH} .#{filename}-temp.html #{filename}.#{format} --title "#{@book.title}" --authors "#{@book.author}" --chapter "//h:pagebreak"`
	FileUtils.rm(filename + "-temp.html")
end