1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Allow for case statements with indented when

Case statements can either be all indented to the same level, or the
when clauses (and possible else clause) can all be indented in from the
opening `case`.

Allow for this, and don't raise SyntaxError if there is an else clause.
This commit is contained in:
Matt Wildig 2012-08-17 01:28:00 +01:00
parent 9a77742f36
commit 7cb7d55fab

View file

@ -291,11 +291,20 @@ module Haml
check_push_script_stack(keyword)
if ["else", "elsif"].include?(keyword)
if ["else", "elsif", "when"].include?(keyword)
if @script_level_stack.empty?
raise Haml::SyntaxError.new(Error.message(:missing_if, keyword), @line.index)
elsif @script_level_stack.last != @line.tabs
message = Error.message(:bad_script_indent, keyword, @script_level_stack.last, @line.tabs)
end
if keyword == 'when' and !@script_level_stack.last[2]
if @script_level_stack.last[1] + 1 == @line.tabs
@script_level_stack.last[1] += 1
end
@script_level_stack.last[2] = true
end
if @script_level_stack.last[1] != @line.tabs
message = Error.message(:bad_script_indent, keyword, @script_level_stack.last[1], @line.tabs)
raise Haml::SyntaxError.new(message, @line.index)
end
end
@ -306,7 +315,10 @@ module Haml
def check_push_script_stack(keyword)
if ["if", "case", "unless"].include?(keyword)
@script_level_stack.push(@line.tabs)
# @script_level_stack contents are arrays of form
# [:keyword, stack_level, other_info]
@script_level_stack.push([keyword.to_sym, @line.tabs])
@script_level_stack.last << false if keyword == 'case'
@tab_up = true
end
end