Class: Haml::Parser
Defined Under Namespace
Classes: ParseNode
Constant Summary
Instance Attribute Summary (collapse)
-
- root
readonly
Returns the value of attribute root.
Instance Method Summary (collapse)
-
- (Parser) initialize(template, options)
constructor
A new instance of Parser.
- - parse
Methods included from Util
#av_template_class, #caller_info, #check_encoding, #check_haml_encoding, #contains_interpolation?, #def_static_method, #handle_interpolation, #html_safe, #human_indentation, #inspect_obj, #powerset, #rails_xss_safe?, #silence_warnings, #static_method_name, #unescape_interpolation
Constructor Details
- (Parser) initialize(template, options)
Returns a new instance of Parser
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/haml/parser.rb', line 88
def initialize(template, options)
# :eod is a special end-of-document marker
@template = (template.rstrip).split(/\r\n|\r|\n/) + [:eod, :eod]
@options = options
@flat = false
@index = 0
# Record the indent levels of "if" statements to validate the subsequent
# elsif and else statements are indented at the appropriate level.
@script_level_stack = []
@template_index = 0
@template_tabs = 0
end
|
Instance Attribute Details
- root (readonly)
Returns the value of attribute root
7 8 9 |
# File 'lib/haml/parser.rb', line 7
def root
@root
end
|
Instance Method Details
- parse
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/haml/parser.rb', line 101
def parse
@root = @parent = ParseNode.new(:root)
@haml_comment = false
@indentation = nil
@line = next_line
raise SyntaxError.new(Error.message(:indenting_at_start), @line.index) if @line.tabs != 0
while next_line
process_indent(@line) unless @line.text.empty?
if flat?
text = @line.full.dup
text = "" unless text.gsub!(/^#{@flat_spaces}/, '')
@filter_buffer << "#{text}\n"
@line = @next_line
next
end
@tab_up = nil
process_line(@line.text, @line.index) unless @line.text.empty? || @haml_comment
if @parent.type != :haml_comment && (block_opened? || @tab_up)
@template_tabs += 1
@parent = @parent.children.last
end
if !@haml_comment && !flat? && @next_line.tabs - @line.tabs > 1
raise SyntaxError.new(Error.message(:deeper_indenting, @next_line.tabs - @line.tabs), @next_line.index)
end
@line = @next_line
end
# Close all the open tags
close until @parent.type == :root
@root
rescue Haml::Error => e
e.backtrace.unshift "#{@options[:filename]}:#{(e.line ? e.line + 1 : @index) + @options[:line] - 1}"
raise
end
|