lib/epubmaker/epubv2.rb in review-2.0.0.beta1 vs lib/epubmaker/epubv2.rb in review-2.0.0
- old
+ new
@@ -1,9 +1,9 @@
# encoding: utf-8
# = epubv2.rb -- EPUB version 2 producer.
#
-# Copyright (c) 2010-2015 Kenshi Muto and Masayoshi Takahashi
+# Copyright (c) 2010-2016 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".
@@ -21,38 +21,28 @@
super
end
# Return opf file content.
def opf
- s = <<EOT
-<?xml version="1.0" encoding="UTF-8"?>
-<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
- <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
-EOT
+ @opf_metainfo = opf_metainfo
+ @opf_coverimage = opf_coverimage
+ @opf_manifest = opf_manifest
+ @opf_toc = opf_tocx
- s << opf_metainfo
- s << opf_coverimage
-
- s << %Q[ </metadata>\n]
-
- s << opf_manifest
- s << opf_tocx
- s << opf_guide
-
- s << %Q[</package>\n]
-
- s
+ tmplfile = File.expand_path('./opf/epubv2.opf.erb', ReVIEW::Template::TEMPLATE_DIR)
+ tmpl = ReVIEW::Template.load(tmplfile)
+ return tmpl.result(binding)
end
def opf_metainfo
s = ""
%w[title language date type format source description relation coverage subject rights].each do |item|
- next if @producer.params[item].nil?
- if @producer.params[item].instance_of?(Array)
- s << @producer.params[item].map {|i| %Q[ <dc:#{item}>#{CGI.escapeHTML(i.to_s)}</dc:#{item}>\n]}.join
+ next unless @producer.params[item]
+ if @producer.params[item].kind_of?(Array)
+ s << @producer.params.names_of(item).map {|i| %Q[ <dc:#{item}>#{CGI.escapeHTML(i)}</dc:#{item}>\n]}.join
else
- s << %Q[ <dc:#{item}>#{CGI.escapeHTML(@producer.params[item].to_s)}</dc:#{item}>\n]
+ s << %Q[ <dc:#{item}>#{CGI.escapeHTML(@producer.params.name_of(item))}</dc:#{item}>\n]
end
end
# ID
if @producer.params["isbn"].nil?
@@ -61,20 +51,20 @@
s << %Q[ <dc:identifier id="BookId" opf:scheme="ISBN">#{@producer.params["isbn"]}</dc:identifier>\n]
end
# creator (should be array)
%w[aut a-adp a-ann a-arr a-art a-asn a-aqt a-aft a-aui a-ant a-bkp a-clb a-cmm a-dsr a-edt a-ill a-lyr a-mdc a-mus a-nrt a-oth a-pht a-prt a-red a-rev a-spn a-ths a-trc a-trl].each do |role|
- next if @producer.params[role].nil?
- @producer.params[role].each do |v|
+ next unless @producer.params[role]
+ @producer.params.names_of(role).each do |v|
s << %Q[ <dc:creator opf:role="#{role.sub('a-', '')}">#{CGI.escapeHTML(v)}</dc:creator>\n]
end
end
# contributor (should be array)
%w[adp ann arr art asn aqt aft aui ant bkp clb cmm dsr edt ill lyr mdc mus nrt oth pht prt red rev spn ths trc trl].each do |role|
- next if @producer.params[role].nil?
- @producer.params[role].each do |v|
+ next unless @producer.params[role]
+ @producer.params.names_of(role).each do |v|
s << %Q[ <dc:contributor opf:role="#{role}">#{CGI.escapeHTML(v)}</dc:contributor>\n]
if role == "prt"
s << %Q[ <dc:publisher>#{v}</dc:publisher>\n]
end
end
@@ -113,49 +103,25 @@
s << %Q[ <itemref idref="#{@producer.params["bookname"]}" linear="#{cover_linear}"/>\n]
s << %Q[ <itemref idref="toc" />\n] unless @producer.params["mytoc"].nil?
@producer.contents.each do |item|
next if item.media !~ /xhtml\+xml/ # skip non XHTML
- s << %Q[ <itemref idref="#{item.id}"/>\n] if item.notoc.nil?
+ s << %Q[ <itemref idref="#{item.id}"/>\n]
end
s << %Q[ </spine>\n]
s
end
- def opf_guide
- s = ""
- s << %Q[ <guide>\n]
- s << %Q[ <reference type="cover" title="#{@producer.res.v("covertitle")}" href="#{@producer.params["cover"]}"/>\n]
- s << %Q[ <reference type="title-page" title="#{@producer.res.v("titlepagetitle")}" href="titlepage.#{@producer.params["htmlext"]}"/>\n] unless @producer.params["titlepage"].nil?
- s << %Q[ <reference type="toc" title="#{@producer.res.v("toctitle")}" href="#{@producer.params["bookname"]}-toc.#{@producer.params["htmlext"]}"/>\n] unless @producer.params["mytoc"].nil?
- s << %Q[ <reference type="colophon" title="#{@producer.res.v("colophontitle")}" href="colophon.#{@producer.params["htmlext"]}"/>\n] unless @producer.params["colophon"].nil?
- s << %Q[ </guide>\n]
- s
- end
-
# Return ncx content. +indentarray+ has prefix marks for each level.
def ncx(indentarray)
- s = <<EOT
-<?xml version="1.0" encoding="UTF-8"?>
-<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
- <head>
- <meta name="dtb:depth" content="1"/>
- <meta name="dtb:totalPageCount" content="0"/>
- <meta name="dtb:maxPageNumber" content="0"/>
-EOT
- s << ncx_isbn
+ @ncx_isbn = ncx_isbn
+ @ncx_doctitle = ncx_doctitle
+ @ncx_navmap = ncx_navmap(indentarray)
- s << <<EOT
- </head>
-EOT
- s << ncx_doctitle
- s << ncx_navmap(indentarray)
-
- s << <<EOT
-</ncx>
-EOT
- s
+ tmplfile = File.expand_path('./ncx/epubv2.ncx.erb', ReVIEW::Template::TEMPLATE_DIR)
+ tmpl = ReVIEW::Template.load(tmplfile)
+ return tmpl.result(binding)
end
# Produce EPUB file +epubfile+.
# +basedir+ points the directory has contents.
# +tmpdir+ defines temporary directory.
@@ -167,26 +133,7 @@
@producer.call_hook(@producer.params["epubmaker"]["hook_prepack"], tmpdir)
export_zip(tmpdir, epubfile)
end
- private
-
- # Return common XHTML headder
- def common_header
- s =<<EOT
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="#{@producer.params["language"]}">
-<head>
- <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
- <meta http-equiv="Content-Style-Type" content="text/css"/>
- <meta name="generator" content="Re:VIEW"/>
-EOT
-
- @producer.params["stylesheet"].each do |file|
- s << %Q[ <link rel="stylesheet" type="text/css" href="#{file}"/>\n]
- end
- s
- end
end
end