lib/webby/filters/outline.rb
def filter
    doc = Hpricot(@str)

    # extract directives from the "toc" tag
    toc_elem = doc.search('toc').first

    unless toc_elem.nil?
      @numbering = toc_elem['numbering'] !~ %r/off/i
      @numbering_start = Integer(toc_elem['numbering_start']) if toc_elem.has_attribute? 'numbering_start'
      @toc_style = toc_elem['toc_style'] if toc_elem.has_attribute? 'toc_style'
      @toc_range = toc_elem['toc_range'] if toc_elem.has_attribute? 'toc_range'
    end

    unless %w[ul ol].include? @toc_style
      raise ArgumentError, "unknown ToC list type '#{@toc_style}'"
    end

    m = %r/h(\d)\s*-\s*h(\d)/i.match @toc_range
    @toc_range = Integer(m[1])..Integer(m[2])
    @list_opening = build_list_opening(toc_elem)

    doc.traverse_element(*%w[h1 h2 h3 h4 h5 h6]) do |elem|
      text, id = heading_info(elem)
      add_to_toc(text, id) if @toc_range.include? current_level
    end

    toc_elem.swap(toc) unless toc_elem.nil?
    doc.to_html
  end
# call-seq:
#    filter    => html
#
# Process the original html document passed to the filter when it was
# created. The document will be scanned for heading tags (h1, h2, etc.)
# and outline numbering and id attributes will be inserted. A table of
# contents will also be created and inserted into the page if a <toc />
# tag is found.
#
# For example, if there is a heading tag
#
#    <h3>Get Fuzzy</h3>
#
# somewhere in a page about comic strips, the tag might be altered as such
#
#    <h3 id="h2_2_1"><span class="heading-num">2.2.1</span>Get Fuzzy</h3>
# 
# The id attribute is used to generate a linke from the table of contents
# to this particular heading tag. The original text of the tag is used in
# the table of contents -- "Get Fuzzy" in this example.
#
call-seq:
filter    => html

Process the original html document passed to the filter when it was
created. The document will be scanned for heading tags (h1, h2, etc.)
and outline numbering and id attributes will be inserted. A table of
contents will also be created and inserted into the page if a 
tag is found.

For example, if there is a heading tag

Get Fuzzy

somewhere in a page about comic strips, the tag might be altered as such



The id attribute is used to generate a linke from the table of contents
to this particular heading tag. The original text of the tag is used in
the table of contents -- "Get Fuzzy" in this example.
call - seq : filter = > html Process the original html document passed to the filter when it was created . The document will be scanned for heading tags ( h1 h2 etc . ) and outline numbering and id attributes will be inserted . A table of contents will also be created and inserted into the page if a tag is found . For example if there is a heading tag Get Fuzzy somewhere in a page about comic strips the tag might be altered as such The id attribute is used to generate a linke from the table of contents to this particular heading tag . The original text of the tag is used in the table of contents -- " Get Fuzzy " in this example .
def filter
    doc = Hpricot(@str)
    toc_elem = doc.search('toc').first
    unless toc_elem.nil?
      @numbering = toc_elem['numbering'] !~ %r/off/i
      @numbering_start = Integer(toc_elem['numbering_start']) if toc_elem.has_attribute? 'numbering_start'
      @toc_style = toc_elem['toc_style'] if toc_elem.has_attribute? 'toc_style'
      @toc_range = toc_elem['toc_range'] if toc_elem.has_attribute? 'toc_range'
    end
    unless %w[ul ol].include? @toc_style
      raise ArgumentError, "unknown ToC list type '#{@toc_style}'"
    end
    m = %r/h(\d)\s*-\s*h(\d)/i.match @toc_range
    @toc_range = Integer(m[1])..Integer(m[2])
    @list_opening = build_list_opening(toc_elem)
    doc.traverse_element(*%w[h1 h2 h3 h4 h5 h6]) do |elem|
      text, id = heading_info(elem)
      add_to_toc(text, id) if @toc_range.include? current_level
    end
    toc_elem.swap(toc) unless toc_elem.nil?
    doc.to_html
  end
def filter doc = Hpricot ( @str ) toc_elem = doc . search ( 'toc' ) . first unless toc_elem . nil? @numbering = toc_elem [ 'numbering' ] !~ %r/ off /i @numbering_start = Integer ( toc_elem [ 'numbering_start' ] ) if toc_elem . has_attribute? 'numbering_start' @toc_style = toc_elem [ 'toc_style' ] if toc_elem . has_attribute? 'toc_style' @toc_range = toc_elem [ 'toc_range' ] if toc_elem . has_attribute? 'toc_range' end unless %w[ ul ol ] . include? @toc_style raise ArgumentError , "unknown ToC list type '#{@toc_style}'" end m = %r/ h( \d ) \s *- \s *h( \d ) /i . match @toc_range @toc_range = Integer ( m [ 1 ] ) .. Integer ( m [ 2 ] ) @list_opening = build_list_opening ( toc_elem ) doc . traverse_element ( * %w[ h1 h2 h3 h4 h5 h6 ] ) do | elem | text , id = heading_info ( elem ) add_to_toc ( text , id ) if @toc_range . include? current_level end toc_elem . swap ( toc ) unless toc_elem . nil? doc . to_html end
call-seq:
filter    => html
call - seq : filter = > html
# extract directives from the "toc" tag