# encoding: utf-8
=begin
* Name: SiSU
* Description: a framework for document structuring, publishing and search
* Author: Ralph Amissah
* Copyright: (C) 1997 - 2011, Ralph Amissah, All Rights Reserved.
* License: GPL 3 or later:
SiSU, a framework for document structuring, publishing and search
Copyright (C) Ralph Amissah
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see .
If you have Internet connection, the latest version of the GPL should be
available at these locations:
* SiSU uses:
* Standard SiSU markup syntax,
* Standard SiSU meta-markup syntax, and the
* Standard SiSU object citation numbering and system
* Hompages:
* Download:
* Ralph Amissah
** Description: epub formating, css template
=end
module SiSU_EPUB_Format
include SiSU_Viz
class Paragraph_number
def initialize(md,ocn)
@md,@ocn=md,ocn.to_s
@ocn ||=''
vz=SiSU_Env::Get_init.instance.skin
@skin_no_ocn=if defined? vz.ocn_display_off \
and vz.ocn_display_off==true
true
else false
end
end
def ocn_display
if @md.markup.inspect =~/no_ocn/ \
or @md.opt.mod.inspect =~/--no-ocn/ \
or @skin_no_ocn
ocn_class='ocn_off'
@ocn.gsub(/^(\d+|)$/,
%{})
elsif @ocn.to_i==0
@ocn.gsub(/^(\d+|)$/,
%{})
else
ocn_class='ocn'
@ocn.gsub(/^(\d+|)$/,
%{})
end
end
def name
%{}
end
def id #w3c? "tidy" complains about numbers as identifiers ! annoying
%{id="o#{@ocn}"}
end
def goto
%{}
end
end
class Css
def css_epub_xhtml
<
WOK
end
=begin
~/epub
|-- META-INF
| `-- container.xml #✓ simple, make sure full-path of rootfile points to metadata.opf
|-- content
| |-- 1.xhtml
| |-- 2.xhtml
| |-- 3.xhtml
| |-- ... .xhtml
| |-- concordance.xhtml
| |-- css
| | `-- xhtml.css
| |-- endnotes.xhtml
| |-- image
| | |-- arrow_next_red.png
| | |-- arrow_prev_red.png
| | |-- arrow_up_red.png
| | `-- bullet_09.png
| |-- index.xhtml
| |-- meta.xhtml
| |-- 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)
=end
def doc_type
doc_type_xhtml
end
def mimetype
<
WOK
end
def toc_ncx #list of navigation points (like chapters), table of contents, listing each navigation point (chapters and such) under the navigation map
def structure
open
head_open
head
head_close
doc_title
doc_author
navmap_open
#navmap ...
navmap_close
close
end
def open
<
WOK
end
def close
<
WOK
end
def head_open
<
WOK
end
def head
depth=@md.lvs[2] + @md.lvs[3] + @md.lvs[4]
<
#{@md.title.full} by #{@md.author}
WOK
end
def head_close
<
WOK
end
def doc_title
<
#{@md.title.full}
WOK
end
def doc_author
<
#{@md.author}
WOK
end
def navmap_open
<
WOK
end
def navmap_sisu_toc(no)
id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \
? '' \
: "-#{no}"
<
Table of Contents
WOK
end
def navpoint(dob,no)
id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \
? '' \
: "-#{no}"
<
#{dob.obj}
WOK
end
def navpoint_top3(dob,no,name)
id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \
? '' \
: "-#{no}"
<
#{dob.obj}
WOK
end
def navpoint_close
<
WOK
end
def navmap_close
<
WOK
end
self
end
def metadata_opf #(i) metadata dc; (ii) manifest (contents); (iii) spine (mimetypes)
def structure
package_open
metadata_open
metadata_close
manifest_open
manifest_close
spine_open
spine_close
guide_open
guide_close
package_close
end
def package_open
<
WOK
end
def package_close
<
WOK
end
def metadata #metadata dc
author=if defined? @md.creator.author \
and @md.creator.author =~/\S+/
m=''
@md.creator.author_detail.each do |x|
surname=x[:the] \
? x[:the] \
: ''
other_names=x[:others] \
? ', ' + x[:others] \
: ''
m=(m.empty?) \
? (surname + other_names) \
: (m + '; ' + surname + ', ' + other_names)
m.gsub!(/,'<'); m.gsub!(/>/,'>')
m.gsub!(/<br(?: \/)?>/,';')
end
x=@md.creator.author.dup
x.gsub!(/,'<'); x.gsub!(/>/,'>')
x.gsub!(/<br(?: \/)?>/,'
')
%{\n #{x}}
else ''
end
editor=if defined? @md.creator.editor \
and @md.creator.editor =~/\S+/
m=''
@md.creator.editor_detail.each do |x|
surname=x[:the] \
? x[:the] \
: ''
other_names=x[:others] \
? ', ' + x[:others] \
: ''
m=(m.empty?) \
? (surname + other_names) \
: (m + '; ' + surname + ', ' + other_names)
m.gsub!(/,'<'); m.gsub!(/>/,'>')
m.gsub!(/<br(?: \/)?>/,';')
end
x=@md.creator.editor.dup
x.gsub!(/,'<'); x.gsub!(/>/,'>')
x.gsub!(/<br(?: \/)?>/,'
')
%{\n #{x}}
else ''
end
translator=if defined? @md.creator.translator \
and @md.creator.translator =~/\S+/
m=''
@md.creator.translator_detail.each do |x|
surname=x[:the] \
? x[:the] \
: ''
other_names=x[:others] \
? ', ' + x[:others] \
: ''
m=(m.empty?) \
? (surname + other_names) \
: (m + '; ' + surname + ', ' + other_names)
m.gsub!(/,'<'); m.gsub!(/>/,'>')
m.gsub!(/<br(?: \/)?>/,';')
end
x=@md.creator.translator.dup
x.gsub!(/,'<'); x.gsub!(/>/,'>')
x.gsub!(/<br(?: \/)?>/,'
')
%{\n #{x}}
else ''
end
illustrator=if defined? @md.creator.illustrator \
and @md.creator.illustrator =~/\S+/
m=''
@md.creator.illustrator_detail.each do |x|
surname=x[:the] \
? x[:the] \
: ''
other_names=x[:others] \
? ', ' + x[:others] \
: ''
m=(m.empty?) \
? (surname + other_names) \
: (m + '; ' + surname + ', ' + other_names)
m.gsub!(/,'<'); m.gsub!(/>/,'>')
m.gsub!(/<br(?: \/)?>/,';')
end
x=@md.creator.illustrator.dup
x.gsub!(/,'<'); x.gsub!(/>/,'>')
x.gsub!(/<br(?: \/)?>/,'
')
%{\n #{x}}
else ''
end
date_published=if defined? @md.date.published \
and @md.date.published =~/\S+/
x=@md.date.published.dup
x.gsub!(/,'<'); x.gsub!(/>/,'>')
x.gsub!(/<br(?: \/)?>/,'
')
%{\n #{x}}
else ''
end
subject=if defined? @md.classify.subject \
and @md.classify.subject =~/\S+/
x=@md.classify.subject.dup
x.gsub!(/,'<'); x.gsub!(/>/,'>')
x.gsub!(/<br(?: \/)?>/,'
')
%{\n #{x}}
else ''
end
language=if defined? @md.opt.lng \
and @md.opt.lng =~/\S+/
language=@md.opt.lng.gsub(/
/,'
')
%{\n #{language}}
else ''
end
rights=if defined? @md.rights.all \
and @md.rights.all =~/\S+/
rights=@md.rights.all.gsub(/
/,'
')
%{\n #{rights}}
else ''
end
f=SiSU_Env::SiSU_file.new(@md)
<
#{@md.title.full}
#{author}#{editor}#{translator}#{illustrator}#{language}#{date_published}#{subject}#{rights}
#{f.output_path.epub.url}/#{f.base_filename.epub}
urn:uuid:#{@md.dgst[1]}
WOK
end
def manifest_open
<
WOK
end
def manifest_content_sisu_toc
<
WOK
end
def manifest_content(dob)
<
WOK
end
def manifest_images(imgs)
imgs=imgs + ['arrow_next_red.png','arrow_prev_red.png','arrow_up_red.png','bullet_09.png']
images=[" \n"]
imgs.each do |i|
image,type=/(\S+?)\.(png|jpg|gif)/.match(i)[1,2]
images<<<
WOK
end
images=images.join('')
images
end
def manifest_close
<
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
end
def spine_sisu_toc
<
WOK
end
def spine(dob)
<
WOK
end
def spine_close
<
WOK
end
def guide_open
#guide: presentation order of XHTML files by reader).
<
WOK
end
def guide_sisu_toc
<
WOK
end
def guide(dob)
<
WOK
end
def guide_close
<
WOK
end
self
end
def toc_head_escript
end
def seg_head_escript
end
def table_close
%{
#{@vz.table_close}}
end
def buttons_home
%{
#{@vz.banner_home_and_index_buttons}
}
end
def copyat
%{copy @
#{@vz.txt_home}
}
end
def xhtml_close
%{#{@vz.credits_sisu_epub}