Class: Org::RootToken

Inherits:
Token
  • Object
show all
Defined in:
lib/org/to/toc.rb,
lib/org/to/html.rb

Instance Attribute Summary

Attributes inherited from Token

#block, #childs, #name, #options, #parent, #values

Instance Method Summary collapse

Methods inherited from Token

#<<, #initialize, #pretty_inspect

Constructor Details

This class inherits a constructor from Org::Token

Instance Method Details

#to_htmlObject

little optimization, avoid check for root



4
5
6
# File 'lib/org/to/html.rb', line 4

def to_html
  @childs.map{|child| child.to_html }.join
end

#to_tocObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/org/to/toc.rb', line 3

def to_toc
  found = @childs.map{|child| child.to_toc }.flatten.compact

  out = []
  nest = 0

  while token = found.shift
    level, text = *token.values
    level = level.size

    if level > nest
      out << '<ol>'
    elsif level < nest
      out << '</ol>'
    end
    nest = level

    out << "<li>#{token.toc_link}</li>"
  end

  nest.times do
    out << '</ol>'
  end

  out
end