module Haml::Precompiler
def process_line(text, index)
This method doesn't return anything; it simply processes the line and
Processes a single line of Haml.
def process_line(text, index) @index = index + 1 case text[0] when DIV_CLASS; render_div(text) when DIV_ID return push_plain(text) if text[1] == ?{ render_div(text) when ELEMENT; render_tag(text) when COMMENT; render_comment(text[1..-1].strip) when SANITIZE return push_plain(text[3..-1].strip, :escape_html => true) if text[1..2] == "==" return push_script(text[2..-1].strip, :escape_html => true) if text[1] == SCRIPT return push_flat_script(text[2..-1].strip, :escape_html => true) if text[1] == FLAT_SCRIPT return push_plain(text[1..-1].strip, :escape_html => true) if text[1] == ?\s push_plain text when SCRIPT return push_plain(text[2..-1].strip) if text[1] == SCRIPT push_script(text[1..-1]) when FLAT_SCRIPT; push_flat_script(text[1..-1]) when SILENT_SCRIPT return start_haml_comment if text[1] == SILENT_COMMENT raise SyntaxError.new(<<END.rstrip, index) if text[1..-1].strip == "end" don't need to use "- end" in Haml. Use indentation instead: foo? trong Foo! se t foo. push_silent(text[1..-1], true) newline_now # Handle stuff like - end.join("|") @to_close_stack.last << false if text =~ /^-\s*end\b/ && !block_opened? case_stmt = text =~ /^-\s*case\b/ keyword = mid_block_keyword?(text) block = block_opened? && !keyword # It's important to preserve tabulation modification for keywords # that involve choosing between posible blocks of code. if %w[else elsif when].include?(keyword) # @to_close_stack may not have a :script on top # when the preceding "- if" has nothing nested if @to_close_stack.last && @to_close_stack.last.first == :script @dont_indent_next_line, @dont_tab_up_next_text = @to_close_stack.last[1..2] else push_and_tabulate([:script, @dont_indent_next_line, @dont_tab_up_next_text]) end # when is unusual in that either it will be indented twice, # or the case won't have created its own indentation if keyword == "when" push_and_tabulate([:script, @dont_indent_next_line, @dont_tab_up_next_text, false]) end elsif block || case_stmt push_and_tabulate([:script, @dont_indent_next_line, @dont_tab_up_next_text]) elsif block && case_stmt push_and_tabulate([:script, @dont_indent_next_line, @dont_tab_up_next_text]) end when FILTER; start_filtered(text[1..-1].downcase) when DOCTYPE return render_doctype(text) if text[0...3] == '!!!' return push_plain(text[3..-1].strip, :escape_html => false) if text[1..2] == "==" return push_script(text[2..-1].strip, :escape_html => false) if text[1] == SCRIPT return push_flat_script(text[2..-1].strip, :escape_html => false) if text[1] == FLAT_SCRIPT return push_plain(text[1..-1].strip, :escape_html => false) if text[1] == ?\s push_plain text when ESCAPE; push_plain text[1..-1] else push_plain text end end