# encoding: utf-8
# = 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 +params+ 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.params["bookname"]}.opf"
end
def opf_coverimage
s = ""
if @producer.params["coverimage"]
file = nil
@producer.contents.each do |item|
if item.media.start_with?('image') && item.file =~ /#{@producer.params["coverimage"]}\Z/
s << %Q[ \n]
file = item.file
break
end
end
raise "coverimage #{@producer.params["coverimage"]} not found. Abort." if file.nil?
end
s
end
def ncx_isbn
uid = @producer.params["isbn"] || @producer.params["urnid"]
%Q[ \n]
end
def ncx_doctitle
<#{CGI.escapeHTML(@producer.params.name_of("title"))}
EOT
if @producer.params["subtitle"]
@body << <<-EOT
#{CGI.escapeHTML(@producer.params.name_of("subtitle"))}
EOT
end
end
@title = CGI.escapeHTML(@producer.params.name_of("title"))
@language = @producer.params['language']
@stylesheets = @producer.params["stylesheet"]
if @producer.params["htmlversion"].to_i == 5
tmplfile = File.expand_path('./html/layout-html5.html.erb', ReVIEW::Template::TEMPLATE_DIR)
else
tmplfile = 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.params.name_of("title"))
@body = <
#{CGI.escapeHTML(@producer.res.v(role))} | #{CGI.escapeHTML(join_with_separator(@producer.params.names_of(role), ReVIEW::I18n.t("names_splitter")))} |
---|---|
ISBN | #{@producer.isbn_hyphen} |
#{join_with_separator(@producer.params.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.params["date"]))}
\n] end buf << %Q[