Class: Banzai::Filter::TableOfContentsFilter::HeaderNode
- Inherits:
-
Object
- Object
- Banzai::Filter::TableOfContentsFilter::HeaderNode
- Defined in:
- lib/banzai/filter/table_of_contents_filter.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#initialize(node: nil, href: nil, previous_header: nil) ⇒ HeaderNode
constructor
A new instance of HeaderNode.
- #level ⇒ Object
- #text ⇒ Object
Constructor Details
#initialize(node: nil, href: nil, previous_header: nil) ⇒ HeaderNode
Returns a new instance of HeaderNode.
80 81 82 83 84 85 86 87 |
# File 'lib/banzai/filter/table_of_contents_filter.rb', line 80 def initialize(node: nil, href: nil, previous_header: nil) @node = node @href = CGI.escape(href) if href @children = [] @parent = find_parent(previous_header) @parent.children.push(self) if @parent end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
78 79 80 |
# File 'lib/banzai/filter/table_of_contents_filter.rb', line 78 def children @children end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
78 79 80 |
# File 'lib/banzai/filter/table_of_contents_filter.rb', line 78 def href @href end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
78 79 80 |
# File 'lib/banzai/filter/table_of_contents_filter.rb', line 78 def node @node end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
78 79 80 |
# File 'lib/banzai/filter/table_of_contents_filter.rb', line 78 def parent @parent end |
Instance Method Details
#level ⇒ Object
89 90 91 92 93 |
# File 'lib/banzai/filter/table_of_contents_filter.rb', line 89 def level return 0 unless node @level ||= node.name[1].to_i end |
#text ⇒ Object
95 96 97 98 99 |
# File 'lib/banzai/filter/table_of_contents_filter.rb', line 95 def text return '' unless node @text ||= CGI.escapeHTML(node.text) end |