From 5803430358cff957f500fa2dcf1e290eae95a748 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 23 Nov 2014 01:01:27 -0500 Subject: d: xmls, reorganize, introduce new file --- lib/sisu/develop/xhtml.rb | 98 ++++++++++++------------- lib/sisu/develop/xhtml_table.rb | 1 - lib/sisu/develop/xml_dom.rb | 94 ++++++++++++------------ lib/sisu/develop/xml_odf_odt.rb | 47 ++++++------ lib/sisu/develop/xml_odf_odt_format.rb | 2 +- lib/sisu/develop/xml_persist.rb | 126 +++++++++++++++++++++++++++++++++ lib/sisu/develop/xml_sax.rb | 123 ++++++++++++++++---------------- 7 files changed, 309 insertions(+), 182 deletions(-) create mode 100644 lib/sisu/develop/xml_persist.rb (limited to 'lib') diff --git a/lib/sisu/develop/xhtml.rb b/lib/sisu/develop/xhtml.rb index bb5db51b..9e06d7b2 100644 --- a/lib/sisu/develop/xhtml.rb +++ b/lib/sisu/develop/xhtml.rb @@ -63,10 +63,11 @@ module SiSU_XHTML include SiSU_XML_Munge require_relative 'xml_format' # xml_format.rb include SiSU_XML_Format + require_relative 'xml_persist' # xml_persist.rb require_relative 'rexml' # rexml.rb include SiSU_Rexml require_relative 'shared_metadata' # shared_metadata.rb - @@alt_id_count,@@tablehead,@@number_of_cols=0,0,0 + @@alt_id_count=0 @@tablefoot='' class Source def initialize(opt) @@ -144,12 +145,12 @@ module SiSU_XHTML require_relative 'txt_shared' # txt_shared.rb include SiSU_TextUtils require_relative 'css' # css.rb - @@xml={ body: [], sisu: [], open: [], close: [], head: [] } def initialize(particulars) @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array @tab="\t" @trans=SiSU_XML_Munge::Trans.new(@md) @sys=SiSU_Env::SystemCall.new + @per=SiSU_XML_Persist::Persist.new end def songsheet pre @@ -202,7 +203,7 @@ WOK end def xml_head metadata=SiSU_Metadata::Summary.new(@md).xhtml_scroll.metadata - @@xml[:head] << metadata + @per.head << metadata end def name_tags(dob) tags='' @@ -228,15 +229,15 @@ WOK gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'\1') util=SiSU_TextUtils::Wrap.new(dob.obj,70) wrapped=util.line_wrap - @@xml[:body] << if defined? dob.ocn + @per.body << if defined? dob.ocn %{#{Ax[:tab]*0}} else "#{Ax[:tab]*0}" end - @@xml[:body] << %{#{Ax[:tab]*1}#{named}\n#{Ax[:tab]*2}#{wrapped}\n#{Ax[:tab]*1}} unless lv # main text, contents, body KEEP - @@xml[:body] << %{#{Ax[:tab]*1}#{named}\n#{Ax[:tab]*2}#{wrapped}\n#{Ax[:tab]*1}} if lv # main text, contents, body KEEP - @@xml[:body] << @endnotes.compact.join if @endnotes.length > 0 # main text, endnotes KEEP - @@xml[:body] << "#{Ax[:tab]*1}#{dob.ocn}" if defined? dob.ocn - @@xml[:body] << "#{Ax[:tab]*0}" + @per.body << %{#{Ax[:tab]*1}#{named}\n#{Ax[:tab]*2}#{wrapped}\n#{Ax[:tab]*1}} unless lv # main text, contents, body KEEP + @per.body << %{#{Ax[:tab]*1}#{named}\n#{Ax[:tab]*2}#{wrapped}\n#{Ax[:tab]*1}} if lv # main text, contents, body KEEP + @per.body << @endnotes.compact.join if @endnotes.length > 0 # main text, endnotes KEEP + @per.body << "#{Ax[:tab]*1}#{dob.ocn}" if defined? dob.ocn + @per.body << "#{Ax[:tab]*0}" @endnotes=[] end end @@ -246,12 +247,12 @@ WOK dob.obj=dob.obj.strip. gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'\1'). #footnote/endnote clean gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'\1') #footnote/endnote clean - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*1}#{named}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*1}} - @@xml[:body] << "#{Ax[:tab]*0}" + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*1}#{named}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*1}} + @per.body << "#{Ax[:tab]*0}" end def group_structure(dob) named=name_tags(dob) @@ -259,42 +260,42 @@ WOK dob.obj=dob.obj.strip. gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'\1'). #footnote/endnote clean gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'\1') #footnote/endnote clean - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*1}#{named}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*1}} - @@xml[:body] << "#{Ax[:tab]*0}" + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*1}#{named}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*1}} + @per.body << "#{Ax[:tab]*0}" end def poem_structure(dob) named=name_tags(dob) dob=@trans.markup_group(dob) dob.obj=dob.obj.strip - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*1}#{named}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*1}} - @@xml[:body] << "#{Ax[:tab]*0}" + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*1}#{named}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*1}} + @per.body << "#{Ax[:tab]*0}" end def code_structure(dob) named=name_tags(dob) dob=@trans.markup_group(dob) dob.obj=dob.obj.gsub(/\s\s/,'  ').strip - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*1}#{named}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*1}} - @@xml[:body] << "#{Ax[:tab]*0}" + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*1}#{named}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*1}} + @per.body << "#{Ax[:tab]*0}" end def table_structure(dob) named=name_tags(dob) table=SiSU_XHTML_Shared::TableXHTML.new(dob) - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*2}#{named}#{table.table.obj}} - @@xml[:body] << "#{Ax[:tab]*0}" + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*2}#{named}#{table.table.obj}} + @per.body << "#{Ax[:tab]*0}" end def markup(data) @endnotes=[] @@ -370,39 +371,38 @@ WOK end 6.downto(4) do |x| y=x - 1; v=x - 3 - @@xml[:body] << "#{Ax[:tab]*5}\n#{Ax[:tab]*y}" if @level[x]==true + @per.body << "#{Ax[:tab]*5}\n#{Ax[:tab]*y}" if @level[x]==true end 3.downto(1) do |x| y=x - 1 - @@xml[:body] << "#{Ax[:tab]*y}" if @level[x]==true + @per.body << "#{Ax[:tab]*y}" if @level[x]==true end end def pre rdf=SiSU_XML_Tags::RDF.new(@md) - @@xml[:head],@@xml[:body]=[],[] + @per.head,@per.body=[],[] stylesheet=SiSU_Style::CSS_HeadInfo.new(@md,'xhtml').stylesheet encoding=(@sys.locale =~/utf-?8/i) \ ? '' : '' - @@xml[:open] =< WOK - @@xml[:head] << %{\n\t} - @@xml[:body] << '' + @per.head << %{\n\t} + @per.body << '' end def post - @@xml[:head] << '' - @@xml[:body] << '' - @@xml[:close] = '' + @per.head << '' + @per.body << '' + @per.close = '' end def publish content=[] - content << @@xml[:open] << @@xml[:head] << @@xml[:body] << @@xml[:metadata] - content << @@xml[:owner_details] if @md.stmp =~/\w\w/ - content << @@xml[:tail] << @@xml[:close] + content << @per.open << @per.head << @per.body << @per.metadata + content << @per.tail << @per.close content=content.flatten.compact Output.new(content,@md).xhtml @@xml={} diff --git a/lib/sisu/develop/xhtml_table.rb b/lib/sisu/develop/xhtml_table.rb index df5a2822..9c3618c5 100644 --- a/lib/sisu/develop/xhtml_table.rb +++ b/lib/sisu/develop/xhtml_table.rb @@ -58,7 +58,6 @@ module SiSU_XHTML_Table require_relative 'xhtml_parts' # xhtml_parts.rb class TableXHTML include SiSU_Parts_XHTML - @@tablehead=0 @@tablefoot=[] #watch def initialize(table) @table_obj=table diff --git a/lib/sisu/develop/xml_dom.rb b/lib/sisu/develop/xml_dom.rb index 3664820d..b3d3adde 100644 --- a/lib/sisu/develop/xml_dom.rb +++ b/lib/sisu/develop/xml_dom.rb @@ -64,10 +64,11 @@ module SiSU_XML_DOM include SiSU_XML_Munge require_relative 'xml_format' # xml_format.rb include SiSU_XML_Format + require_relative 'xml_persist' # xml_persist.rb require_relative 'rexml' # rexml.rb include SiSU_Rexml require_relative 'shared_metadata' # shared_metadata.rb - @@alt_id_count,@@tablehead,@@number_of_cols=0,0,0 + @@alt_id_count=0 @@tablefoot='' class Source def initialize(opt) @@ -158,12 +159,12 @@ module SiSU_XML_DOM require_relative 'txt_shared' # txt_shared.rb include SiSU_TextUtils require_relative 'xhtml_shared' # decide use, whether xml rather than xhtml - @@xml={ body: [], open: [], close: [], head: [], sc: [] } def initialize(particulars) @env, @md, @ao_arr= particulars.env,particulars.md,particulars.ao_array @trans=SiSU_XML_Munge::Trans.new(@md) @sys=SiSU_Env::SystemCall.new + @per=SiSU_XML_Persist::Persist.new end def songsheet pre @@ -182,7 +183,7 @@ module SiSU_XML_DOM end def xml_head metadata=SiSU_Metadata::Summary.new(@md).xml_dom.metadata - @@xml[:head] << metadata + @per.head << metadata end def xml_sc(md='') sc=if @md.sc_info @@ -204,7 +205,7 @@ module SiSU_XML_DOM WOK else '' end - @@xml[:sc]=sc + @per.sc=sc end def xml_element(dob,xml_el='',xml_content='',type='norm') n=n1=n2=n3=0 @@ -221,7 +222,7 @@ WOK else '' end xml_el ||='' - @@xml[:body] <<< #{Ax[:tab]*n2} @@ -262,26 +263,26 @@ WOK if @cont[1] \ or @cont[2] \ or @cont[3] - @@xml[:body] << "#{Ax[:tab]*5}" + @per.body << "#{Ax[:tab]*5}" end @cont[1]=false if @cont[1] @cont[2]=false if @cont[2] @cont[3]=false if @cont[3] ####### attempt to close contents if @copen[4] # 4~ - [4,3,2,1].each { |v| @@xml[:body] << "#{Ax[:tab]*n}" } + [4,3,2,1].each { |v| @per.body << "#{Ax[:tab]*n}" } @copen[1]=@copen[2]=@copen[3]=@copen[4]=false elsif @copen[3] # 3~ - [3,2,1].each { |v| @@xml[:body] << "#{Ax[:tab]*n}" } + [3,2,1].each { |v| @per.body << "#{Ax[:tab]*n}" } @copen[1]=@copen[2]=@copen[3]=false elsif @copen[2] # 2~ - [2,1].each { |v| @@xml[:body] << "#{Ax[:tab]*n}" } + [2,1].each { |v| @per.body << "#{Ax[:tab]*n}" } @copen[1]=@copen[2]=@copen[3]=false elsif @copen[1] # 1~ - [1].each { |v| @@xml[:body] << "#{Ax[:tab]*n}" } + [1].each { |v| @per.body << "#{Ax[:tab]*n}" } @copen[1]=@copen[2]=@copen[3]=false end - @@xml[:body] << "#{Ax[:tab]*y}" if @level[x] + @per.body << "#{Ax[:tab]*y}" if @level[x] @level[x]=false end when 4..7 @@ -295,29 +296,29 @@ WOK xml_content="\n#{Ax[:tab]*5}" case lv when 4 - @@xml[:body] << "#{Ax[:tab]*5}" if @cont[1] + @per.body << "#{Ax[:tab]*5}" if @cont[1] if @copen[4]==true # 4~ - [4,3,2,1].each { |v| @@xml[:body] << "#{Ax[:tab]*n}" } + [4,3,2,1].each { |v| @per.body << "#{Ax[:tab]*n}" } elsif @copen[3]==true # 3~ - [3,2,1].each { |v| @@xml[:body] << "#{Ax[:tab]*n}" } + [3,2,1].each { |v| @per.body << "#{Ax[:tab]*n}" } elsif @copen[2]==true # 2~ - [2,1].each { |v| @@xml[:body] << "#{Ax[:tab]*n}" } + [2,1].each { |v| @per.body << "#{Ax[:tab]*n}" } elsif @copen[1]==true # 1~ - [1].each { |v| @@xml[:body] << "#{Ax[:tab]*n}" } + [1].each { |v| @per.body << "#{Ax[:tab]*n}" } end @cont[1]=true when 5 if @cont[3] \ or @cont[2] \ or @cont[1] - @@xml[:body] << "#{Ax[:tab]*5}" + @per.body << "#{Ax[:tab]*5}" end if @copen[4]==true #4~ - [4,3,2].each { |v| @@xml[:body] << "#{Ax[:tab]*n}" } + [4,3,2].each { |v| @per.body << "#{Ax[:tab]*n}" } elsif @copen[3]==true #3~ - [3,2].each { |v| @@xml[:body] << "#{Ax[:tab]*n}" } + [3,2].each { |v| @per.body << "#{Ax[:tab]*n}" } elsif @copen[2]==true #2~ - [2].each { |v| @@xml[:body] << "#{Ax[:tab]*n}" } + [2].each { |v| @per.body << "#{Ax[:tab]*n}" } end @cont[2]=true when 6 @@ -325,12 +326,12 @@ WOK or @cont[3] \ or @cont[2] \ or @cont[1] - @@xml[:body] << "#{Ax[:tab]*5}" + @per.body << "#{Ax[:tab]*5}" end if @copen[4] #4~ - [4,3].each { |v| @@xml[:body] << "#{Ax[:tab]*n}" } + [4,3].each { |v| @per.body << "#{Ax[:tab]*n}" } elsif @copen[3] #3~ - [3].each { |v| @@xml[:body] << "#{Ax[:tab]*n}" } + [3].each { |v| @per.body << "#{Ax[:tab]*n}" } end @cont[3]=true when 7 @@ -338,10 +339,10 @@ WOK or @cont[3] \ or @cont[2] \ or @cont[1] - @@xml[:body] << "#{Ax[:tab]*5}" + @per.body << "#{Ax[:tab]*5}" end if @copen[4] #4~ - [4].each { |v| @@xml[:body] << "#{Ax[:tab]*n}" } + [4].each { |v| @per.body << "#{Ax[:tab]*n}" } end @cont[4]=true end @@ -357,15 +358,15 @@ WOK if defined? dob.obj # main text, contents, body KEEP if defined? dob.ocn \ and dob.ocn - @@xml[:body] << %{#{Ax[:tab]*6}} - @@xml[:body] << %{#{Ax[:tab]*7}#{dob.ocn}} if defined? dob.ocn + @per.body << %{#{Ax[:tab]*6}} + @per.body << %{#{Ax[:tab]*7}#{dob.ocn}} if defined? dob.ocn end - #@@xml[:body] << %{#{Ax[:tab]*7}#{dob.obj}} - #@@xml[:body] << %{#{Ax[:tab]*7}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*7}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*8}#{dob.obj}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*7}} - @@xml[:body] << %{#{Ax[:tab]*6}} + #@per.body << %{#{Ax[:tab]*7}#{dob.obj}} + #@per.body << %{#{Ax[:tab]*7}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*7}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*8}#{dob.obj}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*7}} + @per.body << %{#{Ax[:tab]*6}} end end def block_structure(dob) @@ -523,16 +524,16 @@ WOK y=x - 1; v=x - 3 if @level[x]==true #2004w36 bug fix? watch/test previous logic broke on free.for.all @coontent_flag introduced if @content_flag==true - @@xml[:body] << "#{Ax[:tab]*5}\n#{Ax[:tab]*y}" + @per.body << "#{Ax[:tab]*5}\n#{Ax[:tab]*y}" @content_flag=false else - @@xml[:body] << "\n#{Ax[:tab]*y}" + @per.body << "\n#{Ax[:tab]*y}" end end end 3.downto(1) do |x| y=x - 1 - @@xml[:body] << "#{Ax[:tab]*y}" if @level[x]==true + @per.body << "#{Ax[:tab]*y}" if @level[x]==true end end def pre @@ -541,29 +542,28 @@ WOK encoding=if @sys.locale =~/utf-?8/i then '' else '' end - @@xml[:open] =< WOK - @@xml[:head] << '' - @@xml[:body] << '' + @per.head << '' + @per.body << '' end def post - @@xml[:head] << @@xml[:sc] - @@xml[:head] << '' - @@xml[:body] << '' - @@xml[:close] = '' + @per.head << @per.sc + @per.head << '' + @per.body << '' + @per.close << '' end def publish content=[] - content << @@xml[:open] << @@xml[:head] << @@xml[:body] << @@xml[:metadata] - content << @@xml[:owner_details] if @md.stmp =~/\w\w/ - content << @@xml[:tail] << @@xml[:close] + content << @per.open << @per.head << @per.body # << @per.metadata + content << @per.tail << @per.close content=content.flatten.compact Output.new(content,@md).xml - @@xml[:head],@@xml[:body],@@xml[:tail]=[],[],[] # check whether should be nil + @per.head,@per.body,@per.tail=[],[],[] # check whether should be nil end end class Output diff --git a/lib/sisu/develop/xml_odf_odt.rb b/lib/sisu/develop/xml_odf_odt.rb index de1dde96..16a77e7a 100644 --- a/lib/sisu/develop/xml_odf_odt.rb +++ b/lib/sisu/develop/xml_odf_odt.rb @@ -67,7 +67,8 @@ module SiSU_XML_ODF_ODT require_relative 'txt_shared' # txt_shared.rb require_relative 'xml_shared' # xml_shared.rb include SiSU_XML_Munge - @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 + require_relative 'xml_persist' # xml_persist.rb + @@alt_id_count,@@alt_id_count=0,0 class Source begin require 'zlib' @@ -128,7 +129,6 @@ module SiSU_XML_ODF_ODT require_relative 'txt_shared' # txt_shared.rb include SiSU_Parts_XML @@img_count=0 - @@odf={ body: [], head: [], toc: [], metadata: [], tail: [], book_idx: [], endnotes: [] } @@docstart=true @@fns=nil def initialize(particulars) @@ -140,6 +140,7 @@ module SiSU_XML_ODF_ODT end def songsheet begin + @per=SiSU_XML_Persist::Persist.new pre @data=markup(@ao_array) publish @@ -187,18 +188,18 @@ module SiSU_XML_ODF_ODT end idx_arr << x.strip if x.is_a?(String) end - @@odf[:book_idx]=idx_arr.join + @per.book_idx=idx_arr.join end end def odf_metadata - @@odf[:metadata]=SiSU_Metadata::Summary.new(@md). + @per.metadata=SiSU_Metadata::Summary.new(@md). odf.metadata end def odf_tail manifest="#{@md.file.output_path.manifest.url}/#{@md.file.base_filename.manifest}" - @@odf[:tail] << %{Available document outputs:
<#{manifest}>
} - @@odf[:tail] << %{\nSiSU: <www.jus.uio.no/sisu> and <www.sisudoc.org>} - @@odf[:tail] << "\n" + @per.tail << %{Available document outputs:
<#{manifest}>
} + @per.tail << %{\nSiSU: <www.jus.uio.no/sisu> and <www.sisudoc.org>} + @per.tail << "\n" end def set_bookmark_tag(dob) SiSU_XML_ODF_ODT_Format::Tags.new.set_bookmark_tag(dob) @@ -616,26 +617,26 @@ module SiSU_XML_ODF_ODT end end if dob.is==:heading - @@odf[:body] << heading(dob,p_num).obj << break_line*2 + @per.body << heading(dob,p_num).obj << break_line*2 if SiSU_Env::ProcessingSettings.new(md).build.toc? if dob.lv =~/[A-D1]/i - @@odf[:toc] << toc(dob,p_num).obj + @per.toc << toc(dob,p_num).obj end end elsif dob.is ==:verse - @@odf[:body] << poem(dob,p_num).obj << break_line*2 + @per.body << poem(dob,p_num).obj << break_line*2 elsif dob.is==:group - @@odf[:body] << group(dob,p_num).obj << break_line*2 + @per.body << group(dob,p_num).obj << break_line*2 elsif dob.is==:block - @@odf[:body] << block(dob,p_num).obj << break_line*2 + @per.body << block(dob,p_num).obj << break_line*2 elsif dob.is==:code - @@odf[:body] << code(dob,p_num).obj << break_line*2 + @per.body << code(dob,p_num).obj << break_line*2 elsif dob.is==:table #elsif dob.obj =~ / ' content << - @@odf[:head] << - @@odf[:toc] << + @per.head << + @per.toc << br_pg << - @@odf[:body] << - @@odf[:book_idx] << + @per.body << + @per.book_idx << br_pg << - @@odf[:metadata] << - @@odf[:tail] + @per.metadata << + @per.tail SiSU_XML_ODF_ODT::Source::Output.new(content,@md,@env).odf @@odf={ head: [], toc: [], body: [], tail: [], book_idx: [], metadata: [] } end diff --git a/lib/sisu/develop/xml_odf_odt_format.rb b/lib/sisu/develop/xml_odf_odt_format.rb index 8bd83e09..efe5e733 100644 --- a/lib/sisu/develop/xml_odf_odt_format.rb +++ b/lib/sisu/develop/xml_odf_odt_format.rb @@ -162,7 +162,7 @@ module SiSU_XML_ODF_ODT_Format end end class Table - @@tablehead,@@table_counter=0,0 #reinitialise on new file + @@table_counter=0 @@tablefoot=[] #watch @@fns='' def initialize(md,dob,p_num) diff --git a/lib/sisu/develop/xml_persist.rb b/lib/sisu/develop/xml_persist.rb new file mode 100644 index 00000000..6fb52eba --- /dev/null +++ b/lib/sisu/develop/xml_persist.rb @@ -0,0 +1,126 @@ +# 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_XML_Persist + class Persist + @@persist=nil + attr_accessor :head,:toc,:body,:tail,:open,:close,:sc,:endnotes,:book_idx,:metadata + #attr_accessor :head,:body,:tail,:open,:close,:sc +#@@odf={ body: [], head: [], toc: [], metadata: [], tail: [], book_idx: [], endnotes: [] } + def initialize(args=nil) + @@persist=args=(args ? args : (@@persist || persist_init_hash_values)) + @head=args[:head] + @toc=args[:toc] + @body=args[:body] + @tail=args[:tail] + @open=args[:open] + @close=args[:close] + @sc=args[:sc] + @endnotes=args[:endnotes] + @book_idx=args[:book_idx] + @metadata=args[:metadata] + end + def head + @head + end + def toc + @toc + end + def body + @body + end + def tail + @tail + end + def open + @open + end + def close + @close + end + def sc + @sc + end + def endnotes + @endnotes + end + def book_idx + @book_idx + end + def metadata + @metadata + end + def persist_init_hash_values + { + head: [], + toc: [], + body: [], + tail: [], + open: [], + close: [], + sc: [], + endnotes: [], + book_idx: [], + metadata: [], + } + end + def persist_init + @@persist=nil + Persist.new(persist_init_hash_values) + end + end +end +__END__ diff --git a/lib/sisu/develop/xml_sax.rb b/lib/sisu/develop/xml_sax.rb index 3a193a6a..81e2423d 100644 --- a/lib/sisu/develop/xml_sax.rb +++ b/lib/sisu/develop/xml_sax.rb @@ -63,10 +63,11 @@ module SiSU_XML_SAX include SiSU_XML_Munge require_relative 'xml_format' # xml_format.rb include SiSU_XML_Format + require_relative 'xml_persist' # xml_persist.rb require_relative 'rexml' # rexml.rb include SiSU_Rexml require_relative 'shared_metadata' # shared_metadata.rb - @@alt_id_count,@@tablehead,@@number_of_cols=0,0,0 + @@alt_id_count=0 @@tablefoot='' class Source def initialize(opt) @@ -159,12 +160,12 @@ module SiSU_XML_SAX include SiSU_TextUtils require_relative 'css' # css.rb require_relative 'xhtml_shared' # decide use, whether xml rather than xhtml - @@xml={ body: [], open: [], close: [], head: [] } def initialize(particulars) @env, @md, @ao_arr= particulars.env,particulars.md,particulars.ao_array @trans=SiSU_XML_Munge::Trans.new(@md) @sys=SiSU_Env::SystemCall.new + @per=SiSU_XML_Persist::Persist.new end def songsheet pre @@ -219,7 +220,7 @@ WOK end def xml_head metadata=SiSU_Metadata::Summary.new(@md).xml_sax.metadata - @@xml[:head] << metadata + @per.head << metadata end def xml_sc(md='') sc=if @md.sc_info @@ -241,7 +242,7 @@ WOK WOK else '' end - @@xml[:sc]=sc + @per.sc=sc end def xml_structure(dob,type='norm') if dob.is==:heading @@ -257,16 +258,16 @@ WOK util=SiSU_TextUtils::Wrap.new(dob.obj,70) wrapped=util.line_wrap #end - @@xml[:body] << if defined? dob.ocn; %{#{Ax[:tab]*0}} + @per.body << if defined? dob.ocn; %{#{Ax[:tab]*0}} else "#{Ax[:tab]*0}" end - @@xml[:body] << "#{Ax[:tab]*1}#{dob.ocn}" if defined? dob.ocn - @@xml[:body] << if lv; %{#{Ax[:tab]*1}\n#{Ax[:tab]*2}#{wrapped}\n#{Ax[:tab]*1}} + @per.body << "#{Ax[:tab]*1}#{dob.ocn}" if defined? dob.ocn + @per.body << if lv; %{#{Ax[:tab]*1}\n#{Ax[:tab]*2}#{wrapped}\n#{Ax[:tab]*1}} else %{#{Ax[:tab]*1}\n#{Ax[:tab]*2}#{wrapped}\n#{Ax[:tab]*1}} # main text, contents, body KEEP end - @@xml[:body] << @endnotes if @endnotes - ##@@xml[:body] << "#{Ax[:tab]*1}#{dob[@regx,2]}" if dob[@regx,2] # old unwrapped main text, contents, body KEEP - @@xml[:body] << "#{Ax[:tab]*0}" + @per.body << @endnotes if @endnotes + ##@per.body << "#{Ax[:tab]*1}#{dob[@regx,2]}" if dob[@regx,2] # old unwrapped main text, contents, body KEEP + @per.body << "#{Ax[:tab]*0}" @endnotes=[] end def block_structure(dob='') @@ -275,13 +276,13 @@ WOK gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'\1') #footnote/endnote clean dob=@trans.markup_block(dob) dob.obj=dob.obj.strip - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*1}} - @@xml[:body] << "#{Ax[:tab]*0}" - @@xml[:body] << @endnotes if @endnotes + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*1}} + @per.body << "#{Ax[:tab]*0}" + @per.body << @endnotes if @endnotes @endnotes=[] end def group_structure(dob='') @@ -290,48 +291,48 @@ WOK gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'\1') #footnote/endnote clean dob=@trans.markup_group(dob) dob.obj=dob.obj.strip - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*1}} - @@xml[:body] << "#{Ax[:tab]*0}" - @@xml[:body] << @endnotes if @endnotes + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*1}} + @per.body << "#{Ax[:tab]*0}" + @per.body << @endnotes if @endnotes @endnotes=[] end def poem_structure(dob='') dob=@trans.markup_group(dob) #dob.obj.gsub(/\s\s/,'  ') dob.obj=dob.obj.strip - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*0}} end def code_structure(dob='') dob=@trans.markup_group(dob) dob.obj=dob.obj.gsub(/\s\s/,'  ').strip - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*1}} - @@xml[:body] << "#{Ax[:tab]*0}" + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*1}} + @per.body << "#{Ax[:tab]*0}" end def table_structure(dob) table=SiSU_XHTML_Shared::TableXHTML.new(dob) - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*2}#{table.table.obj}} - @@xml[:body] << %{#{Ax[:tab]*1}} - #@@xml[:body] << %{#{tab*1}} - @@xml[:body] << "#{Ax[:tab]*0}" - #@@xml[:body] << %{#{Ax[:tab]*0}} - #@@xml[:body] << %{#{Ax[:tab]*1}#{table}\n#{Ax[:tab]*1}} # unless lv # main text, contents, body KEEP - #@@xml[:body] << "#{Ax[:tab]*0}" + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*2}#{table.table.obj}} + @per.body << %{#{Ax[:tab]*1}} + #@per.body << %{#{tab*1}} + @per.body << "#{Ax[:tab]*0}" + #@per.body << %{#{Ax[:tab]*0}} + #@per.body << %{#{Ax[:tab]*1}#{table}\n#{Ax[:tab]*1}} # unless lv # main text, contents, body KEEP + #@per.body << "#{Ax[:tab]*0}" #@endnotes=[] end def markup(data) @@ -403,7 +404,7 @@ WOK elsif dob.obj =~/(Owner Details)/ # txt_obj={ txt: '
Owner Details' } # format_scroll=FormatScroll.new(@md,txt_obj) -# @@xml[:owner_details]=format_scroll.bold_para +# @per.owner_details=format_scroll.bold_para dob.obj='' end if dob.obj =~// \ @@ -424,41 +425,41 @@ WOK end 7.downto(4) do |x| y=x - 1; v=x - 3 - @@xml[:body] << "#{Ax[:tab]*5}\n#{Ax[:tab]*y}" if @level[x]==true + @per.body << "#{Ax[:tab]*5}\n#{Ax[:tab]*y}" if @level[x]==true end 3.downto(1) do |x| y=x - 1 - @@xml[:body] << "#{Ax[:tab]*y}" if @level[x]==true + @per.body << "#{Ax[:tab]*y}" if @level[x]==true end - #7.downto(1) { |x| y=x - 1; @@xml[:body] << "#{Ax[:tab]*y}" if @level[x]==true } + #7.downto(1) { |x| y=x - 1; @per.body << "#{Ax[:tab]*y}" if @level[x]==true } end def pre rdf=SiSU_XML_Tags::RDF.new(@md) - @@xml[:head],@@xml[:body]=[],[] + @per.head,@per.body=[],[] stylesheet=SiSU_Style::CSS_HeadInfo.new(@md,'xml_sax').stylesheet encoding=if @sys.locale =~/utf-?8/i then '' else '' end - @@xml[:open] =< WOK - @@xml[:head] << '' - @@xml[:body] << '' + @per.head << '' + @per.body << '' end def post - @@xml[:head] << @@xml[:sc] - @@xml[:head] << '' - @@xml[:body] << '' - @@xml[:close] = '' + @per.head << @per.sc + @per.head << '' + @per.body << '' + @per.close = '' end def publish content=[] - content << @@xml[:open] << @@xml[:head] << @@xml[:body] << @@xml[:metadata] - content << @@xml[:owner_details] if @md.stmp =~/\w\w/ - content << @@xml[:tail] << @@xml[:close] + content << @per.open << @per.head << @per.body #<< @per.metadata + #content << @per.owner_details if @md.stmp =~/\w\w/ + content << @per.tail << @per.close content=content.flatten.compact Output.new(content,@md).xml @@xml={} -- cgit v1.2.3