Parameter hash.
Array of content objects.
Message resource object.
Take YAML file
and return parameter hash.
# File ../../../../../lib/epubmaker/producer.rb, line 31 def self.load(file) raise "Can't open #{file}." if file.nil? || !File.exist?(file) loader = ReVIEW::YAMLLoader.new loader.load_file(file) end
Construct producer object. config
takes initial parameter
hash. This parameters can be overriden by EPUBMaker#load or
EPUBMaker#merge_config. version
takes EPUB version (default is
2).
# File ../../../../../lib/epubmaker/producer.rb, line 47 def initialize(config = nil, version = nil) @contents = [] @config = ReVIEW::Configure.new @epub = nil @config['epubversion'] = version unless version.nil? @res = ReVIEW::I18n merge_config(config) if config end
# File ../../../../../lib/epubmaker/producer.rb, line 179 def call_hook(filename, *params) return if !filename.present? || !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
Write colophon file to IO object wobj
.
# File ../../../../../lib/epubmaker/producer.rb, line 127 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 106 def container(wobj) s = @epub.container wobj.puts s if !s.nil? && !wobj.nil? end
Write cover file to IO object wobj
. If #config is defined, it will be
used for the cover image.
# File ../../../../../lib/epubmaker/producer.rb, line 114 def cover(wobj) type = @config['epubversion'] >= 3 ? 'cover' : nil s = @epub.cover(type) wobj.puts s if !s.nil? && !wobj.nil? end
# File ../../../../../lib/epubmaker/producer.rb, line 57 def coverimage return nil unless config['coverimage'] @contents.each do |item| if item.media.start_with?('image') && item.file =~ /#{config['coverimage']}\Z/ return item.file end end 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 140 def import_imageinfo(path, base = nil, allow_exts = nil) return nil unless File.exist?(path) allow_exts = @config['image_ext'] if allow_exts.nil? Dir.foreach(path) do |f| next if f.start_with?('.') if f =~ /\.(#{allow_exts.join('|')})\Z/ path.chop! if path =~ %r{/\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 import_imageinfo("#{path}/#{f}", base) if FileTest.directory?("#{path}/#{f}") end end
# File ../../../../../lib/epubmaker/producer.rb, line 188 def isbn_hyphen str = @config['isbn'].to_s return "#{str[0..0]}-#{str[1..5]}-#{str[6..8]}-#{str[9..9]}" if str =~ /\A\d{10}\Z/ return "#{str[0..2]}-#{str[3..3]}-#{str[4..8]}-#{str[9..11]}-#{str[12..12]}" if str =~ /\A\d{13}\Z/ nil end
Take YAML file
and update parameter hash.
# File ../../../../../lib/epubmaker/producer.rb, line 38 def load(file) raise "Can't open #{file}." if file.nil? || !File.exist?(file) loader = ReVIEW::YAMLLoader.new merge_config(@config.deep_merge(loader.load_file(file))) end
Update parameters by merging from new parameter hash config
.
# File ../../../../../lib/epubmaker/producer.rb, line 68 def merge_config(config) @config.deep_merge!(config) complement unless @config['epubversion'].nil? case @config['epubversion'].to_i when 2 @epub = EPUBMaker::EPUBv2.new(self) when 3 @epub = EPUBMaker::EPUBv3.new(self) else raise "Invalid EPUB version (#{@config['epubversion']}.)" end end ReVIEW::I18n.locale = config['language'] if config['language'] support_legacy_maker end
Write mimetype file to IO object wobj
.
# File ../../../../../lib/epubmaker/producer.rb, line 87 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 133 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 100 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 93 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 162 def produce(epubfile, basedir = nil, tmpdir = nil) current = Dir.pwd basedir = current if basedir.nil? new_tmpdir = tmpdir.nil? ? Dir.mktmpdir : tmpdir epubfile = "#{current}/#{epubfile}" if epubfile !~ %r{\A/} # FIXME: error check File.unlink(epubfile) if File.exist?(epubfile) begin @epub.produce(epubfile, basedir, new_tmpdir) ensure FileUtils.rm_r(new_tmpdir) if tmpdir.nil? end end
Write title file (copying) to IO object wobj
.
# File ../../../../../lib/epubmaker/producer.rb, line 121 def titlepage(wobj) s = @epub.titlepage wobj.puts s if !s.nil? && !wobj.nil? end