lib/review/epubmaker.rb in review-2.4.0 vs lib/review/epubmaker.rb in review-2.5.0
- old
+ new
@@ -48,11 +48,17 @@
puts s if @config['debug'].present?
end
def load_yaml(yamlfile)
loader = ReVIEW::YAMLLoader.new
- @config = ReVIEW::Configure.values.deep_merge(loader.load_file(yamlfile))
+ @config = ReVIEW::Configure.values
+ begin
+ @config.deep_merge!(loader.load_file(yamlfile))
+ rescue => e
+ error "yaml error #{e.message}"
+ end
+
@producer = Producer.new(@config)
@producer.load(yamlfile)
@config = @producer.config
@config.maker = 'epubmaker'
end
@@ -132,12 +138,15 @@
Dir.mkdir(epubtmpdir)
end
log('Call ePUB producer.')
@producer.produce("#{bookname}.epub", basetmpdir, epubtmpdir)
log('Finished.')
+ rescue ApplicationError => e
+ raise if @config['debug']
+ error(e.message)
ensure
- FileUtils.remove_entry_secure basetmpdir unless @config['debug']
+ FileUtils.remove_entry_secure(basetmpdir) unless @config['debug']
end
end
def call_hook(hook_name, *params)
filename = @config['epubmaker'][hook_name]
@@ -362,11 +371,12 @@
end
def write_info_body(basetmpdir, _id, filename, ispart = nil, chaptype = nil)
headlines = []
path = File.join(basetmpdir, filename)
- Document.parse_stream(File.new(path), ReVIEWHeaderListener.new(headlines))
+ htmlio = File.new(path)
+ Document.parse_stream(htmlio, ReVIEWHeaderListener.new(headlines))
properties = detect_properties(path)
prop_str = ''
prop_str = ',properties=' + properties.join(' ') if properties.present?
first = true
headlines.each do |headline|
@@ -376,10 +386,11 @@
else
@htmltoc.add_item(headline['level'], filename, headline['title'], { force_include: true, chaptype: chaptype + prop_str, notoc: headline['notoc'] })
first = nil
end
end
+ htmlio.close
end
def push_contents(_basetmpdir)
@htmltoc.each_item do |level, file, title, args|
next if level.to_i > @config['toclevel'] && args[:force_include].nil?
@@ -433,10 +444,10 @@
@body = ''
@body << %Q(<div class="titlepage">\n)
@body << %Q(<h1 class="tp-title">#{CGI.escapeHTML(@config.name_of('booktitle'))}</h1>\n)
@body << %Q(<h2 class="tp-subtitle">#{CGI.escapeHTML(@config.name_of('subtitle'))}</h2>\n) if @config['subtitle']
@body << %Q(<h2 class="tp-author">#{CGI.escapeHTML(@config.names_of('aut').join(ReVIEW::I18n.t('names_splitter')))}</h2>\n) if @config['aut']
- @body << %Q(<h3 class="tp-publisher">#{CGI.escapeHTML(@config.names_of('prt').join(ReVIEW::I18n.t('names_splitter')))}</h3>\n) if @config['prt']
+ @body << %Q(<h3 class="tp-publisher">#{CGI.escapeHTML(@config.names_of('pbl').join(ReVIEW::I18n.t('names_splitter')))}</h3>\n) if @config['pbl']
@body << '</div>'
@language = @producer.config['language']
@stylesheets = @producer.config['stylesheet']
tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR)