Class: PageHub::Markdown::ToC::Heading

Inherits:
Object
  • Object
show all
Defined in:
lib/pagehub-markdown/processors/toc_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#childrenObject

Returns the value of attribute children.



65
66
67
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 65

def children
  @children
end

#indexObject

Returns the value of attribute index.



65
66
67
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 65

def index
  @index
end

#levelObject

Returns the value of attribute level.



65
66
67
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 65

def level
  @level
end

#parentObject

Returns the value of attribute parent.



65
66
67
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 65

def parent
  @parent
end

#titleObject

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_htmlObject



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