lib/review/epubmaker.rb in review-4.2.0 vs lib/review/epubmaker.rb in review-5.0.0
- old
+ new
@@ -16,11 +16,10 @@
require 'review/yamlloader'
require 'review/version'
require 'review/htmltoc'
require 'review/htmlbuilder'
-require 'review/yamlloader'
require 'rexml/document'
require 'rexml/streamlistener'
require 'epubmaker'
require 'review/epubmaker/reviewheaderlistener'
require 'review/makerhelper'
@@ -50,22 +49,13 @@
def log(msg)
@logger.debug(msg)
end
def load_yaml(yamlfile)
- loader = ReVIEW::YAMLLoader.new
- @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
def self.execute(*args)
self.new.execute(*args)
end
@@ -92,17 +82,17 @@
[cmd_config, args[0], args[1]]
end
def execute(*args)
- @config = ReVIEW::Configure.values
- @config.maker = 'epubmaker'
cmd_config, yamlfile, exportfile = parse_opts(args)
error "#{yamlfile} not found." unless File.exist?(yamlfile)
+ @config = ReVIEW::Configure.create(maker: 'epubmaker',
+ yamlfile: yamlfile,
+ config: cmd_config)
load_yaml(yamlfile)
- @config.deep_merge!(cmd_config)
update_log_level
log("Loaded yaml file (#{yamlfile}).")
produce(yamlfile, exportfile)
end
@@ -250,11 +240,11 @@
allow_exts ||= @config['image_ext']
FileUtils.mkdir_p(destdir)
if @config['epubmaker']['verify_target_images'].present?
@config['epubmaker']['force_include_images'].each do |file|
unless File.exist?(file)
- if file !~ /\Ahttp[s]?:/
+ if file !~ /\Ahttps?:/
warn "#{file} is not found, skip."
end
next
end
basedir = File.dirname(file)
@@ -305,12 +295,11 @@
@ncxstr = ''
@tocdesc = []
basedir = File.dirname(yamlfile)
base_path = Pathname.new(basedir)
- book = ReVIEW::Book.load(basedir)
- book.config = @config
+ book = ReVIEW::Book::Base.new(basedir, config: @config)
@converter = ReVIEW::Converter.new(book, ReVIEW::HTMLBuilder.new)
@compile_errors = nil
book.parts.each do |part|
if part.name.present?
@@ -338,13 +327,13 @@
def build_part(part, basetmpdir, htmlfile)
log("Create #{htmlfile} from a template.")
File.open(File.join(basetmpdir, htmlfile), 'w') do |f|
@body = ''
@body << %Q(<div class="part">\n)
- @body << %Q(<h1 class="part-number">#{CGI.escapeHTML(ReVIEW::I18n.t('part', part.number))}</h1>\n)
+ @body << %Q(<h1 class="part-number">#{h(ReVIEW::I18n.t('part', part.number))}</h1>\n)
if part.name.strip.present?
- @body << %Q(<h2 class="part-title">#{CGI.escapeHTML(part.name.strip)}</h2>\n)
+ @body << %Q(<h2 class="part-title">#{h(part.name.strip)}</h2>\n)
end
@body << %Q(</div>\n)
@language = @producer.config['language']
@stylesheets = @producer.config['stylesheet']
@@ -561,22 +550,22 @@
true
end
def build_titlepage(basetmpdir, htmlfile)
# TODO: should be created via epubcommon
- @title = CGI.escapeHTML(@config.name_of('booktitle'))
+ @title = h(@config.name_of('booktitle'))
File.open(File.join(basetmpdir, htmlfile), 'w') do |f|
@body = ''
@body << %Q(<div class="titlepage">\n)
- @body << %Q(<h1 class="tp-title">#{CGI.escapeHTML(@config.name_of('booktitle'))}</h1>\n)
+ @body << %Q(<h1 class="tp-title">#{h(@config.name_of('booktitle'))}</h1>\n)
if @config['subtitle']
- @body << %Q(<h2 class="tp-subtitle">#{CGI.escapeHTML(@config.name_of('subtitle'))}</h2>\n)
+ @body << %Q(<h2 class="tp-subtitle">#{h(@config.name_of('subtitle'))}</h2>\n)
end
if @config['aut']
- @body << %Q(<h2 class="tp-author">#{CGI.escapeHTML(@config.names_of('aut').join(ReVIEW::I18n.t('names_splitter')))}</h2>\n)
+ @body << %Q(<h2 class="tp-author">#{h(@config.names_of('aut').join(ReVIEW::I18n.t('names_splitter')))}</h2>\n)
end
if @config['pbl']
- @body << %Q(<h3 class="tp-publisher">#{CGI.escapeHTML(@config.names_of('pbl').join(ReVIEW::I18n.t('names_splitter')))}</h3>\n)
+ @body << %Q(<h3 class="tp-publisher">#{h(@config.names_of('pbl').join(ReVIEW::I18n.t('names_splitter')))}</h3>\n)
end
@body << '</div>'
@language = @producer.config['language']
@stylesheets = @producer.config['stylesheet']