lib/epubmaker/epubv2.rb in review-1.2.0 vs lib/epubmaker/epubv2.rb in review-1.3.0
- old
+ new
@@ -1,9 +1,9 @@
# encoding: utf-8
# = epubv2.rb -- EPUB version 2 producer.
#
-# Copyright (c) 2010-2013 Kenshi Muto and Masayoshi Takahashi
+# 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".
@@ -350,11 +350,18 @@
if @producer.params["history"]
@producer.params["history"].each_with_index do |items, edit|
items.each_with_index do |item, rev|
editstr = (edit == 0) ? "初版" : "第#{edit + 1}版" # FIXME:i18n
revstr = "第#{rev + 1}刷"
- s << %Q[ <p>#{date_to_s(item)} #{editstr}#{revstr} 発行</p>\n] # FIXME:i18n
+ if item =~ /\A\d+\-\d+\-\d+\Z/
+ s << %Q[ <p>#{date_to_s(item)} #{editstr}#{revstr} 発行</p>\n] # FIXME:i18n
+ else
+ # custom date with string
+ item.match(/\A(\d+\-\d+\-\d+)[\s ](.+)/) do |m|
+ s << %Q[ <p>#{date_to_s(m[1])} #{m[2]}</p>\n]
+ end
+ end
end
end
else
s << %Q[ <p>#{date_to_s(@producer.params["date"])} 発行</p>\n] #FIXME:i18n
end
@@ -380,10 +387,16 @@
end
s << %Q[ <tr><th>ISBN</th><td>#{isbn}</td></tr>\n]
end
s << <<EOT
</table>
+EOT
+ if !@producer.params["rights"].nil? && @producer.params["rights"].size > 0
+ s << %Q[ <p class="copyright">#{@producer.params["rights"].join("<br />")}</p>]
+ end
+
+ s << <<EOT
</div>
</body>
</html>
EOT
s
@@ -419,31 +432,48 @@
def hierarchy_ncx(type)
require 'rexml/document'
level = 1
find_jump = nil
+ has_part = nil
+ toclevel = @producer.params["toclevel"].to_i
# check part existance
@producer.contents.each do |item|
- if item.notoc.nil? && item.level == 0
- level = 0
+ if item.notoc.nil? && item.chaptype == "part"
+ has_part = true
+ break
end
end
+ if !has_part.nil?
+ @producer.contents.each do |item|
+ item.level += 1 if item.chaptype == "part" || item.chaptype == "body"
+ item.notoc = true if (item.chaptype == "pre" || item.chaptype == "post") && !item.level.nil? && (item.level + 1 == toclevel)
+ end
+ toclevel += 1
+ end
+
doc = REXML::Document.new(%Q[<#{type} class="toc-h#{level}"><li /></#{type}>])
e = doc.root.elements[1] # first <li/>
@producer.contents.each do |item|
- next if !item.notoc.nil? || item.level.nil? || item.file.nil? || item.title.nil? || item.level > @producer.params["toclevel"].to_i
+ next if !item.notoc.nil? || item.level.nil? || item.file.nil? || item.title.nil? || item.level > toclevel
if item.level == level
e2 = e.parent.add_element("li")
e = e2
elsif item.level > level
find_jump = true if (item.level - level) > 1
# deeper
(level + 1).upto(item.level) do |n|
+ if e.size == 0
+ # empty span for epubcheck
+ es = e.add_element("span")
+ es.add_text(REXML::Text.new(" ", false, nil, true))
+ end
+
e2 = e.add_element(type, {"class" => "toc-h#{n}"})
e3 = e2.add_element("li")
e = e3
end
level = item.level
@@ -514,13 +544,35 @@
end
end
def export_zip(tmpdir, epubfile)
Dir.chdir(tmpdir) {|d| system("#{@producer.params["zip_stage1"]} #{epubfile} mimetype") }
- Dir.chdir(tmpdir) {|d| system("#{@producer.params["zip_stage2"]} #{epubfile} META-INF OEBPS") }
+ Dir.chdir(tmpdir) {|d| system("#{@producer.params["zip_stage2"]} #{epubfile} META-INF OEBPS #{@producer.params["zip_addpath"]}") }
end
+ def legacy_cover_and_title_file(loadfile, writefile)
+ s = common_header
+ s << <<EOT
+ <title>#{@producer.params["booktitle"]}</title>
+</head>
+<body>
+EOT
+ File.open(loadfile) do |f|
+ f.each_line do |l|
+ s << l
+ end
+ end
+ s << <<EOT
+</body>
+</html>
+EOT
+
+ File.open(writefile, "w") do |f|
+ f.puts s
+ end
+ end
+
private
# Return common XHTML headder
def common_header
s =<<EOT
@@ -528,10 +580,10 @@
<!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="EPUBMaker::Producer"/>
+ <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