class SiSU_SimpleXML_ModelSax::Convert::Scroll

Public Class Methods

new(data='',particulars='') click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 145
def initialize(data='',particulars='')
  @data,@env,@md=data,particulars.env,particulars.md
  @regx=/^(?:#{Mx[:mk_o]}:p[bn]#{Mx[:mk_c]}\s*)?(?:#{Mx[:lv_o]}[1-9]:(\S*)#{Mx[:lv_c]})?(.+)/
  @tab="\t"
  if @md
    @trans=SiSU_XML_Munge::Trans.new(@md)
  end
  @sys=SiSU_Env::SystemCall.new
end

Public Instance Methods

songsheet() click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 154
def songsheet
  pre
  markup
  post
  publish
end

Protected Instance Methods

block_structure(para='') click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 219
def block_structure(para='')
  para.gsub!(/<:block(?:-end)?>/,'')
  para.strip!
  @@xml[:body] << %{#{@tab*0}<object>}
  @@xml[:body] << %{#{@tab*1}<text class="block">#{@tab*1}\n}
  @@xml[:body] << %{#{@tab*2}#{para}#{@tab*1}\n}
  @@xml[:body] << %{#{@tab*1}</text>\n}
  @@xml[:body] << "#{@tab*0}</object>"
end
code_structure(para='') click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 246
def code_structure(para='')
  para.gsub!(/<:code(?:-end)?>/,'')
  para.strip!
  @@xml[:body] << %{#{@tab*0}<object>}
  @@xml[:body] << %{#{@tab*1}<text class="code">#{@tab*1}\n}
  @@xml[:body] << %{#{@tab*2}#{para}#{@tab*1}\n}
  @@xml[:body] << %{#{@tab*1}</text>\n}
  @@xml[:body] << "#{@tab*0}</object>" << "\n"
end
embedded_endnotes(para='') click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 161
def embedded_endnotes(para='')
  para.gsub!(/~\{(.+?)\}~/,'<endnote symbol="norm">\1</endnote> ')
  para.gsub!(/~\[([*+])\s+(.+?)\]~/,'<endnote symbol="\1">\2</endnote> ')
end
group_structure(para='') click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 228
def group_structure(para='')
  para.gsub!(/<:group(?:-end)?>/,'')
  para.strip!
  @@xml[:body] << %{#{@tab*0}<object>}
  @@xml[:body] << %{#{@tab*1}<text class="group">#{@tab*1}\n}
  @@xml[:body] << %{#{@tab*2}#{para}#{@tab*1}\n}
  @@xml[:body] << %{#{@tab*1}</text>\n}
  @@xml[:body] << "#{@tab*0}</object>"
end
markup() click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 270
def markup
  data=[]
  xml_sc(@md)
  @endnotes,@level,@cont,@copen,@xml_contents_close=[],[],[],[],[]
  @rcdc=false
  (0..6).each { |x| @cont[x]=@level[x]=false }
  (4..6).each { |x| @xml_contents_close[x]='' }
  @data.each do |para|
    data << SiSU_AO_DocumentStructureExtract::Structure.new(@md,para).structure #takes on Mx marks
  end
  data.each do |para|
    if para !~/^\s*(?:%+ |<:code>)/
      if @md.sem_tag and para =~/[:;]\{|\}[:;]/
        para=@trans.xml_semantic_tags(para)
      end
      if para =~/[:;]\{|\}[:;]/
        para=SiSU_Sem::Tags.new(para,@md).rm.all
      end
    end
    para=@trans.markup_light(para)
    @trans.char_enc.utf8(para) if @sys.locale =~/utf-?8/i #% utf8
    para.gsub!(/^@(\S+?):/,"#{Mx[:lv_o]}@\\1#{Mx[:lv_c]}")
    if para =~/\A#{Mx[:lv_o]}@(\S+?)#{Mx[:lv_c]}\s*(.+?)\Z/m # for headers
      d_meta=SiSU_TextUtils::HeaderScan.new(@md,para).meta
      if d_meta; xml_head(d_meta)
      end
    end
    para='' if para=~/#{Mx[:lv_o]}@\S+?#{Mx[:lv_c]}/
    if @rcdc==false \
    and (para =~/~metadata/ or para =~/^1~meta\s+Document Information/)
      @rcdc=true
    end
    if para !~/(^@\S+?:|^\s*$|<ENDNOTES>|<EOF>)/
      @sto=SiSU_text_parts::SplitTextObject.new(@md,para).lev_segname_para
      unless @rcdc
        SiSU_XML_Format::FormatScroll.new(@md,@sto.text) if @sto.format =~/i[1-9]|ordinary/
        case @sto.format
        when /^(1):(\S*)/
          xml_clean(para)
          xml_structure(para,$1,$2)
          para=@sto.lev_para_ocn.heading_body1
        when /^(2):(\S*)/
          xml_clean(para)
          xml_structure(para,$1,$2)
          para=@sto.lev_para_ocn.heading_body2
        when /^(3):(\S*)/
          xml_clean(para)
          xml_structure(para,$1,$2)
          para=@sto.lev_para_ocn.heading_body3
        when /^(4):(\S*)/ # work on see SplitTextObject
          xml_clean(para)
          xml_structure(para,$1,$2)
          para=@sto.lev_para_ocn.heading_body4
        when /^(5):(\S*)/
          xml_clean(para)
          xml_structure(para,$1,$2)
          para=@sto.lev_para_ocn.heading_body5
        when /^(6):(\S*)/
          xml_clean(para)
          xml_structure(para,$1,$2)
          para=@sto.lev_para_ocn.heading_body6
        else
          if para =~ /<:verse>/
            para=poem_structure(para)
          elsif para =~ /<:group>/
            para=group_structure(para)
          elsif para =~ /<:code>/
            para.gsub!(/</,'&lt;')
            para.gsub!(/>/,'&gt;')
            para=code_structure(para)
          elsif para =~/<!Th?.+/ # tables come as single block #work area 2005w13
            table=SiSU_Tables::TableXML.new(para)
            para=table.table_split
            para=table_structure(para)
          else xml_structure(para,nil,nil)
          end
        end
        if para =~/<a name="n\d+">/ \
        and para =~/^(-\{{2}~\d+|<!e[:_]\d+!>)/ # -endnote
          para=''
        end
        if para =~/.*<:#>.*$/
          para=case para
          when /<:i1>/
            format_text=FormatTextObject.new(para,'')
            format_text.scr_inden_ocn_e_no_paranum
          when /<:i2>/
            format_text=FormatTextObject.new(para,'')
            format_text.scr_inden_ocn_e_no_paranum
          end
        end
        if para =~/<:center>/
          one,two=/(.*)<:center>(.*)/.match(para)[1,2]
          format_text=FormatTextObject.new(one,two)
          para=format_text.center
        end
      end
      para.gsub!(/<:\S+?>/,'')
      para.gsub!(/<!.+!>/,'') ## Clean Prepared Text #bugwatch reinstate
      para
    end
    para
  end
  6.downto(4) do |x|
    y=x - 1; v=x - 3
    @@xml[:body] << "#{@tab*5}</content>\n#{@tab*y}</contents#{v}>\n" if @level[x]==true
  end
  3.downto(1) do |x|
    y=x - 1
    @@xml[:body] << "#{@tab*y}</heading#{x}>\n" if @level[x]==true
  end
end
poem_structure(para='') click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 237
def poem_structure(para='')
  para.gsub!(/<:verse(?:-end)?>/,'')
  para.strip!
  @@xml[:body] << %{#{@tab*0}<object>}
  @@xml[:body] << %{#{@tab*1}<text class="verse">#{@tab*1}\n}
  @@xml[:body] << %{#{@tab*2}#{para}#{@tab*1}\n}
  @@xml[:body] << %{#{@tab*1}</text>\n}
  @@xml[:body] << "#{@tab*0}</object>" << "\n"
end
post() click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 399
def post
  @@xml[:head] << @@xml[:sc]
  @@xml[:head] << "</head>\n"
  @@xml[:body] << "</body>\n"
  @@xml[:close] = "</document>\n"
end
pre() click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 382
      def pre
        rdf=SiSU_XML_Tags::RDF.new(@md)
        dir=SiSU_Env::InfoEnv.new
        @@xml[:head],@@xml[:body]=[],[]
        css=SiSU_Env::CSS_Select.new(@md).xml_sax
        encoding=if @sys.locale =~/utf-?8/i then '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
        else                                     '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>'
        end
        @@xml[:open] =<<WOK
#{encoding}
<?xml-stylesheet type="text/css" href="../#{dir.path.style}/#{css}"?>
#{rdf.comment_xml_sax}
<document>
WOK
        @@xml[:head] << "<head>\n"
        @@xml[:body] << "<body>\n"
      end
publish() click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 405
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]
  Output.new(content.join,@md).xml
  @@xml={}
end
table_structure(table='') click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 255
def table_structure(table='') #tables
  @@xml[:body] << %{#{@tab*0}<object>}
  @@xml[:body] << %{#{@tab*1}#{table}\n#{@tab*1}\n} # unless lv  # main text, contents, body KEEP
  @@xml[:body] << "#{@tab*0}</object>" << "\n" #if para[@regx]
  @endnotes=[]
end
tidywords(wordlist) click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 261
def tidywords(wordlist)
  wordlist.each do |x|
    x.gsub!(/&/,'&amp;') unless x =~/&\S+;/
  end
end
xml_clean(para) click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 266
def xml_clean(para)
  para.gsub!(/#{Mx[:gl_o]}[1-9]:\S*?#{Mx[:gl_c]}/,'') #Danger, watch
  para
end
xml_head(meta) click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 165
      def xml_head(meta)
        txt=meta.text
        txt.gsub!(/\/{(.+?)}\//,'<i>\1</i>')
        txt.gsub!(/[*!]{(.+?)}[*!]/,'<b>\1</b>')
        txt.gsub!(/_{(.+?)}_/,'<u>\1</u>')
        txt.gsub!(/-{(.+?)}-/,'<del>\1</del>')
        txt.gsub!(/<br(?: \/)?>/,'<br />')
        txt.gsub!(/ & /,' and ')
        @@xml[:head] <<<<WOK
#{@tab}<header class="#{meta.attrib}">
#{@tab*2}<#{meta.el}>
#{@tab*3}#{txt}
#{@tab*2}</#{meta.el}>
#{@tab}</header>
WOK
      end
xml_sc(md='') click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 181
      def xml_sc(md='')
        sc=if @md.sc_info
          <<WOK
    <source_control>
      <sc class="sourcefile">
        #{@md.sc_filename}
      </sc>
      <sc class="number">
        #{@md.sc_number}
      </sc>
      <sc class="date">
        #{@md.sc_date}
      </sc>
    </source_control>
WOK
        else ''
        end
        @@xml[:sc]=sc
      end
xml_structure(para='',lv='',hname='') click to toggle source
# File lib/sisu/sst_to_s_xml_sax.rb, line 200
def xml_structure(para='',lv='',hname='') #extracted endnotes
  lv=lv.to_i
  lv=nil if lv==0
  embedded_endnotes(para)
  if para[@regx]
    paragraph="#{para[@regx,2]}"
    util=SiSU_TextUtils::Wrap.new(paragraph,70)
    wrapped=util.line_wrap
  end
  @@xml[:body] << "#{@tab*0}<object>" if para[@regx]
  @@xml[:body] << "#{@tab*1}" << "\n" if para[@regx]
  @@xml[:body] << if lv; %{#{@tab*1}<text class="h#{lv}">\n#{@tab*2}#{wrapped}\n#{@tab*1}</text>\n} << "\n"
  elsif wrapped =~/\A%%?\s+/; %{<!--\n#{@tab*1}<text class="comment">\n#{@tab*2}#{wrapped}\n#{@tab*1}</text>\n-->\n} # comments
  else                        %{#{@tab*1}<text class="norm">\n#{@tab*2}#{wrapped}\n#{@tab*1}</text>\n} # main text, contents, body KEEP
  end
  @@xml[:body] << "#{@endnotes}" if @endnotes # main text, endnotes KEEP
  @@xml[:body] << "#{@tab*0}</object>" << "\n" if para[@regx]
  @endnotes=[]
end