Class: Conversio::HTMLTableOfContent
- Inherits:
-
Object
- Object
- Conversio::HTMLTableOfContent
- Defined in:
- lib/conversio/htmltoc.rb
Instance Attribute Summary collapse
-
#numbering ⇒ Object
Returns the value of attribute numbering.
-
#table_of_content_div_class ⇒ Object
Returns the value of attribute table_of_content_div_class.
Instance Method Summary collapse
- #get_html ⇒ Object
- #get_html_table_of_content ⇒ Object
- #get_html_with_anchors ⇒ Object
-
#initialize(html_input) ⇒ HTMLTableOfContent
constructor
A new instance of HTMLTableOfContent.
Constructor Details
#initialize(html_input) ⇒ HTMLTableOfContent
Returns a new instance of HTMLTableOfContent.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/conversio/htmltoc.rb', line 7 def initialize(html_input) @numbering = true @table_of_content_div_class = 'toc' # Variables @html_input = Array.new @heading_elements = Array.new html_input.split("\n").each { |l| @html_input << l } scan_for_heading_elements() numbers() end |
Instance Attribute Details
#numbering ⇒ Object
Returns the value of attribute numbering.
5 6 7 |
# File 'lib/conversio/htmltoc.rb', line 5 def numbering @numbering end |
#table_of_content_div_class ⇒ Object
Returns the value of attribute table_of_content_div_class.
5 6 7 |
# File 'lib/conversio/htmltoc.rb', line 5 def table_of_content_div_class @table_of_content_div_class end |
Instance Method Details
#get_html ⇒ Object
40 41 42 |
# File 'lib/conversio/htmltoc.rb', line 40 def get_html() return get_html_table_of_content() << "\n" << get_html_with_anchors end |
#get_html_table_of_content ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/conversio/htmltoc.rb', line 23 def get_html_table_of_content() output = String.new @heading_elements.each do |heading| index, level, content, anchor, number = heading level = level.to_i next if level > 3 # only h1,h2, and h3 tags are used space = ' ' case level when 2 then output << space when 3 then output << space << space end content = "#{number} #{content}" if numbering? output << %{<a href="##{anchor}">#{content}</a><br/>\n} end return %{<div class="#{@table_of_content_div_class}">\n#{output}</div>\n} end |
#get_html_with_anchors ⇒ Object
18 19 20 21 |
# File 'lib/conversio/htmltoc.rb', line 18 def get_html_with_anchors() inject_anchors() return @html_input.join("\n") end |