# encoding: utf-8
# = epubcommon.rb -- super class for EPUBv2 and EPUBv3
#
# Copyright (c) 2010-2014 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 'epubmaker/producer'
require 'review/i18n'
require 'cgi'
require 'shellwords'
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)
@producer = producer
end
# Return mimetype content.
def mimetype
"application/epub+zip"
end
def opf_coverimage
s = ""
if @producer.params["coverimage"]
file = nil
@producer.contents.each do |item|
if item.media =~ /\Aimage/ && 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
if @producer.params["isbn"].nil?
%Q[ \n]
else
%Q[ \n]
end
end
def ncx_doctitle
<#{CGI.escapeHTML(@producer.params["title"])}
EOT
if @producer.params["aut"]
s << <
#{ReVIEW::I18n.t("published_by1", [date_to_s(item), editstr+revstr])}
\n] else # custom date with string item.match(/\A(\d+\-\d+\-\d+)[\s ](.+)/) do |m| s << %Q[#{ReVIEW::I18n.t("published_by3", [date_to_s(m[1]), m[2]])}
\n] end end end end else s << %Q[#{ReVIEW::I18n.t("published_by2", date_to_s(@producer.params["date"]))}
\n] end s << %Q[#{@producer.res.v("aut")} | #{CGI.escapeHTML(@producer.params["aut"].join(", "))} |
---|---|
#{@producer.res.v("csl")} | #{CGI.escapeHTML(@producer.params["csl"].join(", "))} |
#{@producer.res.v("trl")} | #{CGI.escapeHTML(@producer.params["trl"].join(", "))} |
#{@producer.res.v("dsr")} | #{CGI.escapeHTML(@producer.params["dsr"].join(", "))} |
#{@producer.res.v("ill")} | #{CGI.escapeHTML(@producer.params["ill"].join(", "))} |
#{@producer.res.v("edt")} | #{CGI.escapeHTML(@producer.params["edt"].join(", "))} |
#{@producer.res.v("pbl")} | #{CGI.escapeHTML(@producer.params["pbl"].join(", "))} |
#{@producer.res.v("prt")} | #{CGI.escapeHTML(@producer.params["prt"].join(", "))} |
#{@producer.res.v("pht")} | #{CGI.escapeHTML(@producer.params["pht"].join(", "))} |
ISBN | #{isbn} |