lib/epubmaker/epubcommon.rb in review-2.1.0 vs lib/epubmaker/epubcommon.rb in review-2.2.0
- old
+ new
@@ -1,25 +1,19 @@
# encoding: utf-8
# = epubcommon.rb -- super class for EPUBv2 and EPUBv3
#
-# Copyright (c) 2010-2016 Kenshi Muto and Masayoshi Takahashi
+# 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'
-require 'shellwords'
-begin
- require 'zip'
-rescue LoadError
- ## I cannot find rubyzip library, so I use external zip command.
-end
module EPUBMaker
# EPUBCommon is the common class for EPUB producer.
class EPUBCommon
@@ -142,10 +136,15 @@
EOT
else
@body = <<-EOT
<h1 class="cover-title">#{CGI.escapeHTML(@producer.params.name_of("title"))}</h1>
EOT
+ if @producer.params["subtitle"]
+ @body << <<-EOT
+<h2 class="cover-subtitle">#{CGI.escapeHTML(@producer.params.name_of("subtitle"))}</h2>
+ EOT
+ end
end
@title = CGI.escapeHTML(@producer.params.name_of("title"))
@language = @producer.params['language']
@stylesheets = @producer.params["stylesheet"]
@@ -157,16 +156,25 @@
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 = <<EOT
<h1 class="tp-title">#{@title}</h1>
EOT
+
+ if @producer.params["subtitle"]
+ @body << <<EOT
+ <h2 class="tp-subtitle">#{CGI.escapeHTML(@producer.params.name_of("subtitle"))}</h2>
+EOT
+ end
+
if @producer.params["aut"]
@body << <<EOT
<p>
<br />
<br />
@@ -257,15 +265,18 @@
items.each_with_index do |item, rev|
editstr = (edit == 0) ? ReVIEW::I18n.t("first_edition") : ReVIEW::I18n.t("nth_edition","#{edit+1}")
revstr = ReVIEW::I18n.t("nth_impression", "#{rev+1}")
if item =~ /\A\d+\-\d+\-\d+\Z/
buf << %Q[ <p>#{ReVIEW::I18n.t("published_by1", [date_to_s(item), editstr+revstr])}</p>\n]
- else
+ elsif item =~ /\A(\d+\-\d+\-\d+)[\s ](.+)/
# custom date with string
item.match(/\A(\d+\-\d+\-\d+)[\s ](.+)/) do |m|
buf << %Q[ <p>#{ReVIEW::I18n.t("published_by3", [date_to_s(m[1]), m[2]])}</p>\n]
end
+ else
+ # free format
+ buf << %Q[ <p>#{item}</p>\n]
end
end
end
else
buf << %Q[ <p>#{ReVIEW::I18n.t("published_by2", date_to_s(@producer.params["date"]))}</p>\n]
@@ -400,48 +411,9 @@
next if item.file =~ /#/ # skip subgroup
fname = "#{basedir}/#{item.file}"
raise "#{fname} doesn't exist. Abort." unless File.exist?(fname)
FileUtils.mkdir_p(File.dirname("#{tmpdir}/OEBPS/#{item.file}"))
FileUtils.cp(fname, "#{tmpdir}/OEBPS/#{item.file}")
- end
- end
-
- def export_zip(tmpdir, epubfile)
- if defined?(Zip)
- export_zip_rubyzip(tmpdir, epubfile)
- else
- export_zip_extcmd(tmpdir, epubfile)
- end
- end
-
- def export_zip_extcmd(tmpdir, epubfile)
- Dir.chdir(tmpdir) {|d| `#{@producer.params["epubmaker"]["zip_stage1"]} #{epubfile.shellescape} mimetype` }
- Dir.chdir(tmpdir) {|d| `#{@producer.params["epubmaker"]["zip_stage2"]} #{epubfile.shellescape} META-INF OEBPS #{@producer.params["epubmaker"]["zip_addpath"]}` }
- end
-
- def export_zip_rubyzip(tmpdir, epubfile)
- Dir.chdir(tmpdir) do |d|
- Zip::OutputStream.open(epubfile) do |epub|
- root_pathname = Pathname.new(tmpdir)
- # relpath = Pathname.new(File.join(tmpdir,'mimetype')).relative_path_from(root_pathname)
- epub.put_next_entry('mimetype', nil, nil, Zip::Entry::STORED)
- epub << "application/epub+zip"
-
- export_zip_rubyzip_addpath(epub, File.join(tmpdir,'META-INF'), root_pathname)
- export_zip_rubyzip_addpath(epub, File.join(tmpdir,'OEBPS'), root_pathname)
- if @producer.params["zip_addpath"].present?
- export_zip_rubyzip_addpath(epub, File.join(tmpdir,@producer.params["zip_addpath"]), root_pathname)
- end
- end
- end
- end
-
- def export_zip_rubyzip_addpath(epub, dirname, rootdir)
- Dir[File.join(dirname,'**','**')].each do |path|
- next if File.directory?(path)
- relpath = Pathname.new(path).relative_path_from(rootdir)
- epub.put_next_entry(relpath)
- epub << File.binread(path)
end
end
def legacy_cover_and_title_file(loadfile, writefile)
@title = @producer.params["booktitle"]