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, renderer) ⇒ Heading
constructor
A new instance of Heading.
- #to_html ⇒ Object
Constructor Details
#initialize(title, level, index, renderer) ⇒ Heading
Returns a new instance of Heading.
67 68 69 70 71 72 73 74 75 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 67 def initialize(title, level, index, renderer) @title = title @level = level @index = index @parent = nil @renderer = renderer @children = [] super() end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
65 66 67 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 65 def children @children end |
#index ⇒ Object
Returns the value of attribute index.
65 66 67 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 65 def index @index end |
#level ⇒ Object
Returns the value of attribute level.
65 66 67 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 65 def level @level end |
#parent ⇒ Object
Returns the value of attribute parent.
65 66 67 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 65 def parent @parent end |
#title ⇒ Object
Returns the value of attribute title.
65 66 67 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 65 def title @title end |
Instance Method Details
#<<(h) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 77 def <<(h) @children.each { |child| return if child.title == h.title } h.parent = self @children << h end |
#to_html ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 86 def to_html() html = "" html << "<li>" html << "<a href=\"\##{header_anchor(title)}\">" << title << "</a>" if children.any? then html << "<ol>" children.each { |child| html << child.to_html } html << "</ol>" end html << "</li>" end |