class SiSU_HTML::Source::Toc

Public Class Methods

new(md=nil,data='') click to toggle source
# File lib/sisu/html.rb, line 260
def initialize(md=nil,data='')
  @data,@md=data,md
  @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) if @md
end

Public Instance Methods

minitoc() click to toggle source
# File lib/sisu/html.rb, line 317
def minitoc
  minitoc=@@toc[:seg_mini].join("\n")
  '<div class="toc">' + minitoc + '</div>'
end
songsheet() click to toggle source
# File lib/sisu/html.rb, line 264
def songsheet #extracts toc for scroll & seg
  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],
      'Toc'
    ).txt_grey
  end
  toc=nil
  @@firstseg=nil
  @@toc={ seg: [], seg_mini: [], scr: [] }
  @data.each do |dob|
    if dob.is==:heading \
    || dob.is==:heading_insert
      dob_toc=dob.dup
      toc=if dob_toc.is ==:heading \
      || dob.is==:heading_insert
        toc=case dob_toc.ln
        when 0 then SiSU_HTML::Source::Toc.new(@md,dob_toc).level_0
        when 1 then SiSU_HTML::Source::Toc.new(@md,dob_toc).level_1
        when 2 then SiSU_HTML::Source::Toc.new(@md,dob_toc).level_2
        when 3 then SiSU_HTML::Source::Toc.new(@md,dob_toc).level_3
        when 4 then SiSU_HTML::Source::Toc.new(@md,dob_toc).level_4
        when 5 then SiSU_HTML::Source::Toc.new(@md,dob_toc).level_5
        when 6 then SiSU_HTML::Source::Toc.new(@md,dob_toc).level_6
        else nil
        end
      end
      toc.each do |k,d|
        d.gsub!(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ')
      end if toc
      if @@firstseg.nil? \
      and dob.ln==4 \
      and dob.name =~/\S+/
        @@firstseg=dob.name
      end
      if toc
        begin
          @@toc[:seg] << toc[:seg] if toc[:seg]
          @@toc[:seg_mini] << toc[:seg_mini] if toc[:seg_mini]
          @@toc[:scr] << toc[:scr] if toc[:scr]
        rescue
          SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
            __LINE__.to_s + ':' + __FILE__
          end
        end
      end
    end
  end
  @md.firstseg=@@firstseg
  @@toc
end

Protected Instance Methods

level_0() click to toggle source

<– not used

# File lib/sisu/html.rb, line 360
def level_0
  dob=@data
  linkname,link=dob.obj.strip,dob.ocn
  if link \
  and link !~/#/ #% keep eye on link
    SiSU_HTML_Format::ParagraphNumber.new(@md,link)
  end
  title=linkname
  toc={}
  txt_obj={ txt: title }
  format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
  toc[:seg]=format_toc.lev0
  toc[:seg_mini]=format_toc.mini_lev0
  title=if dob.ocn ==0 then linkname
  else
    @@toc[:scr] <<  '<br>'
    %{<b><a href="##{dob.ocn}">#{linkname}</a></b>}
  end
  txt_obj={ txt: title }
  format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
  toc[:scr]=format_toc.lev0
  toc
end
level_1() click to toggle source
# File lib/sisu/html.rb, line 383
def level_1
  dob=@data
  linkname,link=dob.obj.strip,dob.ocn
  if link \
  and link !~/#/ #% keep eye on link
    SiSU_HTML_Format::ParagraphNumber.new(@md,link)
  end
  title=if dob.obj !~/^Metadata$/ then linkname
  else
    link='metadata'
    %{<b><a href="#{link}#{@md.lang_code_insert}#{Sfx[:html]}">#{linkname}</a></b>}
  end
  toc={}
  txt_obj={ txt: title }
  format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
  toc[:seg]=if dob.name =~/^meta/ \
  and dob.obj =~/Document Information/
    format_toc.lev0
  else format_toc.lev1
  end
  toc[:seg_mini]=if dob.name =~/^meta/ \
  and dob.obj =~/Document Information/
    @md.concord_make \
    ? format_toc.mini_concord_tail
    : format_toc.mini_tail
  else format_toc.mini_lev1
  end
  title=if dob.ocn ==0
    if dob.name =~/^meta/ \
    and dob.obj =~/Document Information/
      %{<a href="#docinfo">#{linkname}</a>}
    else linkname
    end
  else
    @@toc[:scr] <<  '<br>'
    %{<b><a href="##{dob.ocn}">#{linkname}</a></b>}
  end
  txt_obj={ txt: title }
  format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
  toc[:scr]=if dob.obj =~/^Metadata$/ then ''
  elsif txt_obj[:txt] =~/<a href="#">/
    format_toc.lev1.gsub(/<a href="#">|<\/a>/,'')
  else format_toc.lev1
  end
  toc
end
level_2() click to toggle source
# File lib/sisu/html.rb, line 429
def level_2
  dob=@data
  linkname,ocn=dob.obj.strip,dob.ocn
  p_num=if ocn \
  and ocn !~/#/
    SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
  else nil
  end
  txt_obj={ txt: linkname }
  format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
  toc={}
  toc[:seg]=format_toc.lev2
  toc[:seg_mini]=format_toc.mini_lev2
  if p_num
    title=%{#{p_num.goto}#{linkname}</a>}
    txt_obj={ txt: title }
    format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
    toc[:scr]=if txt_obj[:txt] =~/<a href="#">/
      format_toc.lev2.gsub(/<a href="#">|<\/a>/,'')
    else format_toc.lev2
    end
  end
  toc
end
level_3() click to toggle source
# File lib/sisu/html.rb, line 453
def level_3
  dob=@data
  linkname,ocn=dob.obj.strip,dob.ocn
  p_num=if ocn \
  and ocn !~/#/
    SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
  else nil
  end
  txt_obj={ txt: linkname }
  format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
  toc={}
  toc[:seg]=format_toc.lev3
  toc[:seg_mini]=format_toc.mini_lev3
  if p_num
    title=%{#{p_num.goto}#{linkname}</a>}
    txt_obj={ txt: title }
    format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
    toc[:scr]=if txt_obj[:txt] =~/<a href="#">/
      format_toc.lev3.gsub(/<a href="#">|<\/a>/,'')
    else format_toc.lev3
    end
  end
  toc
end
level_4() click to toggle source
# File lib/sisu/html.rb, line 477
    def level_4
      dob=@data
      linkname,ocn=dob.obj.strip,dob.ocn
      p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn) if ocn
      if dob.ln ==4
        fnh={
          fn: dob.name,
        }
        f=@md.file.base_filename.html_seg(fnh)
        seg_link=%{  <a href="#{f}" target="_top">
  #{dob.obj}
</a> }
        @@seg_url=dob.name
      elsif dob.obj =~/\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+/
        fn,hd=/^(\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+)(.*)/.match(dob.obj)[1,2]
        fnh={
          fn: fn,
        }
        f=@md.file.base_filename.html_seg(fnh)
        seg_link=%{<a href="#{f}" target="_top">#{fn} #{hd}</a> }
      end
      p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn) if ocn
      @file=SiSU_Env::FileOp.new(@md) if @md
      txt_obj=if seg_link=~/sisu_manifest\.html/
        man_link=if @file.output_dir_structure.by_language_code? \
        or @file.output_dir_structure.by_filetype?
          seg_link.gsub(/sisu_manifest\.html/,"../../manifest/#{@file.base_filename.manifest}")
        else seg_link
        end
        { txt: man_link }
      else { txt: seg_link }
      end
      format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
      toc={}
      toc[:seg]=format_toc.lev4
      toc[:seg_mini]=format_toc.mini_lev4
      title=%{#{p_num.goto}#{linkname}</a>} if p_num
      txt_obj=if title=~/sisu_manifest.html/
        man_link=title.gsub(/sisu_manifest.html/,"../manifest/#{@file.base_filename.manifest}")
        { txt: man_link }
      else { txt: title }
      end
      format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
      toc[:scr]=format_toc.lev4
      toc
     #end
    end
level_5() click to toggle source
# File lib/sisu/html.rb, line 524
    def level_5
      dob=@data
      linkname,ocn=dob.obj.strip,dob.ocn
      toc={}
      if ocn \
      and ocn !~/#/
        fnh={
          fn: @@seg_url,
        }
        f=@md.file.base_filename.html_seg(fnh)
        p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
        lnk_n_txt=%{  <a href="#{f}##{ocn}">
  #{linkname}
</a>}
        txt_obj={ txt: lnk_n_txt }
        format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
        toc[:seg]=format_toc.lev5
        toc[:seg_mini]=format_toc.mini_lev5
        title=%{#{p_num.goto}#{linkname}</a>}
        txt_obj={ txt: title }
        format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
        toc[:scr]=format_toc.lev5
      end
      toc
    end
level_6() click to toggle source
# File lib/sisu/html.rb, line 549
      def level_6
        dob=@data
        linkname,ocn=dob.obj.strip,dob.ocn
        toc={}
        if ocn \
        and ocn !~/#/
          fnh={
            fn: @@seg_url,
          }
          f=@md.file.base_filename.html_seg(fnh)
          p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
          lnk_n_txt=%{  <a href="#{f}##{ocn}">
  #{linkname}
</a>}
          txt_obj={ txt: lnk_n_txt }
          format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
          toc[:seg]=format_toc.lev6
          toc[:seg_mini]=format_toc.mini_lev6
          title=%{#{p_num.goto}#{linkname}</a>}
          txt_obj={ txt: title }
          format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
          toc[:scr]=format_toc.lev6
        end
        toc
      end
level_concordance() click to toggle source
# File lib/sisu/html.rb, line 343
def level_concordance
  format_head_toc=SiSU_HTML_Format::HeadToc.new(@md)
  @@toc[:seg_mini] << format_head_toc.mini_seg_concordance
end
level_endnotes() click to toggle source

not used –>

# File lib/sisu/html.rb, line 337
def level_endnotes
  if @md.flag_endnotes
    format_head_scroll=SiSU_HTML_Format::HeadScroll.new(@md)
    @@toc[:scr] << format_head_scroll.toc_endnote
  end
end
level_metadata() click to toggle source
# File lib/sisu/html.rb, line 347
def level_metadata
  format_head_toc=SiSU_HTML_Format::HeadToc.new(@md)
  @@toc[:scr] << format_head_toc.metadata
  @@toc[:seg] << format_head_toc.seg_metadata
  @@toc[:seg_mini] << format_head_toc.mini_seg_metadata
end
level_word_index() click to toggle source
# File lib/sisu/html.rb, line 353
def level_word_index
  format_head_toc=SiSU_HTML_Format::HeadToc.new(@d0c)
  @@toc[:scr] << format_head_toc.concordance
  @@toc[:seg] << format_head_toc.concordance
  @@toc[:seg_mini] << format_head_toc.mini_concordance
end
rss() click to toggle source
# File lib/sisu/html.rb, line 322
      def rss #sort all wrong, disabled but kept
        @@toc[:seg] <<<<WOK
<center>
<table><tr><td>
<p><font color="#222222" #{the_font.set_face} size="2">
(relatively static) RSS feeds for DOCUMENTS:<br>
<a href="../rssfeed/documents.xml"><img border="0" height="14" width="36" src="../_sisu/image/rss.png" alt="RSS feed"></a>&nbsp;http://www.jus.uio.no/lm/rssfeed/documents.xml<br>
<a href="../rssfeed/tradelaw.xml"><img border="0" height="14" width="36" src="../_sisu/image/rss.png" alt="RSS feed"></a>&nbsp;http://www.jus.uio.no/lm/rssfeed/tradelaw.xml<br>
<a href="../rssfeed/environmental.xml"><img border="0" height="14" width="36" src="../_sisu/image/rss.png" alt="RSS feed"></a>&nbsp;http://www.jus.uio.no/lm/rssfeed/environmental.xml<br>
<center><a href="mailto:info@address.com" target="_top">info@address.com</a></center>
</font></p>
</td></tr></table>
WOK
      end