Class: PageHub::Markdown::ToC::Heading
- Inherits:
-
Object
- Object
- PageHub::Markdown::ToC::Heading
- Defined in:
- lib/pagehub-markdown/processors/toc_generator.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#index ⇒ Object
Returns the value of attribute index.
-
#level ⇒ Object
Returns the value of attribute level.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #<<(h) ⇒ Object
-
#initialize(title, level, index) ⇒ Heading
constructor
A new instance of Heading.
- #to_html ⇒ Object
Constructor Details
#initialize(title, level, index) ⇒ Heading
Returns a new instance of Heading.
55 56 57 58 59 60 61 62 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 55 def initialize(title, level, index) @title = title @level = level @index = index @parent = nil @children = [] super() end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
53 54 55 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 53 def children @children end |
#index ⇒ Object
Returns the value of attribute index.
53 54 55 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 53 def index @index end |
#level ⇒ Object
Returns the value of attribute level.
53 54 55 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 53 def level @level end |
#parent ⇒ Object
Returns the value of attribute parent.
53 54 55 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 53 def parent @parent end |
#title ⇒ Object
Returns the value of attribute title.
53 54 55 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 53 def title @title end |
Instance Method Details
#<<(h) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 64 def <<(h) @children.each { |child| return if child.title == h.title } h.parent = self @children << h end |
#to_html ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 73 def to_html() html = "" html << "<li>" html << "<a href=\"\#toc_#{index}\">" << title << "</a>" if children.any? then html << "<ol>" children.each { |child| html << child.to_html } html << "</ol>" end html << "</li>" end |