lib/softcover/builders/epub.rb in softcover-1.0.5 vs lib/softcover/builders/epub.rb in softcover-1.1.beta1
- old
+ new
@@ -32,12 +32,12 @@
def escape(string)
CGI.escape_html(string)
end
# Returns a content.opf file based on a valid template.
- def content_opf_template(title, copyright, author, uuid, cover_id,
- toc_chapters, manifest_chapters, images)
+ def content_opf_template(title, copyright, author, uuid, cover_id,
+ toc_chapters, manifest_chapters, images)
%(<?xml version="1.0" encoding="UTF-8"?>
<package unique-identifier="BookID" version="3.0" xmlns="http://www.idpf.org/2007/opf">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:opf="http://www.idpf.org/2007/opf">
<dc:title>#{escape(title)}</dc:title>
@@ -105,11 +105,11 @@
#{nav_list.join("\n")}
</ol>
</nav>
</body>
</html>
-)
+)
end
end
module Builders
@@ -133,11 +133,11 @@
write_toc
write_nav
copy_image_files
write_html(options)
write_contents
- create_style_files
+ create_style_files(options)
make_epub(options)
move_epub
end
# Returns true if generating a book preview.
@@ -308,10 +308,14 @@
png['src'] = File.join('images', 'texmath',
File.basename(png_filename))
png['alt'] = png_filename.sub('.png', '')
svg.replace(png)
end
+ # Make references relative.
+ source.css('a.hyperref').each do |ref_node|
+ ref_node['href'] = ref_node['href'].sub('.html', '_fragment.html')
+ end
source.at_css('div#book').children.to_xhtml
end
# Returns the PhantomJS executable (if available).
def phantomjs
@@ -341,20 +345,20 @@
# an unnecessary call to page.js).
def math?(string)
!!string.match(/(?:\\\(|\\\[|\\begin{equation})/)
end
- def create_style_files
+ def create_style_files(options)
html_styles = File.join('html', 'stylesheets')
epub_styles = File.join('epub', 'OEBPS', 'styles')
FileUtils.cp(File.join(html_styles, 'pygments.css'), epub_styles)
File.write(File.join(epub_styles, 'softcover.css'),
clean_book_id(path("#{html_styles}/softcover.css")))
# Copy over the EPUB-specific CSS.
- template_dir = File.join(File.dirname(__FILE__), '..', 'template')
+ template_dir = Softcover::Utils.template_dir(options)
epub_css = File.join(template_dir, epub_styles, 'epub.css')
FileUtils.cp(epub_css, epub_styles)
# Copy over custom CSS.
File.write(File.join(epub_styles, 'custom.css'),
@@ -472,11 +476,11 @@
# invalid character such as a number.
label = File.basename(image).gsub('.', '-')
id = "img-#{label}"
%(<item id="#{id}" href="#{href}" media-type="image/#{ext}"/>)
end
- content_opf_template(manifest.title, manifest.copyright,
- manifest.author, manifest.uuid, cover_id,
+ content_opf_template(manifest.title, manifest.copyright,
+ manifest.author, manifest.uuid, cover_id,
toc_ch, man_ch, images)
end
def cover_page
%(<?xml version="1.0" encoding="utf-8"?>
\ No newline at end of file