Class: Teepee::Parser

Inherits:
ParserNode show all
Defined in:
lib/teepee/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ParserNode

#use_scope

Constructor Details

#initialize(text) ⇒ Parser

Returns a new instance of Parser.



63
64
65
66
67
68
# File 'lib/teepee/parser.rb', line 63

def initialize(text)
  @variables = Hash.new
  @text = text
  @tokenizer = Tokenizer.new text
  parse
end

Instance Attribute Details

#paragraphsObject (readonly)

Returns the value of attribute paragraphs.



57
58
59
# File 'lib/teepee/parser.rb', line 57

def paragraphs
  @paragraphs
end

#split_tokensObject (readonly)

Returns the value of attribute split_tokens.



57
58
59
# File 'lib/teepee/parser.rb', line 57

def split_tokens
  @split_tokens
end

#textObject (readonly)

Returns the value of attribute text.



57
58
59
# File 'lib/teepee/parser.rb', line 57

def text
  @text
end

#tokenizerObject (readonly)

Returns the value of attribute tokenizer.



57
58
59
# File 'lib/teepee/parser.rb', line 57

def tokenizer
  @tokenizer
end

#variablesObject

Returns the value of attribute variables.



56
57
58
# File 'lib/teepee/parser.rb', line 56

def variables
  @variables
end

Instance Method Details

#parseObject



70
71
72
73
# File 'lib/teepee/parser.rb', line 70

def parse
  @split_tokens = tokens.split {|token| token.class == EmptyNewlinesToken}
  @paragraphs = @split_tokens.map {|split_tokens| ParagraphParser.new(self, split_tokens)}
end

#to_htmlObject



75
76
77
# File 'lib/teepee/parser.rb', line 75

def to_html
  paragraphs.map(&:to_html).join "\n"
end

#tokensObject



59
60
61
# File 'lib/teepee/parser.rb', line 59

def tokens
  tokenizer.tokens
end