# 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_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 =~ /\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
end
@title = @producer.params['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.
def titlepage
@title = @producer.params["title"]
@body = <
#{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| @body << %Q[#{ReVIEW::I18n.t("published_by3", [date_to_s(m[1]), m[2]])}
\n] end end end end else @body << %Q[#{ReVIEW::I18n.t("published_by2", date_to_s(@producer.params["date"]))}
\n] end @body << %Q[#{@producer.res.v(role)} | #{CGI.escapeHTML(@producer.params[role].join(", "))} |
---|---|
ISBN | #{isbn} |
#{@producer.params["rights"].join("
")}