Class: MaRuKu::Section
Overview
A section in the table of contents of a document.
Instance Attribute Summary collapse
-
#header_element ⇒ MDElement
The ‘:header` node for this section.
-
#immediate_children ⇒ Array<MDElement>
The immediate child nodes of this section.
-
#section_children ⇒ Array<Section>
The subsections of this section.
-
#section_level ⇒ Fixnum
The depth of the section (0 for toplevel).
-
#section_number ⇒ Array<Fixnum>
The nested section number, e.g.
Instance Method Summary collapse
-
#initialize ⇒ Section
constructor
A new instance of Section.
- #inspect(indent = 1) ⇒ Object
-
#numerate ⇒ Object
Assign section numbers to this section and its children.
-
#to_html ⇒ Object
Returns an HTML representation of the table of contents.
-
#to_latex ⇒ Object
Returns a LaTeX representation of the table of contents.
Constructor Details
#initialize ⇒ Section
Returns a new instance of Section.
53 54 55 56 |
# File 'lib/maruku/toc.rb', line 53 def initialize @immediate_children = [] @section_children = [] end |
Instance Attribute Details
#header_element ⇒ MDElement
The ‘:header` node for this section. The value of `meta` for the header will be this node.
39 40 41 |
# File 'lib/maruku/toc.rb', line 39 def header_element @header_element end |
#immediate_children ⇒ Array<MDElement>
Why does this never contain Strings?
The immediate child nodes of this section.
46 47 48 |
# File 'lib/maruku/toc.rb', line 46 def immediate_children @immediate_children end |
#section_children ⇒ Array<Section>
The subsections of this section.
51 52 53 |
# File 'lib/maruku/toc.rb', line 51 def section_children @section_children end |
#section_level ⇒ Fixnum
The depth of the section (0 for toplevel).
Equivalent to ‘header_element.level`.
28 29 30 |
# File 'lib/maruku/toc.rb', line 28 def section_level @section_level end |
#section_number ⇒ Array<Fixnum>
The nested section number, e.g. ‘[1, 2, 5]` for Section 1.2.5.
33 34 35 |
# File 'lib/maruku/toc.rb', line 33 def section_number @section_number end |
Instance Method Details
#inspect(indent = 1) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/maruku/toc.rb', line 58 def inspect(indent = 1) s = "" if @header_element s << "\_" * indent << "(#{@section_level})>\t #{@section_number.join('.')} : " << @header_element.children_to_s << " (id: '#{@header_element.attributes[:id]}')\n" else s << "Master\n" end @section_children.each {|c| s << c.inspect(indent+1)} s end |
#numerate ⇒ Object
Assign section numbers to this section and its children. This also assigns the section number attribute to the sections’ headers.
This should only be called on the root section.
82 83 84 85 86 87 88 |
# File 'lib/maruku/toc.rb', line 82 def numerate(a = []) self.section_number = a section_children.each_with_index {|c, i| c.numerate(a + [i + 1])} if h = self.header_element h.attributes[:section_number] = self.section_number end end |
#to_html ⇒ Object
Returns an HTML representation of the table of contents.
This should only be called on the root section.
95 96 97 98 99 100 |
# File 'lib/maruku/toc.rb', line 95 def to_html div = Element.new 'div' div.attributes['class'] = 'maruku_toc' div << _to_html div end |
#to_latex ⇒ Object
Returns a LaTeX representation of the table of contents.
This should only be called on the root section.
105 106 107 |
# File 'lib/maruku/toc.rb', line 105 def to_latex _to_latex + "\n\n" end |