Array of content objects.
Parameter hash.
Message resource object.
Take YAML file
and return parameter hash.
# File ../../../../../lib/epubmaker/producer.rb, line 30 def Producer.load(file) raise "Can't open #{yamlfile}." if file.nil? || !File.exist?(file) return YAML.load_file(file) end
Construct producer object. params
takes initial parameter
hash. This parameters can be overriden by EPUBMaker#load or
EPUBMaker#merge_params. version
takes EPUB version (default is
2).
# File ../../../../../lib/epubmaker/producer.rb, line 44 def initialize(params=nil, version=nil) @contents = [] @params = {} @epub = nil @params["epubversion"] = version unless version.nil? @res = ReVIEW::I18n unless params.nil? merge_params(params) end end
# File ../../../../../lib/epubmaker/producer.rb, line 184 def call_hook(filename, *params) if !filename.nil? && File.exist?(filename) && FileTest.executable?(filename) if ENV["REVIEW_SAFE_MODE"].to_i & 1 > 0 warn "hook is prohibited in safe mode. ignored." else system(filename, *params) end end end
Write colophon file to IO object wobj
.
# File ../../../../../lib/epubmaker/producer.rb, line 130 def colophon(wobj) s = @epub.colophon wobj.puts s if !s.nil? && !wobj.nil? end
Write container file to IO object wobj
.
# File ../../../../../lib/epubmaker/producer.rb, line 109 def container(wobj) s = @epub.container wobj.puts s if !s.nil? && !wobj.nil? end
Write cover file to IO object wobj
. If #params is defined, it will be
used for the cover image.
# File ../../../../../lib/epubmaker/producer.rb, line 117 def cover(wobj) type = (@params["epubversion"] >= 3) ? "cover" : nil s = @epub.cover(type) wobj.puts s if !s.nil? && !wobj.nil? end
# File ../../../../../lib/epubmaker/producer.rb, line 56 def coverimage if !params["coverimage"] return nil end @contents.each do |item| if item.media =~ /\Aimage/ && item.file =~ /#{params["coverimage"]}\Z/ # / return item.file end end return nil end
Add informations of figure files in path
to contents array.
base
defines a string to remove from path name.
# File ../../../../../lib/epubmaker/producer.rb, line 143 def import_imageinfo(path, base=nil, allow_exts=nil) return nil unless File.exist?(path) allow_exts = @params["image_ext"] if allow_exts.nil? Dir.foreach(path) do |f| next if f =~ /\A\./ if f =~ /\.(#{allow_exts.join("|")})\Z/ path.chop! if path =~ /\/\Z/ if base.nil? @contents.push(EPUBMaker::Content.new({"file" => "#{path}/#{f}"})) else @contents.push(EPUBMaker::Content.new({"file" => "#{path.sub(base + "/", '')}/#{f}"})) end end if FileTest.directory?("#{path}/#{f}") import_imageinfo("#{path}/#{f}", base) end end end
Take YAML file
and update parameter hash.
# File ../../../../../lib/epubmaker/producer.rb, line 36 def load(file) raise "Can't open #{yamlfile}." if file.nil? || !File.exist?(file) merge_params(@params.merge(YAML.load_file(file))) end
Update parameters by merging from new parameter hash params
.
# File ../../../../../lib/epubmaker/producer.rb, line 69 def merge_params(params) @params = @params.merge(params) complement unless @params["epubversion"].nil? case @params["epubversion"].to_i when 2 @epub = EPUBMaker::EPUBv2.new(self) when 3 @epub = EPUBMaker::EPUBv3.new(self) else raise "Invalid EPUB version (#{@params["epubversion"]}.)" end end if params["language"] ReVIEW::I18n.locale = params["language"] end support_legacy_maker end
Write mimetype file to IO object wobj
.
# File ../../../../../lib/epubmaker/producer.rb, line 90 def mimetype(wobj) s = @epub.mimetype wobj.print s if !s.nil? && !wobj.nil? end
Write own toc file to IO object wobj
.
# File ../../../../../lib/epubmaker/producer.rb, line 136 def mytoc(wobj) s = @epub.mytoc wobj.puts s if !s.nil? && !wobj.nil? end
Write ncx file to IO object wobj
. indentarray
defines prefix string for each level.
# File ../../../../../lib/epubmaker/producer.rb, line 103 def ncx(wobj, indentarray=[]) s = @epub.ncx(indentarray) wobj.puts s if !s.nil? && !wobj.nil? end
Write opf file to IO object wobj
.
# File ../../../../../lib/epubmaker/producer.rb, line 96 def opf(wobj) s = @epub.opf wobj.puts s if !s.nil? && !wobj.nil? end
Produce EPUB file epubfile
. basedir
points the
directory has contents (default: current directory.) tmpdir
defines temporary directory.
# File ../../../../../lib/epubmaker/producer.rb, line 167 def produce(epubfile, basedir=nil, tmpdir=nil) current = Dir.pwd basedir = current if basedir.nil? _tmpdir = tmpdir.nil? ? Dir.mktmpdir : tmpdir epubfile = "#{current}/#{epubfile}" if epubfile !~ /\A\// # / # FIXME: error check File.unlink(epubfile) if File.exist?(epubfile) begin @epub.produce(epubfile, basedir, _tmpdir) ensure FileUtils.rm_r(_tmpdir) if tmpdir.nil? end end
Write title file (copying) to IO object wobj
.
# File ../../../../../lib/epubmaker/producer.rb, line 124 def titlepage(wobj) s = @epub.titlepage wobj.puts s if !s.nil? && !wobj.nil? end