Class: Banzai::Filter::TableOfContentsFilter::HeaderNode

Inherits:
Object
  • Object
show all
Defined in:
lib/banzai/filter/table_of_contents_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#childrenObject (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

#hrefObject (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

#nodeObject (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

#parentObject (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

#levelObject



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

#textObject



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