From 563195c124e66bc1e571e08c574a6107af7eb1c3 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Thu, 20 Nov 2014 23:03:49 -0500 Subject: d: epub, reorganize, introduce new file --- data/doc/sisu/CHANGELOG_v6 | 2 + lib/sisu/develop/xhtml.rb | 10 +- lib/sisu/develop/xhtml_epub2.rb | 182 ++++++++-------- lib/sisu/develop/xhtml_epub2_format.rb | 7 +- lib/sisu/develop/xhtml_epub2_persist.rb | 278 ++++++++++++++++++++++++ lib/sisu/develop/xhtml_epub2_segments.rb | 351 ++++++++++++++++++------------- 6 files changed, 583 insertions(+), 247 deletions(-) create mode 100644 lib/sisu/develop/xhtml_epub2_persist.rb diff --git a/data/doc/sisu/CHANGELOG_v6 b/data/doc/sisu/CHANGELOG_v6 index 6a45a761..5eaa8f1a 100644 --- a/data/doc/sisu/CHANGELOG_v6 +++ b/data/doc/sisu/CHANGELOG_v6 @@ -73,6 +73,8 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_6.4.0.orig.tar.xz * html, segments, reorganize, introduce new file + * epub, reorganize, introduce new file + ** SiSU "UnFrozen" - prior to end of Debian Freeze (upstream bugfix 6.3.2 (5.7.2) intended for Jessie (packaged for Debian as 5.7.1-2) was not accepted) diff --git a/lib/sisu/develop/xhtml.rb b/lib/sisu/develop/xhtml.rb index ca015c02..bb5db51b 100644 --- a/lib/sisu/develop/xhtml.rb +++ b/lib/sisu/develop/xhtml.rb @@ -440,11 +440,11 @@ WOK 'check document structure' ).colorize tell=SiSU_Screen::Ansi.new( - @md.opt.act[:color_state][:set], - 'invert', - '', - '' - ) + @md.opt.act[:color_state][:set], + 'invert', + '', + '' + ) tell.grey_open end tidyfile='/dev/null' #don't want one or screen output, check for alternative flags diff --git a/lib/sisu/develop/xhtml_epub2.rb b/lib/sisu/develop/xhtml_epub2.rb index edfb6e62..b595b00d 100644 --- a/lib/sisu/develop/xhtml_epub2.rb +++ b/lib/sisu/develop/xhtml_epub2.rb @@ -73,6 +73,7 @@ module SiSU_XHTML_EPUB2 require_relative 'xhtml_epub2_tune' # xhtml_epub2_tune.rb include SiSU_XHTML_EPUB2_Tune require_relative 'xhtml_epub2_concordance' # xhtml_epub2_concordance.rb + require_relative 'xhtml_epub2_persist' # xhtml_epub2_persist.rb class Source def initialize(opt) @opt=opt @@ -124,9 +125,9 @@ module SiSU_XHTML_EPUB2 SiSU_Env::FileOp.new(@md).mkdir.output.epub @tuned_file_array=SiSU_XHTML_EPUB2::Source::XHTML_Environment.new(@particulars).tuned_file_instructions data=@tuned_file_array - toc=SiSU_XHTML_EPUB2::Source::Toc.new(@md,data).songsheet + per=SiSU_XHTML_EPUB2::Source::Toc.new(@md,data).songsheet data=@tuned_file_array - SiSU_XHTML_EPUB2::Source::ScrollHeadAndSegToc.new(@md,toc).in_common #watch + SiSU_XHTML_EPUB2::Source::ScrollHeadAndSegToc.new(@md,per).in_common #watch SiSU_XHTML_EPUB2::Source::Seg.new(@md,data).songsheet SiSU_XHTML_EPUB2::Source::Output.new(@md).songsheet rescue @@ -144,11 +145,10 @@ module SiSU_XHTML_EPUB2 end end SiSU_Env::Clear.new(@opt.selections.str,@opt.fns).param_instantiate - @@flag,@@scr,@@seg,@@seg_endnotes,@@seg_subtoc,@@seg_ad={},{},{},{},{},{} - @@seg_total,@@tracker,@@loop_count,@@tablehead,@@number_of_cols=0,0,0,0,0 - @@seg_name,@@seg_name_html,@@seg_subtoc_array,@@seg_endnotes_array,@@segtocband,@@tablefoot=Array.new(7){[]} - @@filename_seg,@@seg_url,@@fn,@@to_lev4,@@get_hash_to,@@get_hash_fn='','','','','','','' - @@is4=@@is3=@@is2=@@is1=@@heading1=@@heading2=@@heading3=@@heading4=0 + @@flag,@@scr,@@seg,@@seg_endnotes,@@seg_subtoc={},{},{},{},{} + @@tracker=0 + @@seg_name,@@seg_name_html,@@seg_subtoc_array,@@seg_endnotes_array,@@tablefoot=Array.new(5){[]} + @@filename_seg,@@seg_url,@@to_lev4,@@get_hash_to,@@get_hash_fn='','','','','' end end private @@ -202,7 +202,6 @@ module SiSU_XHTML_EPUB2 end end class Toc - @@toc={ seg: [], seg_mini: [], scr: [], ncx: [], opf: [] } @@seg_url='' @@firstseg=nil def initialize(md=nil,data='') @@ -210,6 +209,7 @@ module SiSU_XHTML_EPUB2 @epub=SiSU_XHTML_EPUB2_Format::HeadInformation.new(@md) @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) if @md @make=SiSU_Env::ProcessingSettings.new(@md) + @per=SiSU_XHTML_EPUB2_Persist::PersistTOC.new end def songsheet #extracts toc for scroll & seg if (@md.opt.act[:verbose][:set]==:on \ @@ -222,19 +222,19 @@ module SiSU_XHTML_EPUB2 end toc=nil @@firstseg=nil - @@toc={ seg: [], seg_mini: [], scr: [], ncx: [], opf: [] } + SiSU_XHTML_EPUB2_Persist::PersistTOC.new.persist_init md_opf_a_content,md_opf_a_spine,md_opf_a_guide=[],[],[] @nav_no=0 @s_a_no,@s_b_no,@s_c_no,@s_d_no,@lv5_no,@lv6_no=0,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 - @@toc[:ncx] << @epub.toc_ncx.navmap_open - @@toc[:opf] << @epub.metadata_opf.package_open - @@toc[:opf] << @epub.metadata_opf.metadata - @@toc[:opf] << @epub.metadata_opf.manifest_open - @@toc[:seg] << %{
\n
} - @@toc[:scr] << %{
\n
} + @per.ncx << @epub.toc_ncx.open #epub ncx navmap + @per.ncx << @epub.toc_ncx.head_open << @epub.toc_ncx.head << @epub.toc_ncx.head_close + @per.ncx << @epub.toc_ncx.doc_title << @epub.toc_ncx.doc_author + @per.ncx << @epub.toc_ncx.navmap_open + @per.opf << @epub.metadata_opf.package_open + @per.opf << @epub.metadata_opf.metadata + @per.opf << @epub.metadata_opf.manifest_open + @per.seg << %{
\n
} + @per.scr << %{
\n
} if defined? @md.make.cover_image \ and @md.make.cover_image.is_a?(Hash) \ and @md.make.cover_image[:cover] =~/\S+/ @@ -261,24 +261,24 @@ module SiSU_XHTML_EPUB2 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[7] - @@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] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[0] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[5] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[4] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[3] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[2] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[1] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[0] @ncxo[0],@ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6],@ncxo[7]= true, false, false, false, false, false, false, false @epub.sections(dob_toc,lv_name) if @level_a_first_occurrence \ && @make.build.toc? - @@toc[:ncx] << @epub.toc_ncx.navmap_sisu_toc(@nav_no) #epub ncx navmap, toc + @per.ncx << @epub.toc_ncx.navmap_sisu_toc(@nav_no) #epub ncx navmap, toc @nav_no+=1 @level_a_first_occurrence=false end - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc + @per.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) @@ -288,17 +288,17 @@ module SiSU_XHTML_EPUB2 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[7] - @@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] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[5] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[4] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[3] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[2] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[1] @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6],@ncxo[7]= true, false, 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 + @per.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) @@ -308,16 +308,16 @@ module SiSU_XHTML_EPUB2 lv_name='section_c' + @s_c_no.to_s @nav_no+=1 @nav_no2=@nav_no - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[7] - @@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] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[5] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[4] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[3] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[2] @ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6],@ncxo[7]= 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 + @per.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) @@ -327,15 +327,15 @@ module SiSU_XHTML_EPUB2 lv_name='section_d' + @s_d_no.to_s @nav_no+=1 @nav_no3=@nav_no - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[7] - @@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] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[5] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[4] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[3] @ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6],@ncxo[7]= 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 + @per.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) @@ -345,13 +345,13 @@ module SiSU_XHTML_EPUB2 lv_name=dob_toc.name @nav_no+=1 @dob_name=dob.name - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[7] - @@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] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[5] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[4] @ncxo[4],@ncxo[5],@ncxo[6],@ncxo[7]= true, false, false, false - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc + @per.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) @@ -361,12 +361,12 @@ module SiSU_XHTML_EPUB2 hashtag='#o' + dob_toc.ocn.to_s lv_name=@dob_name @nav_no+=1 - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[7] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[5] @ncxo[5],@ncxo[6],@ncxo[7]= true, false, false - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc + @per.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) @@ -376,11 +376,11 @@ module SiSU_XHTML_EPUB2 hashtag='#o' + dob_toc.ocn.to_s lv_name=@dob_name @nav_no+=1 - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[7] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6] @ncxo[6],@ncxo[7]= true, false - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc + @per.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) @@ -390,9 +390,9 @@ module SiSU_XHTML_EPUB2 hashtag='#o' + dob_toc.ocn.to_s lv_name=@dob_name @nav_no+=1 - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[7] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7] @ncxo[7]=true - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc + @per.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) @@ -409,8 +409,8 @@ module SiSU_XHTML_EPUB2 end if toc begin - @@toc[:seg] << toc[:seg] - @@toc[:scr] << toc[:seg] + @per.seg << toc[:seg] + @per.scr << toc[:seg] rescue SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do __LINE__.to_s + ':' + __FILE__ @@ -419,28 +419,28 @@ module SiSU_XHTML_EPUB2 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] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[1] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[0] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[5] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[4] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[3] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[2] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[1] + @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[0] @ncxo[0],@ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=false,false,false,false,false,false,false md_opf_a_content << @epub.metadata_opf.manifest_images(@md.ec[:image]) - @@toc[:seg] << "
\n
" - @@toc[:scr] << "
\n
" - @@toc[:ncx] << @epub.toc_ncx.navmap_close - @@toc[:ncx] << @epub.toc_ncx.close - @@toc[:opf] << md_opf_a_content << @epub.metadata_opf.manifest_close - @@toc[:opf] << @epub.metadata_opf.spine_open << md_opf_a_spine << @epub.metadata_opf.spine_close - @@toc[:opf] << @epub.metadata_opf.guide_open << md_opf_a_guide << @epub.metadata_opf.guide_close - @@toc[:opf] << @epub.metadata_opf.package_close - @@toc[:opf]=@@toc[:opf].flatten - SiSU_XHTML_EPUB2::Source::Output.new(@md,@@toc[:opf]).epub_metadata_opf - SiSU_XHTML_EPUB2::Source::Output.new(@md,@@toc[:ncx]).epub_toc_ncx + @per.seg << "
\n
" + @per.scr << "
\n
" + @per.ncx << @epub.toc_ncx.navmap_close + @per.ncx << @epub.toc_ncx.close + @per.opf << md_opf_a_content << @epub.metadata_opf.manifest_close + @per.opf << @epub.metadata_opf.spine_open << md_opf_a_spine << @epub.metadata_opf.spine_close + @per.opf << @epub.metadata_opf.guide_open << md_opf_a_guide << @epub.metadata_opf.guide_close + @per.opf << @epub.metadata_opf.package_close + @per.opf=@per.opf.flatten + SiSU_XHTML_EPUB2::Source::Output.new(@md,@per.opf).epub_metadata_opf + SiSU_XHTML_EPUB2::Source::Output.new(@md,@per.ncx).epub_toc_ncx @md.firstseg=@@firstseg - @@toc + @per end protected def level_0 @@ -454,7 +454,7 @@ module SiSU_XHTML_EPUB2 toc[:seg]=format_toc.lev1 title=if dob.ocn ==0 then linkname else - @@toc[:scr] << '
' + @per.scr << '
' link=(dob.ln) \ ? dob.ln : '' @@ -490,7 +490,7 @@ module SiSU_XHTML_EPUB2 else linkname end else - @@toc[:scr] << '
' + @per.scr << '
' link=(dob.ln) \ ? dob.ln : '' @@ -636,8 +636,8 @@ module SiSU_XHTML_EPUB2 end end class ScrollHeadAndSegToc < Toc - def initialize(md='',toc='',links_guide_toc='') - @md,@toc,@links_guide_toc=md,toc,links_guide_toc + def initialize(md='',per='',links_guide_toc='') + @md,@per,@links_guide_toc=md,per,links_guide_toc end def in_common toc_shared=[] @@ -699,9 +699,9 @@ module SiSU_XHTML_EPUB2 toc_shared << prefix_b end #Table of Contents added/appended here - toc_shared << @toc[:scr] + toc_shared << @per.scr segtoc << @links_guide_toc - segtoc << @toc[:seg] + segtoc << @per.seg if defined? @md.rights.all \ and @md.rights.all segtoc << rights @@ -716,7 +716,7 @@ module SiSU_XHTML_EPUB2 SiSU_XHTML_EPUB2::Source::Output.new(@md).make_cover_image SiSU_XHTML_EPUB2::Source::Output.new(@md,segtoc).make_segtoc segtoc=[] - @toc[:scr],@toc[:seg]=[],[] + @per.scr,@per.seg=[],[] toc_shared end end diff --git a/lib/sisu/develop/xhtml_epub2_format.rb b/lib/sisu/develop/xhtml_epub2_format.rb index e4d4ac0f..54c79434 100644 --- a/lib/sisu/develop/xhtml_epub2_format.rb +++ b/lib/sisu/develop/xhtml_epub2_format.rb @@ -1251,8 +1251,9 @@ module SiSU_XHTML_EPUB2_Format @md=md # DublinCore 1 - title @css=SiSU_Env::CSS_Stylesheet.new(md) - @seg_name_xhtml=(SiSU_XHTML_EPUB2::Source::Seg.new.seg_name_xhtml || []) - @seg_name_xhtml_tracker=(SiSU_XHTML_EPUB2::Source::Seg.new.seg_name_xhtml_tracker || []) + @per=SiSU_XHTML_EPUB2_Persist::Persist.new + @per.seg_name_x=SiSU_XHTML_EPUB2::Seg.new.seg_name_x + @per.seg_name_x_tracker=SiSU_XHTML_EPUB2::Seg.new.seg_name_x_tracker @tocband_scroll,@tocband_segtoc=nil,nil @index,@metalink='index','#metadata' end @@ -1827,7 +1828,7 @@ output_epub_cont_seg.close %{#{doc_type} - #{@seg_name_xhtml[@seg_name_xhtml_tracker]} - + #{@per.seg_name_x[@per.seg_name_x_tracker]} - #{@md.html_title} diff --git a/lib/sisu/develop/xhtml_epub2_persist.rb b/lib/sisu/develop/xhtml_epub2_persist.rb new file mode 100644 index 00000000..889cd1a3 --- /dev/null +++ b/lib/sisu/develop/xhtml_epub2_persist.rb @@ -0,0 +1,278 @@ +# encoding: utf-8 +=begin + +* Name: SiSU + +** Description: documents, structuring, processing, publishing, search +*** html segment generation, processing + +** Author: Ralph Amissah + + + +** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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: + + + +** Git + + + +=end +module SiSU_XHTML_EPUB2_Persist + class Persist + @@persist=nil + attr_accessor :is0,:is1,:is2,:is3,:is4,:heading0,:heading1,:heading2,:heading3,:heading4, :title, :nav, :tocband_banner, :tocband_bannerless, :headings, :heading_endnotes, :main, :endnote_all, :tail, :credits, :heading_idx, :idx, :seg_endnotes, :seg_endnotes_array, :closed, :get_hash_fn, :get_hash_to, :seg_subtoc, :seg_subtoc_array, :fn, :seg_name ,:seg_name_x,:seg_name_x_tracker + def initialize(args=nil) + @@persist=args=(args ? args : (@@persist || persist_init_hash_values)) + @is0=args[:is0] + @is1=args[:is1] + @is2=args[:is2] + @is3=args[:is3] + @is4=args[:is4] + @heading0=args[:heading0] + @heading1=args[:heading1] + @heading2=args[:heading2] + @heading3=args[:heading3] + @heading4=args[:heading4] + @title=args[:title] + @nav=args[:nav] + @tocband_banner=args[:tocband_banner] + @tocband_bannerless=args[:tocband_bannerless] + @headings=args[:headings] + @heading_endnotes=args[:heading_endnotes] + @main=args[:main] + @endnote_all=args[:endnote_all] + @tail=args[:tail] + @credits=args[:credits] + #@heading_idx=args[:heading_idx] + @idx=args[:idx] + @seg_endnotes=args[:seg_endnotes] + @seg_endnotes_array=args[:seg_endnotes_array] + @closed=args[:closed] + @get_hash_to=args[:get_hash_to] + @get_hash_fn=args[:get_hash_fn] + @seg_subtoc=args[:seg_subtoc] + @seg_subtoc_array=args[:seg_subtoc_array] + @fn=args[:fn] + @seg_name=args[:seg_name] + @seg_name_x=args[:seg_name_x] + @seg_name_x_tracker=args[:seg_name_x_tracker] + end + def is0 + @is0 + end + def is1 + @is1 + end + def is2 + @is2 + end + def is3 + @is3 + end + def is4 + @is4 + end + def heading0 + @heading0 + end + def heading1 + @heading1 + end + def heading2 + @heading2 + end + def heading3 + @heading3 + end + def heading4 + @heading4 + end + def title + @title + end + def nav + @nav + end + def tocband_banner + @tocband_banner + end + def tocband_bannerless + @tocband_bannerless + end + def headings + @headings + end + def heading_endnotes + @heading_endnotes + end + def main + @main + end + def endnote_all + @endnote_all + end + def tail + @tail + end + def credits + @credits + end + def heading_idx + @heading_idx + end + def idx + @idx + end + def seg_endnotes + @seg_endnotes + end + def seg_endnotes_array + @seg_endnotes_array + end + def closed + @closed + end + def get_hash_to + @get_hash_to + end + def get_hash_fn + @get_hash_fn + end + def seg_subtoc + @seg_subtoc + end + def seg_subtoc_array + @seg_subtoc_array + end + def fn + @fn + end + def seg_name + @seg_name + end + def seg_name_x + @seg_name_x + end + def seg_name_x_tracker + @seg_name_x_tracker + end + def persist_init_hash_values + { + is0: 0, + is1: 0, + is2: 0, + is3: 0, + is4: 0, + heading0: '', + heading1: '', + heading2: '', + heading3: '', + heading4: '', + tocband_banner: [], + tocband_bannerless: [], + title: [], + nav: [], + headings: [], + main: [], + idx: [], + tail: [], + credits: [], + endnote_all: [], + heading_endnotes: '', + seg_endnotes: {}, + seg_endnotes_array: [], + closed: [], + get_hash_fn: '', + get_hash_to: '', + seg_subtoc: {}, + seg_subtoc_array: [], + fn: '', + seg_name: [], + seg_name_x: [], + seg_name_x_tracker: 0, + } + end + def persist_init + @@persist=nil + Persist.new(persist_init_hash_values) + end + end + class PersistTOC + @@persist=nil + attr_accessor :seg,:seg_mini,:scr,:ncx,:opf + def initialize(args=nil) + @@persist=args=(args ? args : (@@persist || persist_init_hash_values)) + @seg=args[:seg] + @seg_mini=args[:seg_mini] + @scr=args[:scr] + @ncx=args[:ncx] + @opf=args[:opf] + end + def seg + @seg + end + def seg_mini + @seg_mini + end + def scr + @scr + end + def ncx + @ncx + end + def opf + @opf + end + def persist_init_hash_values + { + seg: [], + seg_mini: [], + scr: [], + ncx: [], + opf: [], + } + end + def persist_init + @@persist=nil + PersistTOC.new(persist_init_hash_values) + end + end +end +__END__ diff --git a/lib/sisu/develop/xhtml_epub2_segments.rb b/lib/sisu/develop/xhtml_epub2_segments.rb index 867f9f31..b3ce33b0 100644 --- a/lib/sisu/develop/xhtml_epub2_segments.rb +++ b/lib/sisu/develop/xhtml_epub2_segments.rb @@ -57,37 +57,60 @@ module SiSU_XHTML_EPUB2_Seg require_relative 'xhtml_shared' # xhtml_shared.rb require_relative 'xhtml_epub2' # xhtml_epub2.rb + require_relative 'xhtml_epub2_persist' # xhtml_epub2_persist.rb require_relative 'shared_metadata' # shared_metadata.rb class Output - def initialize(md,outputfile,seg,type='') - @md,@output_epub_cont_seg,@seg,@type=md,outputfile,seg,type + def initialize(md,outputfile,per,type='') + @md, @output_epub_cont_seg,@per,@type= + md,outputfile, per, type end - def output #CONSIDER - if @seg[:title] =~/\S/ + def output + if @per.title =~/\S/ filename_seg=[] - filename_seg << @seg[:title] << @seg[:nav] + filename_seg \ + << @per.title \ + << @per.nav if @type=='endnotes' - @seg[:headings]=[] #watch + @per.headings=[] #watch txt_obj={ txt: 'Endnotes', ocn_display: ''} format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) - @seg[:headings] << format_seg.title_heading1 - filename_seg << @seg[:heading_endnotes] << @seg[:headings] << %{\n
\n} << @seg[:endnote_all] << '
' + @per.headings \ + << format_seg.title_heading1 + filename_seg \ + << @per.heading_endnotes \ + << @per.headings \ + << %{\n
\n} \ + << @per.endnote_all \ + << '
' elsif @type=='idx' - @seg[:headings]=[] + @per.headings=[] txt_obj={ txt: 'Index', ocn_display: ''} format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) - @seg[:headings] << format_seg.title_heading1 - filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
\n} << @seg[:idx] << '
' + @per.headings << format_seg.title_heading1 + filename_seg \ + << @per.heading_idx \ + << @per.headings \ + << %{\n
\n} \ + << @per.idx \ + << '
' elsif @type=='metadata' metadata=SiSU_Metadata::Summary.new(@md).xhtml_display.metadata - @seg[:headings]=[] + @per.headings=[] txt_obj={ txt: 'Metadata', ocn_display: ''} format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) - @seg[:headings] << format_seg.title_heading1 - filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
\n} << metadata << '
' + @per.headings \ + << format_seg.title_heading1 + filename_seg \ + << @per.heading_idx \ + << @per.headings \ + << %{\n
\n} \ + << metadata \ + << '
' elsif @type=='sisu_manifest' env=SiSU_Env::InfoEnv.new(@md.fns) - path_and_name,url_and_name="#{env.path.output}/#{@md.fnb}/sisu_manifest.html","#{env.url.root}/#{@md.fnb}/sisu_manifest.html" + path_and_name,url_and_name= \ + "#{env.path.output}/#{@md.fnb}/sisu_manifest.html", + "#{env.url.root}/#{@md.fnb}/sisu_manifest.html" manifest=if FileTest.file?("#{path_and_name}")==true <A list of available output types may be available at the following url:

@@ -95,19 +118,32 @@ module SiSU_XHTML_EPUB2_Seg WOK else '' end - @seg[:headings]=[] + @per.headings=[] txt_obj={ txt: 'Manifest', ocn_display: ''} format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) - @seg[:headings] << format_seg.title_heading1 - filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
\n} << manifest << '
' + @per.headings \ + << format_seg.title_heading1 + filename_seg \ + << @per.heading_idx \ + << @per.headings \ + << %{\n
\n} \ + << manifest \ + << '
' else - filename_seg << @seg[:headings] << @seg[:main] << "\n\n" + filename_seg \ + << @per.headings \ + << @per.main \ + << "\n\n" end - filename_seg << @seg[:tail] << @seg[:nav] << @seg[:close] + filename_seg \ + << @per.tail \ + << @per.nav \ + << @per.closed filename_seg=filename_seg.flatten.compact #watch filename_seg.each do |str| unless str =~/\A\s*\Z/ - @output_epub_cont_seg << str.strip + @output_epub_cont_seg \ + << str.strip end end @output_epub_cont_seg.close @@ -115,68 +151,68 @@ WOK end end class Seg - @@seg,@@seg_subtoc,@@seg_endnotes,@@seg_ad={},{},{},{} - @@seg_name,@@seg_name_xhtml=[],[] - @@seg_url=@@fn=@@get_hash_to=@@get_hash_fn='' - @@loop_count=@@seg_total=@@tracker=0 - @@is4=@@is3=@@is2=@@is1=@@is0=0 - @@heading0=@@heading1=@@heading2=@@heading3=@@heading4=0 - @@seg[:headings],@@seg[:main],@@seg[:idx],@@seg[:tail],@@seg_subtoc_array,@@seg_endnotes_array,@@seg[:endnote_all]=Array.new(7){[]} - @@seg[:heading_endnotes]='' - @@tablehead,@@number_of_cols=0,0 - @@fns_previous='' - attr_reader :seg_name_xhtml,:seg_name_xhtml_tracker + @@seg_name=[] + @@seg_url='' + @@tracker=0 + attr_reader :seg_name_x,:seg_name_x_tracker def initialize(md='',data='') @md,@data=md,data - @seg_name_xhtml=@@seg_name_xhtml || nil - @seg_name_xhtml_tracker=@@tracker || nil + @per=SiSU_XHTML_EPUB2_Persist::Persist.new + @seg_name_x=@per.seg_name_x=(@@seg_name || []) + @seg_name_x_tracker=@per.seg_name_x_tracker=(@@tracker || 0) @make=SiSU_Env::ProcessingSettings.new(@md) if @md end def songsheet begin - data=get_subtoc_endnotes(@data) - data=articles(data) - SiSU_XHTML_EPUB2_Seg::Seg.new.cleanup # (((( added )))) + SiSU_XHTML_EPUB2_Persist::Persist.new.persist_init + data=get_subtoc_endnotes(@data,@per) + data=articles(data,@per) + SiSU_XHTML_EPUB2_Seg::Seg.new.cleanup(@md,@per) # (((( added )))) #### (((( END )))) #### rescue SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do __LINE__.to_s + ':' + __FILE__ end ensure - @@seg_name=[] + @@seg_name=@per.seg_name=[] end end protected - def articles(data) + def articles(data,per) + @per=per tracking,newfile=0,0 - @@is4=@@is3=@@is2=@@is1=@@is0=0 printed_endnote_seg='n' idx_xhtml=nil if @md.book_idx - idx_xhtml=SiSU_Particulars::CombinedSingleton.instance.get_idx_xhtml(@md).xhtml_idx - idx_xhtml.each {|x| @@seg[:idx] << x } - @@seg[:heading_idx]='' + idx_xhtml=SiSU_Particulars::CombinedSingleton. + instance.get_idx_xhtml(@md).xhtml_idx + idx_xhtml.each do |x| + @per.idx << x + end + @per.heading_idx='' end data.each do |dob| - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==4 + if (dob.is == :heading \ + || dob.is == :heading_insert) \ + && dob.ln == 4 @@seg_name << dob.name + @per.seg_name = @@seg_name dob.name end end - @@seg_name_xhtml=@@seg_name - @@seg_total=@@seg_name.length - testforartnum=@@seg_name_xhtml + @per.seg_name_x=@per.seg_name + @per.seg_name.length + testforartnum=@per.seg_name_x if (@md.opt.act[:verbose][:set]==:on \ || @md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on) SiSU_Screen::Ansi.new( @md.opt.act[:color_state][:set], - @@seg_name.length + @per.seg_name.length ) end - SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags + SiSU_Particulars::CombinedSingleton. + instance.get_map_nametags(@md).nametags_map #p map_nametags data.each do |dob| #if defined? dob.obj \ #and dob.obj =~/href="#{Xx[:segment]}#+\S+?"/ @@ -194,41 +230,41 @@ WOK if (dob.is==:heading \ || dob.is==:heading_insert) \ && dob.ln==4 - @@heading4=dob.obj - @@is4=newfile=1 + @per.heading4=dob.obj + @per.is4=newfile=1 end if (dob.is==:heading \ || dob.is==:heading_insert) \ && dob.ln==3 - @@heading3=dob.obj - @@is4,@@is3=0,1 + @per.heading3=dob.obj + @per.is4,@per.is3=0,1 end if (dob.is==:heading \ || dob.is==:heading_insert) \ && dob.ln==2 - @@heading2=dob.obj - @@is4,@@is3,@@is2=0,0,1 + @per.heading2=dob.obj + @per.is4,@per.is3,@per.is2=0,0,1 end if (dob.is==:heading \ || dob.is==:heading_insert) \ && dob.ln==1 - @@heading1=dob.obj - @@is4,@@is3,@@is2,@@is1=0,0,0,1 + @per.heading1=dob.obj + @per.is4,@per.is3,@per.is2,@per.is1=0,0,0,1 end if (dob.is==:heading \ || dob.is==:heading_insert) \ && dob.ln==0 - @@heading0=dob.obj - @@is4,@@is3,@@is2,@@is1,@@is0=0,0,0,0,1 + @per.heading0=dob.obj + @per.is4,@per.is3,@per.is2,@per.is1,@per.is0=0,0,0,0,1 end - if (@@is0 && !@@is1 && !@@is2 && !@@is3 && !@@is4) + if (@per.is0 && !@per.is1 && !@per.is2 && !@per.is3 && !@per.is4) if not (dob.is==:heading \ || dob.is==:heading_insert) \ && dob.ln==0 $_ #; check end end - if @@is4==1 + if @per.is4==1 dir_epub_cont="#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}" if newfile==1 \ or dob.obj =~/^#{Mx[:br_endnotes]}|^#{Mx[:br_eof]}/ @@ -237,34 +273,36 @@ WOK || dob.is==:heading_insert) \ && dob.ln==4 if tracking != 0 - SiSU_XHTML_EPUB2_Seg::Seg.new(@md).tail - segfilename="#{dir_epub_cont}/#{@@seg_name_xhtml[tracking-1]}#{Sfx[:epub_xhtml]}" - output_epub_cont_seg=File.new(segfilename,'w') if @@seg_name_xhtml[tracking-1] + tail(@md,@per) + #SiSU_XHTML_EPUB2_Seg::Seg.new(@md,@per).tail + segfilename="#{dir_epub_cont}/#{@per.seg_name_x[tracking-1]}#{Sfx[:epub_xhtml]}" + output_epub_cont_seg=File.new(segfilename,'w') if @per.seg_name_x[tracking-1] if dob.is==:heading \ - or @@seg_name_xhtml[tracking-1] !~/endnotes|book_index|metadata/ - SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg).output + or @per.seg_name_x[tracking-1] !~/endnotes|book_index|metadata/ + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@per).output elsif dob.is==:heading_insert - if @@seg_name_xhtml[tracking-1]=='endnotes' - SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'endnotes').output - elsif @@seg_name_xhtml[tracking-1]=='book_index' - SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'idx').output - @@seg[:idx]=[] - elsif @@seg_name_xhtml[tracking-1]=='metadata' # navigation bug FIX - SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'metadata').output + if @per.seg_name_x[tracking-1]=='endnotes' + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@per,'endnotes').output + elsif @per.seg_name_x[tracking-1]=='book_index' + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@per,'idx').output + @per.idx=[] + elsif @per.seg_name_x[tracking-1]=='metadata' # navigation bug FIX + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@per,'metadata').output else puts "#{__FILE__}::#{__LINE__}" end else puts "#{__FILE__}::#{__LINE__}" end - SiSU_XHTML_EPUB2_Seg::Seg.new.reinitialise + SiSU_XHTML_EPUB2_Seg::Seg.new.reinitialise(per) heading_art(dob) head(dob) - if @@seg_name_xhtml[tracking] =='metadata' - segfilename="#{dir_epub_cont}/#{@@seg_name_xhtml[tracking]}#{Sfx[:epub_xhtml]}" + if @per.seg_name_x[tracking] =='metadata' + segfilename="#{dir_epub_cont}/#{@per.seg_name_x[tracking]}#{Sfx[:epub_xhtml]}" output_epub_cont_seg=File.new(segfilename,'w') - SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'metadata').output - SiSU_XHTML_EPUB2_Seg::Seg.new.reinitialise #BUG navigation bug with items following metadata, and occurring before manifest, this becomes a bug ... work area for book index, FIX + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@per,'metadata').output + SiSU_XHTML_EPUB2_Seg::Seg.new.reinitialise(per) + #BUG navigation bug with items following metadata, and occurring before manifest, this becomes a bug ... work area for book index, FIX end - #@output_epub_cont_seg.close #%(((( EOF )))) --> + #@output_epub_cont_seg.closed #%(((( EOF )))) --> end if tracking==0 heading_art(dob) @@ -277,8 +315,8 @@ WOK || dob.is==:heading_insert) \ && dob.ln==4 \ && dob.name - @@get_hash_to=dob.name - @@get_hash_fn=dob.name + @per.get_hash_to=dob.name + @per.get_hash_fn=dob.name end if dob.obj.is_a?(String) markup(dob) @@ -297,51 +335,56 @@ WOK data end def heading_art(dob) - @@seg[:title]=SiSU_XHTML_EPUB2_Format::HeadSeg.new(@md).head + @per.title=SiSU_XHTML_EPUB2_Format::HeadSeg.new(@md).head end def head(dob) clean=/|<:.*?>$/ @p_num ||= '' - if @@is0==1 + if @per.is0==1 if defined? @md.creator.author \ and @md.creator.author @author=%{#{@md.creator.author}\n} end @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,dob.ocn) - txt_obj={ txt: @@heading0, ocn_display: @p_num.ocn_display } + txt_obj={ txt: @per.heading0, ocn_display: @p_num.ocn_display } format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) - @@seg[:headings] << format_seg.title_heading0.gsub(clean,'') - @@heading0=@@heading0.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') + @per.headings << format_seg.title_heading0.gsub(clean,'') + @per.heading0=@per.heading0. + gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') end - if @@is1==1 + if @per.is1==1 @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,dob.ocn) - txt_obj={ txt: @@heading1, ocn_display: @p_num.ocn_display } + txt_obj={ txt: @per.heading1, ocn_display: @p_num.ocn_display } format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) - @@seg[:headings] << format_seg.title_heading1.gsub(clean,'') - @@heading1=@@heading1.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') + @per.headings << format_seg.title_heading1.gsub(clean,'') + @per.heading1=@per.heading1. + gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') end - if @@is2==1 - heading2=@@heading2 + if @per.is2==1 + heading2=@per.heading2 @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,dob.ocn) txt_obj={ txt: heading2, ocn_display: @p_num.ocn_display } format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) - @@seg[:headings] << format_seg.title_heading2.gsub(clean,'') - @@heading2=@@heading2.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') + @per.headings << format_seg.title_heading2.gsub(clean,'') + @per.heading2=@per.heading2. + gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') end - if @@is3==1 - heading3=@@heading3 + if @per.is3==1 + heading3=@per.heading3 @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,dob.ocn) txt_obj={ txt: heading3, ocn_display: @p_num.ocn_display } format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) - @@seg[:headings] << format_seg.title_heading3.gsub(clean,'') - @@heading3=@@heading3.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') + @per.headings << format_seg.title_heading3.gsub(clean,'') + @per.heading3=@per.heading3. + gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') end - if @@is4==1 - heading4=@@heading4 + if @per.is4==1 + heading4=@per.heading4 @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,dob.ocn) txt_obj={ txt: heading4, ocn_display: @p_num.ocn_display } format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) - @@seg[:headings] << format_seg.title_heading4.gsub(clean,'') + @per.headings \ + << format_seg.title_heading4.gsub(clean,'') end @@tracker=@@tracker+1 end @@ -400,7 +443,9 @@ WOK sto.break end if @md.flag_separate_endnotes # may need to revisit, check - dob.obj=dob.obj.gsub(/"\s+href="##{Mx[:note_ref]}(\d+)">/,%{" href=\"endnotes#{Sfx[:epub_xhtml]}##{Mx[:note_ref]}\\1">}) #endnote- twice #removed file type + dob.obj=dob.obj.gsub(/"\s+href="##{Mx[:note_ref]}(\d+)">/, + %{" href=\"endnotes#{Sfx[:epub_xhtml]}##{Mx[:note_ref]}\\1">}) + #endnote- twice #removed file type end if (dob.is ==:heading \ || dob.is==:heading_insert \ @@ -411,77 +456,82 @@ WOK if (dob.is==:heading \ || dob.is==:heading_insert \ || dob.is==:para) \ - and dob.note_ #dob.obj =~/  \n} - @@seg[:main] << dob_xhtml + @per.main << %{\n
\n} + @per.main << dob_xhtml if @make.build.segsubtoc? - @@seg[:main] << @@seg_subtoc[@@get_hash_fn] #% insertion of sub-toc + @per.main << @per.seg_subtoc[@per.get_hash_fn] + #% insertion of sub-toc end else - @@seg[:main] << dob_xhtml + @per.main << dob_xhtml end end - def tail + def tail(md,per) + @md,@per=md,per format_head_seg=SiSU_XHTML_EPUB2_Format::HeadSeg.new(@md) if @md.flag_auto_endnotes \ - and @@seg_endnotes[@@get_hash_fn] - @@seg[:tail] << %{\n
\n
\n} - if @@seg_endnotes[@@get_hash_fn].flatten.length > 0 - @@seg[:tail] << format_head_seg.endnote_mark - @@seg[:tail] << @@seg_endnotes[@@get_hash_fn].flatten #endnotes deposited at end of individual segments ||@|EXTRACTION OF ENDNOTES| + and @per.seg_endnotes[@per.get_hash_fn] + @per.tail << %{\n
\n
\n} + if @per.seg_endnotes[@per.get_hash_fn].flatten.length > 0 + @per.tail << format_head_seg.endnote_mark + @per.tail << @per.seg_endnotes[@per.get_hash_fn].flatten + #endnotes deposited at end of individual segments ||@|EXTRACTION OF ENDNOTES| end - @@seg[:tail] << '
' - @@seg[:tail] << '
' #this div closes div class content + @per.tail << '
' + @per.tail << '
' #this div closes div class content end - @@seg[:close]=[] - @@seg[:close] << format_head_seg.xhtml_close + @per.closed=[] + @per.closed << format_head_seg.xhtml_close end - def reinitialise - @@seg[:headings],@@seg[:main],@@seg[:tail],@@seg[:credits]=Array.new(4){[]} + def reinitialise(per) + per.headings,per.main,per.tail,per.credits=Array.new(4){[]} end - def cleanup - reinitialise - @@seg_total,@@tracker=0,0 - @@seg_endnotes,@@seg_subtoc={},{} - @@seg_endnotes_array,@@seg_subtoc_array=[],[] - @@seg[:endnote_all]=[] + def cleanup(md,per) + reinitialise(per) + @@tracker=0 + @per.seg_endnotes,@per.seg_subtoc={},{} + @per.seg_endnotes_array,@per.seg_subtoc_array=[],[] + per.endnote_all=[] end - def get_subtoc_endnotes(data) #get endnotes & sub-table of contents subtoc + def get_subtoc_endnotes(data,per) #get endnotes & sub-table of contents subtoc + @per=per data.each do |dob| dob.obj=dob.obj.gsub(/
(.+?)<\/a>/mi,'\1') if @md.flag_auto_endnotes if (dob.is==:heading \ || dob.is==:heading_insert) \ - and dob.ln.to_s =~/^[1234]/ \ - and not @@fn.to_s.empty? - @@seg_endnotes[@@fn]=[] - @@seg_endnotes[@@fn] << @@seg_endnotes_array - @@seg_endnotes_array=[] if dob.ln==4 - @@fns_previous=@md.fns if dob.ln==4 and dob.name =~/^meta/ + && dob.ln.to_s =~/^[1-4]/ \ + and not @per.fn.to_s.empty? + @per.seg_endnotes[@per.fn]=[] + @per.seg_endnotes[@per.fn] << @per.seg_endnotes_array + @per.seg_endnotes_array=[] if dob.ln==4 end if (dob.is==:heading \ || dob.is==:heading_insert) \ - and dob.ln==4 #% EXTRACTION OF SUB-TOCs & SEGMENT NAME, after EXTRACTION OF ENDNOTES & SUB-TOCs - @@seg_subtoc[@@fn]=@@seg_subtoc_array - @@seg_subtoc_array=[] + && dob.ln==4 + #% EXTRACTION OF SUB-TOCs & SEGMENT NAME, after EXTRACTION OF ENDNOTES & SUB-TOCs + @per.seg_subtoc[@per.fn]=@per.seg_subtoc_array + @per.seg_subtoc_array=[] if dob.name \ and dob.obj - @@fn=dob.name + @per.fn=dob.name else - @@fn=(dob.name =~/\S+/) \ + @per.fn=(dob.name =~/\S+/) \ ? dob.name : '' end end end if dob.is==:heading \ - and dob.ln.to_s =~/^[5-7]/ + && dob.ln.to_s =~/^[5-7]/ case dob.ln when 5 format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,dob) @@ -493,7 +543,7 @@ WOK format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,dob) subtoc=format_seg.subtoc_lev7 #keep and make available, this is the subtoc end - @@seg_subtoc_array << subtoc + @per.seg_subtoc_array << subtoc end if @md.flag_auto_endnotes ast,pls='*','+' @@ -504,17 +554,19 @@ WOK endnote_array << dob.obj.scan(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/m) end if dob.obj=~/#{Mx[:en_b_o]}#{ast}\d+\s.+?#{Mx[:en_b_c]}/m - endnote_array << dob.obj.scan(/#{Mx[:en_b_o]}#{ast}\d+\s.+?#{Mx[:en_b_c]}/m) + endnote_array \ + << dob.obj.scan(/#{Mx[:en_b_o]}#{ast}\d+\s.+?#{Mx[:en_b_c]}/m) end if dob.obj=~/#{Mx[:en_b_o]}#{pls}\d+\s.+?#{Mx[:en_b_c]}/m - endnote_array << dob.obj.scan(/#{Mx[:en_b_o]}#{pls}\d+\s.+?#{Mx[:en_b_c]}/m) + endnote_array \ + << dob.obj.scan(/#{Mx[:en_b_o]}#{pls}\d+\s.+?#{Mx[:en_b_c]}/m) end endnote_array=endnote_array.flatten #.compact #check compacting endnote_array.each do |note| note_match=note.dup note_match_seg=note.dup e_n=note_match_seg[/(?:#{Mx[:en_a_o]}(?:\d|#{ast}|#{pls})+|#{Mx[:en_b_o]}(?:#{ast}|#{pls})\d+)\s+(.+?)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m,1] - try=e_n.split(/
/) + try=e_n.split(//) try.each do |e| txt_obj={ txt: e } format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) @@ -522,17 +574,20 @@ WOK format_seg.endnote_body_indent else format_seg.endnote_body end - @@seg_endnotes_array << note_match + @per.seg_endnotes_array << note_match end try.join('
') #% creation of separate end segment/page of all endnotes referenced back to reference segment m=/(?:#{Mx[:en_a_o]}(?:\d|#{ast}|#{pls})+|#{Mx[:en_b_o]}(?:#{ast}|#{pls})\d+)\s+(.+?href=")(##{Mx[:note_ref]}(?:\d|_a|_b)+".+)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/mi endnote_part_a=note_match_seg[m,1] endnote_part_b=note_match_seg[m,2] - txt_obj={ endnote_part_a: endnote_part_a, endnote_part_b: endnote_part_b } + txt_obj={ + endnote_part_a: endnote_part_a, + endnote_part_b: endnote_part_b + } format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) - note_match_all_seg=format_seg.endnote_seg_body(@@fn) #BUG WATCH 200408 - @@seg[:endnote_all] << note_match_all_seg + note_match_all_seg=format_seg.endnote_seg_body(@per.fn) #BUG WATCH 200408 + @per.endnote_all << note_match_all_seg end dob.obj=dob.obj.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') end -- cgit v1.2.3