From ff824c5c3d36f278e3050b171293e04c22b7356e Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 23 Jan 2013 23:48:09 -0500 Subject: v4 v3: epub, epub_format, provide full depth epub table of contents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [request Mikael Böök] --- lib/sisu/v3/epub.rb | 48 +++++++++++++++++++---- lib/sisu/v3/epub_format.rb | 9 +++-- lib/sisu/v4/epub.rb | 95 +++++++++++++++++++++++++++++++--------------- lib/sisu/v4/epub_format.rb | 38 +++++++++++-------- 4 files changed, 133 insertions(+), 57 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v3/epub.rb b/lib/sisu/v3/epub.rb index c51a7656..fdb1398f 100644 --- a/lib/sisu/v3/epub.rb +++ b/lib/sisu/v3/epub.rb @@ -199,7 +199,7 @@ module SiSU_EPUB @@toc={ seg: [], seg_mini: [], scr: [], ncx: [], opf: [] } md_opf_a_content,md_opf_a_spine,md_opf_a_guide=[],[],[] @nav_no=0 - @s_a_no,@s_b_no,@s_c_no=0,0,0 + @s_a_no,@s_b_no,@s_c_no,@lv5_no,@lv6_no=0,0,0,0,0 @@toc[:ncx] << @epub.toc_ncx.open #epub ncx navmap @@toc[:ncx] << @epub.toc_ncx.head_open << @epub.toc_ncx.head << @epub.toc_ncx.head_close @@toc[:ncx] << @epub.toc_ncx.doc_title << @epub.toc_ncx.doc_author @@ -228,11 +228,13 @@ module SiSU_EPUB name_s_a='section_a' + @s_a_no.to_s @nav_no+=1 @nav_no2=@nav_no + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[1] - @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4]=true,false,false,false + @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false,false,false @epub.sections(dob_toc,name_s_a) @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,name_s_a) if dob_toc if @level_a_first_occurrence \ @@ -250,10 +252,12 @@ module SiSU_EPUB name_s_b='section_b' + @s_b_no.to_s @nav_no+=1 @nav_no2=@nav_no + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] - @ncxo[2],@ncxo[3],@ncxo[4]=true,false,false + @ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false,false @epub.sections(dob_toc,name_s_b) @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,name_s_b) if dob_toc md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,name_s_b) @@ -265,9 +269,11 @@ module SiSU_EPUB name_s_c='section_c' + @s_c_no.to_s @nav_no+=1 @nav_no3=@nav_no + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] - @ncxo[3],@ncxo[4]=true,false + @ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false @epub.sections(dob_toc,name_s_c) @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,name_s_c) if dob_toc md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,name_s_c) @@ -277,15 +283,39 @@ module SiSU_EPUB when 4 @ncx_cls=[] @nav_no+=1 + @dob_name=dob.name + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] - @ncxo[4]=true + @ncxo[4],@ncxo[5],@ncxo[6]=true,false,false @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no) if dob_toc md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc) md_opf_a_spine << @epub.metadata_opf.spine(dob_toc) md_opf_a_guide << @epub.metadata_opf.guide(dob_toc) SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_4 - when 5; SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_5 - when 6; SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_6 + when 5 + @ncx_cls=[] + name_lv5=@dob_name + '.xhtml' + '#o' + dob_toc.ocn.to_s + @nav_no+=1 + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @ncxo[5],@ncxo[6]=true,false + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,name_lv5) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,name_lv5) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,name_lv5) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,name_lv5) + SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_5 + when 6 + @ncx_cls=[] + name_lv6=@dob_name + '.xhtml' + '#o' + dob_toc.ocn.to_s + @nav_no+=1 + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @ncxo[6]=true + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,name_lv6) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,name_lv6) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,name_lv6) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,name_lv6) + SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_6 else nil end toc.each do |k,d| @@ -308,10 +338,12 @@ module SiSU_EPUB end end end + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] - @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4]=false,false,false,false + @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=false,false,false,false,false,false md_opf_a_content << @epub.metadata_opf.manifest_images(@md.ec[:image]) @@toc[:seg] << "\n" @@toc[:scr] << "\n" diff --git a/lib/sisu/v3/epub_format.rb b/lib/sisu/v3/epub_format.rb index ee5118e2..38717359 100644 --- a/lib/sisu/v3/epub_format.rb +++ b/lib/sisu/v3/epub_format.rb @@ -1398,6 +1398,7 @@ output_epub_cont_seg.close end def navpoint(dob,no,name=nil) name=name ? name : dob.name + cont_name=(name =~/#{Sfx[:epub_xhtml]}/) ? name : (name + Sfx[:epub_xhtml]) id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \ ? '' : "-#{no}" @@ -1406,7 +1407,7 @@ output_epub_cont_seg.close #{dob.obj} - + WOK end def navpoint_close @@ -1592,8 +1593,9 @@ output_epub_cont_seg.close end def manifest_content(dob,name=nil) name=name ? name : dob.name + href_name=(name =~/#{Sfx[:epub_xhtml]}/) ? name : (name + Sfx[:epub_xhtml]) <<-WOK - + WOK end def manifest_images(imgs) @@ -1648,8 +1650,9 @@ output_epub_cont_seg.close end def guide(dob,name=nil) name=name ? name : dob.name + guide_name=(name =~/#{Sfx[:epub_xhtml]}/) ? name : (name + Sfx[:epub_xhtml]) <<-WOK - + WOK end def guide_close diff --git a/lib/sisu/v4/epub.rb b/lib/sisu/v4/epub.rb index d2d5cc6c..1af5ec49 100644 --- a/lib/sisu/v4/epub.rb +++ b/lib/sisu/v4/epub.rb @@ -197,7 +197,7 @@ module SiSU_EPUB @@toc={ seg: [], seg_mini: [], scr: [], ncx: [], opf: [] } md_opf_a_content,md_opf_a_spine,md_opf_a_guide=[],[],[] @nav_no=0 - @s_a_no,@s_b_no,@s_c_no=0,0,0 + @s_a_no,@s_b_no,@s_c_no,@lv5_no,@lv6_no=0,0,0,0,0 @@toc[:ncx] << @epub.toc_ncx.open #epub ncx navmap @@toc[:ncx] << @epub.toc_ncx.head_open << @epub.toc_ncx.head << @epub.toc_ncx.head_close @@toc[:ncx] << @epub.toc_ncx.doc_title << @epub.toc_ncx.doc_author @@ -230,67 +230,100 @@ module SiSU_EPUB toc=case dob_toc.ln when 1 @s_a_no +=1 - name_s_a='section_a' + @s_a_no.to_s + lv_name='section_a' + @s_a_no.to_s @nav_no+=1 @nav_no2=@nav_no + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[1] - @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4]=true,false,false,false - @epub.sections(dob_toc,name_s_a) - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,name_s_a) if dob_toc + @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false,false,false + @epub.sections(dob_toc,lv_name) + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc if @level_a_first_occurrence \ && @make.build.toc? @nav_no+=1 @@toc[:ncx] << @epub.toc_ncx.navmap_sisu_toc(@nav_no) #epub ncx navmap, toc @level_a_first_occurrence=false end - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,name_s_a) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,name_s_a) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,name_s_a) + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_1 when 2 @s_b_no +=1 - name_s_b='section_b' + @s_b_no.to_s + lv_name='section_b' + @s_b_no.to_s @nav_no+=1 @nav_no2=@nav_no + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] - @ncxo[2],@ncxo[3],@ncxo[4]=true,false,false - @epub.sections(dob_toc,name_s_b) - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,name_s_b) if dob_toc - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,name_s_b) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,name_s_b) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,name_s_b) + @ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false,false + @epub.sections(dob_toc,lv_name) + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_2 when 3 @s_c_no +=1 - name_s_c='section_c' + @s_c_no.to_s + lv_name='section_c' + @s_c_no.to_s @nav_no+=1 @nav_no3=@nav_no + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] - @ncxo[3],@ncxo[4]=true,false - @epub.sections(dob_toc,name_s_c) - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,name_s_c) if dob_toc - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,name_s_c) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,name_s_c) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,name_s_c) + @ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false + @epub.sections(dob_toc,lv_name) + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_3 when 4 @ncx_cls=[] + lv_name=dob_toc.name @nav_no+=1 + @dob_name=dob.name + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] - @ncxo[4]=true - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no) if dob_toc - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc) + @ncxo[4],@ncxo[5],@ncxo[6]=true,false,false + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_4 - when 5; SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_5 - when 6; SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_6 + when 5 + @ncx_cls=[] + hashtag='#o' + dob_toc.ocn.to_s + lv_name=@dob_name + @nav_no+=1 + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @ncxo[5],@ncxo[6]=true,false + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name,hashtag) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name,hashtag) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name,hashtag) + SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_5 + when 6 + @ncx_cls=[] + hashtag='#o' + dob_toc.ocn.to_s + lv_name=@dob_name + @nav_no+=1 + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @ncxo[6]=true + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name,hashtag) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name,hashtag) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name,hashtag) + SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_6 else nil end toc.each do |k,d| @@ -313,10 +346,12 @@ module SiSU_EPUB end end end + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] - @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4]=false,false,false,false + @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=false,false,false,false,false,false md_opf_a_content << @epub.metadata_opf.manifest_images(@md.ec[:image]) @@toc[:seg] << "\n" @@toc[:scr] << "\n" diff --git a/lib/sisu/v4/epub_format.rb b/lib/sisu/v4/epub_format.rb index 60c40dea..84d32000 100644 --- a/lib/sisu/v4/epub_format.rb +++ b/lib/sisu/v4/epub_format.rb @@ -1287,10 +1287,10 @@ application/epub+zip 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} @@ -1396,8 +1396,9 @@ output_epub_cont_seg.close 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}" @@ -1593,7 +1594,7 @@ output_epub_cont_seg.close end def manifest_content_sisu_toc <<-WOK - + WOK end def manifest_cover_image_information(md) @@ -1606,10 +1607,11 @@ output_epub_cont_seg.close else '' end end - def manifest_content(dob,name=nil) - name=name ? name : dob.name + def manifest_content(dob,fn_base,hashtag=nil) + fn=fn_base + Sfx[:epub_xhtml] + name=hashtag ? fn + hashtag : fn <<-WOK - + WOK end def manifest_images(imgs) @@ -1643,11 +1645,12 @@ output_epub_cont_seg.close end def spine_sisu_toc <<-WOK - + WOK end - def spine(dob,name=nil) - name=name ? name : dob.name + def spine(dob,fn_base,hashtag=nil) + fn=fn_base + Sfx[:epub_xhtml] + name=hashtag ? fn + hashtag : fn <<-WOK WOK @@ -1670,13 +1673,16 @@ output_epub_cont_seg.close end def guide_sisu_toc <<-WOK - + 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 + guide_name=(name =~/#{Sfx[:epub_xhtml]}/) ? name : (name + Sfx[:epub_xhtml]) <<-WOK - + WOK end def guide_close -- cgit v1.2.3