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.


75
76
77
78
79
80
81
82
# File 'lib/banzai/filter/table_of_contents_filter.rb', line 75

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


73
74
75
# File 'lib/banzai/filter/table_of_contents_filter.rb', line 73

def children
  @children
end

#hrefObject (readonly)

Returns the value of attribute href


73
74
75
# File 'lib/banzai/filter/table_of_contents_filter.rb', line 73

def href
  @href
end

#nodeObject (readonly)

Returns the value of attribute node


73
74
75
# File 'lib/banzai/filter/table_of_contents_filter.rb', line 73

def node
  @node
end

#parentObject (readonly)

Returns the value of attribute parent


73
74
75
# File 'lib/banzai/filter/table_of_contents_filter.rb', line 73

def parent
  @parent
end

Instance Method Details

#levelObject


84
85
86
87
88
# File 'lib/banzai/filter/table_of_contents_filter.rb', line 84

def level
  return 0 unless node

  @level ||= node.name[1].to_i
end

#textObject


90
91
92
93
94
# File 'lib/banzai/filter/table_of_contents_filter.rb', line 90

def text
  return '' unless node

  @text ||= EscapeUtils.escape_html(node.text)
end