# = epubcommon.rb -- super class for EPUBv2 and EPUBv3
#
# Copyright (c) 2010-2017 Kenshi Muto and Masayoshi Takahashi
#
# This program is free software.
# You can distribute or modify this program under the terms of
# the GNU LGPL, Lesser General Public License version 2.1.
# For details of the GNU LGPL, see the file "COPYING".
#
require 'review/i18n'
require 'review/template'
require 'cgi'
module EPUBMaker
# EPUBCommon is the common class for EPUB producer.
class EPUBCommon
# Construct object with parameter hash +config+ and message resource hash +res+.
def initialize(producer)
@body_ext = ''
@producer = producer
@body_ext = nil
end
# Return mimetype content.
def mimetype
'application/epub+zip'
end
def opf_path
"OEBPS/#{@producer.config['bookname']}.opf"
end
def opf_coverimage
s = ''
if @producer.config['coverimage']
file = nil
@producer.contents.each do |item|
next if !item.media.start_with?('image') || item.file !~ /#{@producer.config["coverimage"]}\Z/
s << %Q( \n)
file = item.file
break
end
raise "coverimage #{@producer.config['coverimage']} not found. Abort." if file.nil?
end
s
end
def ncx_isbn
uid = @producer.config['isbn'] || @producer.config['urnid']
%Q( \n)
end
def ncx_doctitle
<#{CGI.escapeHTML(@producer.config.name_of('title'))}
EOT
if @producer.config['subtitle']
@body << <<-EOT
#{CGI.escapeHTML(@producer.config.name_of('subtitle'))}
EOT
end
end
@title = CGI.escapeHTML(@producer.config.name_of('title'))
@language = @producer.config['language']
@stylesheets = @producer.config['stylesheet']
tmplfile = if @producer.config['htmlversion'].to_i == 5
File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
else
File.expand_path('./html/layout-xhtml1.html.erb', ReVIEW::Template::TEMPLATE_DIR)
end
tmpl = ReVIEW::Template.load(tmplfile)
tmpl.result(binding)
end
# Return title (copying) content.
# NOTE: this method is not used yet.
# see lib/review/epubmaker.rb#build_titlepage
def titlepage
@title = CGI.escapeHTML(@producer.config.name_of('title'))
@body = <
#{CGI.escapeHTML(@producer.res.v(role))} | #{CGI.escapeHTML(join_with_separator(@producer.config.names_of(role), ReVIEW::I18n.t('names_splitter')))} |
---|---|
ISBN | #{@producer.isbn_hyphen} |
#{join_with_separator(@producer.config.names_of('rights').map { |m| CGI.escapeHTML(m) }, '
')}
#{ReVIEW::I18n.t('published_by1', [date_to_s(item), editstr + revstr])}
\n) elsif item =~ /\A(\d+\-\d+\-\d+)[\s ](.+)/ # custom date with string item.match(/\A(\d+\-\d+\-\d+)[\s ](.+)/) do |m| buf << %Q(#{ReVIEW::I18n.t('published_by3', [date_to_s(m[1]), m[2]])}
\n) end else # free format buf << %Q(#{item}
\n) end end end else buf << %Q(#{ReVIEW::I18n.t('published_by2', date_to_s(@producer.config['date']))}
\n) end buf << %Q(