Sha256: 8020d1c0d51b3dfcfcb6ed4cbf144ce7d843ad843a8fca0b8a70ceff4076a1f5

Contents?: true

Size: 1.63 KB

Versions: 18

Compression:

Stored size: 1.63 KB

Contents

# -*- encoding : utf-8 -*-
class Card; module Set; module Type; module Basic; extend Card::Set
# ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/05_standard/set/type/basic.rb ~~~~~~~~~~~
format :html do
  view :open_content do |args|
    content = _render_core args
    table_of_contents(content) || content
  end

  def table_of_contents content
    return if @mode==:closed || !content.present?
    min = card.rule(:table_of_contents).to_i
    #warn "table_of #{name}, #{min}"
    return unless min and min > 0

    toc, dep = [], 1
    content.gsub!( /<(h\d)>(.*?)<\/h\d>/i ) do |match|
      if $~
        tag, value = $~[1,2]
        value = ActionView::Base.new.strip_tags(value).strip
        next if value.empty?
        item = { value: value, uri: URI.escape(value) }
        case tag.downcase
        when 'h1'
          item[:depth] = dep = 1; toc << item
        when 'h2'
          toc << []  if dep == 1
          item[:depth] = dep = 2; toc.last << item
        end
        %{<a name="#{item[:uri]}"></a>#{match}}
      end
    end

    if toc.flatten.length >= min
      content.replace %{ <div class="table-of-contents"> <h5>Table of Contents</h5> } +
        make_table_of_contents_list(toc) + '</div>'+ content
    end
  end


  def make_table_of_contents_list(items)
    list = items.collect do |i|
      Array === i ? make_table_of_contents_list(i) : %{<li><a href="##{i[:uri]}"> #{i[:value]}</a></li>}
    end.join("\n")
    "<ol>" + list + "</ol>"
  end

end



# ~~~~~~~~~~~ below autogenerated; above pulled from /Users/ethan/dev/wagn/gem/card/mod/05_standard/set/type/basic.rb ~~~~~~~~~~~
end;end;end;end;

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
card-1.18.6 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.18.5 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.18.4 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.18.3 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.18.2 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.18.1 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.18.0 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.17.4 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.17.3 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.17.2 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.17.1 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.17.0 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.16.15 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.16.14 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.16.13 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.16.12 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.16.11 tmpsets/set/mod007-05_standard/type/basic.rb
card-1.16.10 tmpsets/set/mod007-05_standard/type/basic.rb