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) ⇒ Heading

Returns a new instance of Heading.



55
56
57
58
59
60
61
62
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 55

def initialize(title, level, index)
  @title = title
  @level = level
  @index = index
  @parent = nil
  @children = []
  super()
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



53
54
55
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 53

def children
  @children
end

#indexObject

Returns the value of attribute index.



53
54
55
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 53

def index
  @index
end

#levelObject

Returns the value of attribute level.



53
54
55
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 53

def level
  @level
end

#parentObject

Returns the value of attribute parent.



53
54
55
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 53

def parent
  @parent
end

#titleObject

Returns the value of attribute title.



53
54
55
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 53

def title
  @title
end

Instance Method Details

#<<(h) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 64

def <<(h)
  @children.each { |child|
    return if child.title == h.title
  }

  h.parent = self
  @children << h
end

#to_htmlObject



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/pagehub-markdown/processors/toc_generator.rb', line 73

def to_html()
  html = ""
  html << "<li>"
  html << "<a href=\"\#toc_#{index}\">" << title << "</a>"

  if children.any? then
    html << "<ol>"
    children.each { |child| html << child.to_html }
    html << "</ol>"
  end

  html << "</li>"
end