Class: SiSU_HTML::Source::Toc

Inherits:
LinksGuide show all
Defined in:
lib/sisu/html.rb

Direct Known Subclasses

ScrollHeadAndSegToc

Constant Summary collapse

@@toc =
{ seg: [], seg_mini: [], scr: [] }
@@seg_url =
''
@@firstseg =
nil

Instance Method Summary collapse

Methods inherited from LinksGuide

#toc

Constructor Details

#initialize(md = nil, data = '') ⇒ Toc

Returns a new instance of Toc.



260
261
262
263
# 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

Instance Method Details

#minitocObject



317
318
319
320
# File 'lib/sisu/html.rb', line 317

def minitoc
  minitoc=@@toc[:seg_mini].join("\n")
  '<div class="toc">' + minitoc + '</div>'
end

#songsheetObject

extracts toc for scroll & seg



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# 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