Class: MaRuKu::Section
- Inherits:
-
Object
- Object
- MaRuKu::Section
- Defined in:
- lib/maruku/toc.rb
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.
34 35 36 37 |
# File 'lib/maruku/toc.rb', line 34 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.
20 21 22 |
# File 'lib/maruku/toc.rb', line 20 def header_element @header_element end |
#immediate_children ⇒ Array<MDElement>
Why does this never contain Strings?
The immediate child nodes of this section.
27 28 29 |
# File 'lib/maruku/toc.rb', line 27 def immediate_children @immediate_children end |
#section_children ⇒ Array<Section>
The subsections of this section.
32 33 34 |
# File 'lib/maruku/toc.rb', line 32 def section_children @section_children end |
#section_level ⇒ Fixnum
The depth of the section (0 for toplevel).
Equivalent to ‘header_element.level`.
9 10 11 |
# File 'lib/maruku/toc.rb', line 9 def section_level @section_level end |
#section_number ⇒ Array<Fixnum>
The nested section number, e.g. ‘[1, 2, 5]` for Section 1.2.5.
14 15 16 |
# File 'lib/maruku/toc.rb', line 14 def section_number @section_number end |
Instance Method Details
#inspect(indent = 1) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/maruku/toc.rb', line 39 def inspect(indent = 1) 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.
61 62 63 64 65 66 67 |
# File 'lib/maruku/toc.rb', line 61 def numerate(a = []) self.section_number = a self.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.
73 74 75 |
# File 'lib/maruku/toc.rb', line 73 def to_html MaRuKu::Out::HTML::HTMLElement.new('div', { 'class' => 'maruku_toc' }, _to_html) end |
#to_latex ⇒ Object
Returns a LaTeX representation of the table of contents.
This should only be called on the root section.
80 81 82 |
# File 'lib/maruku/toc.rb', line 80 def to_latex _to_latex + "\n\n" end |