lib/epubmaker/epubv2.rb in review-1.3.0 vs lib/epubmaker/epubv2.rb in review-1.4.0

- old
+ new

@@ -121,13 +121,19 @@ s << %Q[ </manifest>\n] s end def opf_tocx + if @producer.params["cover_linear"] && @producer.params["cover_linear"] != "no" + cover_linear = "yes" + else + cover_linear = "no" + end + s = "" s << %Q[ <spine toc="ncx">\n] - s << %Q[ <itemref idref="#{@producer.params["bookname"]}" linear="no"/>\n] + 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? @@ -221,11 +227,11 @@ level = item.level.nil? ? 0 : (item.level - 1) level = indent.size - 1 if level >= indent.size s << <<EOT <navPoint id="nav-#{nav_count}" playOrder="#{nav_count}"> <navLabel> - <text>#{indent[level]}#{item.title}</text> + <text>#{indent[level]}#{CGI.escapeHTML(item.title)}</text> </navLabel> <content src="#{item.file}"/> </navPoint> EOT nav_count += 1 @@ -249,16 +255,18 @@ EOT s end # Return cover content. - def cover + def cover(type=nil) + bodyext = type.nil? ? "" : " epub:type=\"#{type}\"" + s = common_header s << <<EOT <title>#{CGI.escapeHTML(@producer.params["title"])}</title> </head> -<body> +<body#{bodyext}> EOT if @producer.params["coverimage"].nil? s << <<EOT <h1 class="cover-title">#{CGI.escapeHTML(@producer.params["title"])}</h1> EOT @@ -446,11 +454,11 @@ 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) + item.notoc = true if (item.chaptype == "pre" || item.chaptype == "post") && !item.level.nil? && (item.level + 1 == toclevel) # FIXME: 部があるときに前後の処理が困難 end toclevel += 1 end doc = REXML::Document.new(%Q[<#{type} class="toc-h#{level}"><li /></#{type}>]) @@ -498,11 +506,11 @@ def flat_ncx(type, indent=nil) s = %Q[<#{type} class="toc-h1">\n] @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 is = indent == true ? " " * item.level : "" - s << %Q[<li><a href="#{item.file}">#{is}#{item.title}</a></li>\n] + s << %Q[<li><a href="#{item.file}">#{is}#{CGI.escapeHTML(item.title)}</a></li>\n] end s << %Q[</#{type}>\n] s end @@ -543,11 +551,11 @@ FileUtils.cp(fname, "#{tmpdir}/OEBPS/#{item.file}") 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 #{@producer.params["zip_addpath"]}") } + Dir.chdir(tmpdir) {|d| `#{@producer.params["zip_stage1"]} #{epubfile} mimetype` } + Dir.chdir(tmpdir) {|d| `#{@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