class SiSU_XHTML_EPUB2_Seg::Seg
Attributes
seg_name_x[R]
seg_name_x_tracker[R]
Public Class Methods
new(md='',data='')
click to toggle source
# File lib/sisu/xhtml_epub2_segments.rb, line 156 def initialize(md='',data='') @md,@data=md,data @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
Public Instance Methods
songsheet()
click to toggle source
# File lib/sisu/xhtml_epub2_segments.rb, line 163 def songsheet begin 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 SiSU_XHTML_EPUB2_Persist::Persist.new.persist_init @@seg_name=@per.seg_name=[] end end
Protected Instance Methods
articles(data,per)
click to toggle source
# File lib/sisu/xhtml_epub2_segments.rb, line 179 def articles(data,per) @per=per tracking,newfile=0,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 do |x| @per.idx << x end @per.heading_idx='' end data.each do |dob| if (dob.is == :heading \ || dob.is == :heading_insert) \ && dob.ln == 4 @@seg_name << dob.name @per.seg_name = @@seg_name dob.name end end @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], @per.seg_name.length ) end 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+?"/ # ##Consider: remove, reinstate earlier? # #while dob.obj =~/href="#{Xx[:segment]}#+(\S+?)"/ # # m=$1 # # if map_nametags[m][:segname] # # dob.obj=dob.obj.sub(/href="#{Xx[:segment]}#+(\S+?)"/,%{href="#{map_nametags[m][:segname]}#{Sfx[:html]}#\\1"}) # # else # # p "NOT FOUND name_tags: #{m}" # # dob.obj=dob.obj.sub(/href="#{Xx[:segment]}#+(\S+?)"/,%{href="#\\1"}) # not satisfactory # # end # #end #end if (dob.is==:heading \ || dob.is==:heading_insert) \ && dob.ln==4 @per.heading4=dob.obj @per.is4=newfile=1 end if (dob.is==:heading \ || dob.is==:heading_insert) \ && dob.ln==3 @per.heading3=dob.obj @per.is4,@per.is3=0,1 end if (dob.is==:heading \ || dob.is==:heading_insert) \ && dob.ln==2 @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 @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 @per.heading0=dob.obj @per.is4,@per.is3,@per.is2,@per.is1,@per.is0=0,0,0,0,1 end 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 @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]}/ newfile=0 if (dob.is==:heading \ || dob.is==:heading_insert) \ && dob.ln==4 if tracking != 0 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 @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 @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(per) heading_art(dob) head(dob) 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,@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.closed #%(((( EOF )))) --> end if tracking==0 heading_art(dob) head(dob) end end tracking=tracking+1 end if (dob.is==:heading \ || dob.is==:heading_insert) \ && dob.ln==4 \ && dob.name @per.get_hash_to=dob.name @per.get_hash_fn=dob.name end if dob.obj.is_a?(String) markup(dob) elsif dob.obj.is_a?(Array) dob.obj.each do |pg| markup(pg) end end if testforartnum[tracking-1] =~/endnote/ if printed_endnote_seg=='n' printed_endnote_seg='y' end end end end data end
cleanup(md,per)
click to toggle source
# File lib/sisu/xhtml_epub2_segments.rb, line 495 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
get_subtoc_endnotes(data,per)
click to toggle source
# File lib/sisu/xhtml_epub2_segments.rb, line 502 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 name=\"h\d.*?\">(.+?)<\/a>/mi,'\1') if @md.flag_auto_endnotes if (dob.is==:heading \ || dob.is==:heading_insert) \ && 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) \ && 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 @per.fn=dob.name else @per.fn=(dob.name =~/\S+/) \ ? dob.name : '' end end end if dob.is==:heading \ && dob.ln.to_s =~/^[5-7]/ case dob.ln when 5 format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,dob) subtoc=format_seg.subtoc_lev5 #keep and make available, this is the subtoc when 6 format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,dob) subtoc=format_seg.subtoc_lev6 #keep and make available, this is the subtoc when 7 format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,dob) subtoc=format_seg.subtoc_lev7 #keep and make available, this is the subtoc end @per.seg_subtoc_array << subtoc end if @md.flag_auto_endnotes ast,pls='*','+' if dob.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(?:\d|#{ast}|#{pls})+ / \ and dob.is !=:code # endnote- endnote_array=[] if dob.obj=~/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/m 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) 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) 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(/<br(?: \/)?>/) try.each do |e| txt_obj={ txt: e } format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) note_match=if e =~/#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}/ format_seg.endnote_body_indent else format_seg.endnote_body end @per.seg_endnotes_array << note_match end try.join('<br \/>') #% 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 } format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) 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 end end end
head(dob)
click to toggle source
# File lib/sisu/xhtml_epub2_segments.rb, line 338 def head(dob) clean=/<!.*?!>|<:.*?>$/ @p_num ||= '' if @per.is0==1 if defined? @md.creator.author \ and @md.creator.author @author=%{<b>#{@md.creator.author}</b>\n} end @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,dob.ocn) txt_obj={ txt: @per.heading0, ocn_display: @p_num.ocn_display } format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) @per.headings << format_seg.title_heading0.gsub(clean,'') @per.heading0=@per.heading0. gsub(/#{$ep[:hsp]}<a name="-[\d*+]+" href="#_[\d*+]+">#{$ep[:hsp]}<sup>[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') end if @per.is1==1 @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,dob.ocn) txt_obj={ txt: @per.heading1, ocn_display: @p_num.ocn_display } format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) @per.headings << format_seg.title_heading1.gsub(clean,'') @per.heading1=@per.heading1. gsub(/#{$ep[:hsp]}<a name="-[\d*+]+" href="#_[\d*+]+">#{$ep[:hsp]}<sup>[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') end 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) @per.headings << format_seg.title_heading2.gsub(clean,'') @per.heading2=@per.heading2. gsub(/#{$ep[:hsp]}<a name="-[\d*+]+" href="#_[\d*+]+">#{$ep[:hsp]}<sup>[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') end 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) @per.headings << format_seg.title_heading3.gsub(clean,'') @per.heading3=@per.heading3. gsub(/#{$ep[:hsp]}<a name="-[\d*+]+" href="#_[\d*+]+">#{$ep[:hsp]}<sup>[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') end 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) @per.headings \ << format_seg.title_heading4.gsub(clean,'') end @@tracker=@@tracker+1 end
heading_art(dob)
click to toggle source
# File lib/sisu/xhtml_epub2_segments.rb, line 335 def heading_art(dob) @per.title=SiSU_XHTML_EPUB2_Format::HeadSeg.new(@md).head end
markup(dob)
click to toggle source
# File lib/sisu/xhtml_epub2_segments.rb, line 389 def markup(dob) @debug=[] if dob.is ==:heading \ || dob.is ==:heading_insert \ || dob.is ==:para #extend as necessary FIX @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,dob.ocn) end sto=SiSU_XHTML_EPUB2_Format::FormatTextObject.new(@md,dob) dob_xhtml=if dob.is==:heading \ || dob.is==:heading_insert \ || dob.is==:para dob_xhtml=if dob.is==:heading \ or dob.is==:heading_insert if dob.ln==4 sto.seg_heading4 # work on see SplitTextObject elsif dob.ln==5 sto.seg_heading5 elsif dob.ln==6 sto.seg_heading6 elsif dob.ln==7 sto.seg_heading7 end elsif dob.is==:para if dob.indent \ and dob.hang \ and dob.indent =~/[0-9]/ \ and dob.hang =~/[0-9]/ if dob.bullet_ (dob.indent =~/[1-9]/) \ ? sto.format('li',"i#{dob.indent}") : sto.format('li','bullet') elsif dob.indent == dob.hang sto.format('p',"i#{dob.indent}") elsif dob.indent != dob.hang sto.format('p',"h#{dob.hang}i#{dob.indent}") else sto.para end else sto.para end end elsif dob.is ==:block \ || dob.is ==:group \ || dob.is ==:alt sto.para #fix this should be block type specific #FIX elsif dob.is==:verse sto.verse elsif dob.is==:code sto.code elsif dob.is==:table sto.table elsif dob.is==:break 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 end if (dob.is ==:heading \ || dob.is==:heading_insert \ || dob.is==:para) \ && (not dob.ocn or dob.ocn.to_s.empty?) format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,dob) end if (dob.is==:heading \ || dob.is==:heading_insert \ || dob.is==:para) \ and dob.note_ #dob.obj =~/<a href="#note_ref\d+"> <sup id=/ #endnote- note- format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,dob) dob.obj=format_seg.no_paranum end if (dob.is==:heading \ || dob.is==:heading_insert) \ and dob.ln==4 @per.main << %{\n<div class="content">\n} @per.main << dob_xhtml if @make.build.segsubtoc? @per.main << @per.seg_subtoc[@per.get_hash_fn] #% insertion of sub-toc end else @per.main << dob_xhtml end end
reinitialise(per)
click to toggle source
# File lib/sisu/xhtml_epub2_segments.rb, line 492 def reinitialise(per) per.headings,per.main,per.tail,per.credits=Array.new(4){[]} end
tail(md,per)
click to toggle source
# File lib/sisu/xhtml_epub2_segments.rb, line 475 def tail(md,per) @md,@per=md,per format_head_seg=SiSU_XHTML_EPUB2_Format::HeadSeg.new(@md) if @md.flag_auto_endnotes \ and @per.seg_endnotes[@per.get_hash_fn] @per.tail << %{\n<div class="content">\n<div class="endnote">\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 @per.tail << '</div>' @per.tail << '</div>' #this div closes div class content end @per.closed=[] @per.closed << format_head_seg.xhtml_close end