mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Haml] Fix an obscure if statement bug.
For example: - if foo - if bar - else baz
This commit is contained in:
parent
380c7773b7
commit
21436193f4
3 changed files with 13 additions and 11 deletions
|
@ -7,6 +7,8 @@
|
|||
|
||||
* Allow CSS-style classes and ids to contain colons.
|
||||
|
||||
* Fix an obscure bug with if statements.
|
||||
|
||||
## 3.0.13
|
||||
|
||||
[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.12).
|
||||
|
|
|
@ -242,29 +242,20 @@ END
|
|||
# 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
|
||||
@dont_indent_next_line, @dont_tab_up_next_text = @to_close_stack.last[1..2]
|
||||
|
||||
# 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
|
||||
elsif block || text =~ /^-\s*(case|if)\b/
|
||||
push_and_tabulate([:script, @dont_indent_next_line, @dont_tab_up_next_text])
|
||||
end
|
||||
when FILTER; start_filtered(text[1..-1].downcase)
|
||||
|
|
|
@ -668,6 +668,15 @@ HTML
|
|||
- else
|
||||
foo
|
||||
HAML
|
||||
|
||||
assert_equal(<<HTML, render(<<HAML))
|
||||
foo
|
||||
HTML
|
||||
- if true
|
||||
- if false
|
||||
- else
|
||||
foo
|
||||
HAML
|
||||
end
|
||||
|
||||
def test_html_attributes_with_hash
|
||||
|
|
Loading…
Add table
Reference in a new issue