Class: ReVIEW::EPUBMaker::Producer
- Defined in:
- lib/review/epubmaker/producer.rb
Overview
EPUBMaker produces EPUB file.
Instance Attribute Summary collapse
-
#config ⇒ Object
Parameter hash.
-
#contents ⇒ Object
Array of content objects.
-
#res ⇒ Object
readonly
Message resource object.
Instance Method Summary collapse
-
#import_imageinfo(path, base = nil, allow_exts = nil) ⇒ Object
(also: #importImageInfo)
Add informations of figure files in
pathto contents array. -
#initialize(config) ⇒ Producer
constructor
Construct producer object.
-
#modify_config ⇒ Object
Modify parameters for EPUB specific.
-
#produce(epubfile, work_dir, tmpdir = nil, base_dir: nil) ⇒ Object
Produce EPUB file
epubfile. - #warn(msg) ⇒ Object
Constructor Details
#initialize(config) ⇒ Producer
Construct producer object. config takes initial parameter hash.
46 47 48 49 50 51 52 53 54 |
# File 'lib/review/epubmaker/producer.rb', line 46 def initialize(config) @contents = [] @config = config @config.maker = 'epubmaker' @epub = nil @res = ReVIEW::I18n @logger = ReVIEW.logger modify_config end |
Instance Attribute Details
#config ⇒ Object
Parameter hash.
36 37 38 |
# File 'lib/review/epubmaker/producer.rb', line 36 def config @config end |
#contents ⇒ Object
Array of content objects.
34 35 36 |
# File 'lib/review/epubmaker/producer.rb', line 34 def contents @contents end |
#res ⇒ Object (readonly)
Message resource object.
38 39 40 |
# File 'lib/review/epubmaker/producer.rb', line 38 def res @res end |
Instance Method Details
#import_imageinfo(path, base = nil, allow_exts = nil) ⇒ Object Also known as: importImageInfo
Add informations of figure files in path to contents array. base defines a string to remove from path name.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/review/epubmaker/producer.rb', line 86 def import_imageinfo(path, base = nil, allow_exts = nil) return nil unless File.exist?(path) allow_exts ||= @config['image_ext'] Dir.foreach(path) do |f| next if f.start_with?('.') if f =~ /\.(#{allow_exts.join('|')})\Z/i path.chop! if path =~ %r{/\Z} if base.nil? @contents.push(ReVIEW::EPUBMaker::Content.new(file: "#{path}/#{f}")) else @contents.push(ReVIEW::EPUBMaker::Content.new(file: "#{path.sub(base + '/', '')}/#{f}")) end end if FileTest.directory?("#{path}/#{f}") import_imageinfo("#{path}/#{f}", base) end end end |
#modify_config ⇒ Object
Modify parameters for EPUB specific.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/review/epubmaker/producer.rb', line 57 def modify_config if @config['epubversion'] >= 3 @config['htmlversion'] = 5 end @config['title'] ||= @config['booktitle'] @config['cover'] ||= "#{@config['bookname']}.#{@config['htmlext']}" %w[bookname title].each do |k| unless @config[k] raise "Key #{k} must have a value. Abort." end end case @config['epubversion'].to_i when 2 @epub = ReVIEW::EPUBMaker::EPUBv2.new(self) when 3 @epub = ReVIEW::EPUBMaker::EPUBv3.new(self) else raise "Invalid EPUB version (#{@config['epubversion']}.)" end ReVIEW::I18n.locale = @config['language'] support_legacy_maker end |
#produce(epubfile, work_dir, tmpdir = nil, base_dir: nil) ⇒ Object
Produce EPUB file epubfile. work_dir points the directory has contents (default: current directory.) tmpdir defines temporary directory. base_dir is original root dir.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/review/epubmaker/producer.rb', line 113 def produce(epubfile, work_dir, tmpdir = nil, base_dir: nil) current = Dir.pwd base_dir ||= current # use Dir to solve a path for Windows (see #1011) new_tmpdir = Dir[File.join(tmpdir.nil? ? Dir.mktmpdir : tmpdir)][0] if epubfile !~ %r{\A/} epubfile = "#{current}/#{epubfile}" end # FIXME: error check File.unlink(epubfile) if File.exist?(epubfile) begin @epub.produce(epubfile, work_dir, new_tmpdir, base_dir: base_dir) ensure FileUtils.rm_r(new_tmpdir) if tmpdir.nil? end end |
#warn(msg) ⇒ Object
40 41 42 |
# File 'lib/review/epubmaker/producer.rb', line 40 def warn(msg) @logger.warn(msg) end |