aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v4/epub_format.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2013-01-24 20:49:58 -0500
committerRalph Amissah <ralph@amissah.com>2013-01-24 20:49:58 -0500
commit0fc8f80a23ad8bc2213af84c169fbc1828978f8a (patch)
treebba9b57928b77c59ffbb24144af6f5b7cee8efb4 /lib/sisu/v4/epub_format.rb
parentdebian/changelog (4.0.1-1) [posted to experimental, awaiting Wheezy freeze end] (diff)
parentv4 v3: epub, epub_format, provide full depth epub table of contents (diff)
Merge tag 'sisu_4.0.2' into debian/sid
Diffstat (limited to 'lib/sisu/v4/epub_format.rb')
-rw-r--r--lib/sisu/v4/epub_format.rb197
1 files changed, 102 insertions, 95 deletions
diff --git a/lib/sisu/v4/epub_format.rb b/lib/sisu/v4/epub_format.rb
index 5a63a6ec..84d32000 100644
--- a/lib/sisu/v4/epub_format.rb
+++ b/lib/sisu/v4/epub_format.rb
@@ -92,7 +92,7 @@ module SiSU_EPUB_Format
end
class CSS
def css_epub_xhtml
-<<WOK
+ <<-WOK
/* SiSU epub css default stylesheet */
body {
color: black;
@@ -1214,7 +1214,7 @@ module SiSU_EPUB_Format
margin-bottom: 20px;
margin-right: 15mm;
}
-WOK
+ WOK
end
end
class HeadInformation
@@ -1232,17 +1232,17 @@ WOK
@tocband_scroll,@tocband_segtoc=nil,nil
end
def doc_type_xhtml
-<<WOK
+ <<-WOK
<?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">
-WOK
+ WOK
end
=begin
~/epub
|-- META-INF
- | `-- container.xml #✓ simple, make sure full-path of rootfile points to metadata.opf
+ | `-- container.xml # simple, make sure full-path of rootfile points to metadata.opf
|-- content
| |-- 1.xhtml
| |-- 2.xhtml
@@ -1262,21 +1262,21 @@ WOK
| |-- metadata.xhtml
| `-- toc.xhtml
|-- metadata.opf #(i) metadata dc; (ii) manifest (contents); (iii) spine (mimetypes)
- |-- mimetype #✓ application/epub+zip
- `-- toc.ncx #✓ (i) head (ii) doc title (iii) navmap, list of navigation points (like chapters)
+ |-- mimetype # application/epub+zip
+ `-- toc.ncx #(i) head (ii) doc title (iii) navmap, list of navigation points (like chapters)
=end
def doc_type
doc_type_xhtml
end
def mimetype
- <<WOK
+ <<-WOK
application/epub+zip
-WOK
+ WOK
end
def metainf_container #container.xml file in META-INF directory
#simple, make sure full-path of rootfile points to metadata.opf
#epub_metadata.opf content.opf
- <<WOK
+ <<-WOK
<?xml version='1.0' encoding='utf-8'?>
<container version="1.0"
xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
@@ -1285,12 +1285,12 @@ WOK
media-type="application/oebps-package+xml" />
</rootfiles>
</container>
-WOK
+ WOK
end
- def sections(dob,name)
- filename="#{name}#{Sfx[:epub_xhtml]}"
- dir_epub_cont="#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}"
- segfilename="#{dir_epub_cont}/#{filename}"
+ def sections(dob,fn_base)
+ name=fn_base + Sfx[:epub_xhtml]
+ dir_epub_cont=@md.env.processing_path.epub + '/' + Ep[:d_oebps]
+ segfilename=dir_epub_cont + '/' + name
output_epub_cont_seg=File.new(segfilename,'w')
output_epub_cont_seg << %{#{doc_type}
<head>
@@ -1303,11 +1303,12 @@ WOK
</head>
#{@vz.color_body}
<div class="content">
-<div class="substance">
- <label class="ocn"><a href="#o8" class="lnkocn">8</a></label>
- <h1 class="norm" id="o8">
- #{dob.obj}
- </h1>
+ <div class="substance">
+ <label class="ocn"><a href="#o#{dob.ocn}" class="lnkocn">#{dob.ocn}</a></label>
+ <h1 class="norm" id="o#{dob.ocn}">
+ #{dob.obj}
+ </h1>
+ </div>
</div>
</body>
</html>}
@@ -1327,26 +1328,26 @@ output_epub_cont_seg.close
close
end
def open
- <<WOK
+ <<-WOK
<?xml version="1.0"?>
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
-WOK
+ WOK
end
def close
- <<WOK
+ <<-WOK
</ncx>
-WOK
+ WOK
end
def head_open
- <<WOK
+ <<-WOK
<head>
-WOK
+ WOK
end
def head
depth=@md.lvs[1] + @md.lvs[2] + @md.lvs[3] + @md.lvs[4]
- <<WOK
+ <<-WOK
<!-- four required metadata items (for all NCX documents,
(including the relaxed constraints of OPS 2.0) -->
<title>#{@md.title.full} by #{@md.author}</title>
@@ -1356,67 +1357,68 @@ WOK
<meta name="dtb:depth" content="#{depth}" />
<meta name="dtb:totalPageCount" content="0" />
<meta name="dtb:maxPageNumber" content="0" />
-WOK
+ WOK
end
def head_close
- <<WOK
+ <<-WOK
</head>
-WOK
+ WOK
end
def doc_title
- <<WOK
+ <<-WOK
<docTitle>
<text>#{@md.title.full}</text>
</docTitle>
-WOK
+ WOK
end
def doc_author
- <<WOK
+ <<-WOK
<docAuthor>
<text>#{@md.author}</text>
</docAuthor>
-WOK
+ WOK
end
def navmap_open
- <<WOK
+ <<-WOK
<navMap>
-WOK
+ WOK
end
def navmap_sisu_toc(no)
id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \
? ''
: "-#{no}"
- <<WOK
+ <<-WOK
<navPoint id="navpoint#{id_u}" playOrder="#{no}">
<navLabel>
<text>Table of Contents</text>
</navLabel>
<content src="index#{Sfx[:epub_xhtml]}" />
</navPoint>
-WOK
+ WOK
end
- def navpoint(dob,no,name=nil)
- name=name ? name : dob.name
+ def navpoint(dob,no,fn_base,hashtag=nil)
+ fn=fn_base + Sfx[:epub_xhtml]
+ name=hashtag ? fn + hashtag : fn
id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \
? ''
: "-#{no}"
- <<WOK
+ <<-WOK
<navPoint id="navpoint#{id_u}" playOrder="#{no}">
<navLabel>
<text>#{dob.obj}</text>
</navLabel>
- <content src="#{name}#{Sfx[:epub_xhtml]}" />
-WOK
+ <content src="#{name}" />
+ WOK
end
def navpoint_close
- <<WOK
+ <<-WOK
</navPoint>
-WOK
+ WOK
end
def navmap_close
- <<WOK
+ <<-WOK
</navMap>
-WOK
+ WOK
end
self
end
@@ -1434,15 +1436,15 @@ WOK
package_close
end
def package_open
- <<WOK
+ <<-WOK
<?xml version='1.0' encoding='utf-8'?>
<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="EPB-UUID" version="2.0">
-WOK
+ WOK
end
def package_close
- <<WOK
+ <<-WOK
</package>
-WOK
+ WOK
end
def metadata #metadata dc
cover_image=if defined? @md.make.cover_image \
@@ -1568,7 +1570,7 @@ WOK
else ''
end
f=SiSU_Env::FileOp.new(@md)
- <<WOK
+ <<-WOK
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:opf="http://www.idpf.org/2007/opf"
unique-identifier="urn:uuid:#{@md.dgst[1]}" version="2.0">
@@ -1578,38 +1580,39 @@ WOK
<dc:identifier id="bookid">urn:uuid:#{@md.dgst[1]}</dc:identifier>
<!-- <dc:identifier id="EPB-UUID">urn:uuid:#{@md.dgst[1]}</dc:identifier> -->
</metadata>
-WOK
+ WOK
end
def manifest_open
- <<WOK
+ <<-WOK
<manifest>
<!-- NCX -->
<item id="ncx" href="#{Ep[:f_ncx]}" media-type="application/x-dtbncx+xml" />
<!-- CSS Style Sheets -->
<item id="main-css" href="css/xhtml.css" media-type="text/css" />
<!-- Content Documents -->
-WOK
+ WOK
end
def manifest_content_sisu_toc
- <<WOK
- <item id="index" href="index.xhtml" media-type="application/xhtml+xml" />
-WOK
+ <<-WOK
+ <item id="index#{Sfx[:epub_xhtml]}" href="index#{Sfx[:epub_xhtml]}" media-type="application/xhtml+xml" />
+ WOK
end
def manifest_cover_image_information(md)
cover_image=if defined? md.make.cover_image \
and @md.make.cover_image.is_a?(Hash) \
and md.make.cover_image[:cover] =~/\S+/
- <<WOK
+ <<-WOK
<item id="cover_image_file" href="cover_image#{Sfx[:epub_xhtml]}" media-type="application/xhtml+xml" />
-WOK
+ WOK
else ''
end
end
- def manifest_content(dob,name=nil)
- name=name ? name : dob.name
- <<WOK
- <item id="#{name}" href="#{name}#{Sfx[:epub_xhtml]}" media-type="application/xhtml+xml" />
-WOK
+ def manifest_content(dob,fn_base,hashtag=nil)
+ fn=fn_base + Sfx[:epub_xhtml]
+ name=hashtag ? fn + hashtag : fn
+ <<-WOK
+ <item id="#{name}" href="#{name}" media-type="application/xhtml+xml" />
+ WOK
end
def manifest_images(imgs)
imgs=imgs + ['arrow_next_red.png','arrow_prev_red.png','arrow_up_red.png','bullet_09.png']
@@ -1617,71 +1620,75 @@ WOK
imgs.each do |i|
image,type=/(\S+?)\.(png|jpg|gif)/.match(i)[1,2]
type=type.sub(/jpg/,'jpeg')
- images<<<<WOK
+ images<<<<-WOK
<item id="#{image}" href="image/#{image}.#{type}" media-type="image/#{type}" />
-WOK
+ WOK
end
images=images.join('')
images
end
def manifest_close
- <<WOK
+ <<-WOK
</manifest>
-WOK
+ WOK
end
def spine_open
#spine: reading order of XHTML files from manifest, idref attribute refers back to id in manifest (exclude images, CSS etc.).
- <<WOK
+ <<-WOK
<spine toc="ncx">
-WOK
+ WOK
end
def spine_cover_image
- <<WOK
+ <<-WOK
<itemref idref="cover_image_file" />
-WOK
+ WOK
end
def spine_sisu_toc
- <<WOK
- <itemref idref="index" linear="yes" />
-WOK
+ <<-WOK
+ <itemref idref="index#{Sfx[:epub_xhtml]}" linear="yes" />
+ WOK
end
- def spine(dob,name=nil)
- name=name ? name : dob.name
- <<WOK
+ def spine(dob,fn_base,hashtag=nil)
+ fn=fn_base + Sfx[:epub_xhtml]
+ name=hashtag ? fn + hashtag : fn
+ <<-WOK
<itemref idref="#{name}" linear="yes" />
-WOK
+ WOK
end
def spine_close
- <<WOK
+ <<-WOK
</spine>
-WOK
+ WOK
end
def guide_open
#guide: presentation order of XHTML files by reader).
- <<WOK
+ <<-WOK
<guide>
-WOK
+ WOK
end
def guide_cover_image
- <<WOK
+ <<-WOK
<reference type="cover" title="Cover of [book title]" href="cover_image#{Sfx[:epub_xhtml]}" />
-WOK
+ WOK
end
def guide_sisu_toc
- <<WOK
- <reference type="index" href="index#{Sfx[:epub_xhtml]}" />
-WOK
+ <<-WOK
+ <reference type="index#{Sfx[:epub_xhtml]}" href="index#{Sfx[:epub_xhtml]}" />
+ WOK
end
- def guide(dob,name=nil)
+ def guide(dob,fn_base,hashtag=nil)
+ fn=fn_base + Sfx[:epub_xhtml]
+ name=hashtag ? fn + hashtag : fn
name=name ? name : dob.name
- <<WOK
- <reference type="text" href="#{name}#{Sfx[:epub_xhtml]}" />
-WOK
+ guide_name=(name =~/#{Sfx[:epub_xhtml]}/) ? name : (name + Sfx[:epub_xhtml])
+ <<-WOK
+ <reference type="text" href="#{guide_name}" />
+ WOK
end
def guide_close
- <<WOK
+ <<-WOK
</guide>
-WOK
+ WOK
end
self
end