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

Merge branch 'stable'

This commit is contained in:
Nathan Weizenbaum 2009-10-08 04:14:30 -07:00
commit fb30b39b6d
4 changed files with 100 additions and 12 deletions

View file

@ -37,6 +37,16 @@ including the line number and the offending character.
* Fixed an `html2haml` issue where `#{}` wasn't escaped
before being transformed into Haml.
* Add `<code>` to the list of tags that's
{file:HAML_REFERENCE.md#preserve-option automatically whitespace-preserved}.
* Fixed a bug with `end` being followed by code in silent scripts -
it no longer throws an error when it's nested beneath tags.
* Fixed a bug with inner whitespace-nuking and conditionals.
The `else` et al. clauses of conditionals are now properly
whitespace-nuked.
## [2.2.6](http://github.com/nex3/haml/commit/2.2.6)
* Made the error message when unable to load a dependency for html2haml

View file

@ -72,9 +72,10 @@ module Haml
:suppress_eval => false,
:attr_wrapper => "'",
# Don't forget to update the docs in lib/haml.rb if you update these
# Don't forget to update the docs in doc-src/HAML_REFERENCE.md
# if you update these
:autoclose => %w[meta img link br hr input area param col base],
:preserve => %w[textarea pre],
:preserve => %w[textarea pre code],
:filename => '(haml)',
:line => 1,

View file

@ -186,7 +186,7 @@ END
return unless line.tabs <= @template_tabs && @template_tabs > 0
to_close = @template_tabs - line.tabs
to_close.times { |i| close unless to_close - 1 - i == 0 && mid_block_keyword?(line.text) }
to_close.times {|i| close unless to_close - 1 - i == 0 && mid_block_keyword?(line.text)}
end
# Processes a single line of Haml.
@ -228,12 +228,27 @@ END
newline_now
# Handle stuff like - end.join("|")
@to_close_stack.first << false if text =~ /^-\s*end\b/ && !block_opened?
@to_close_stack.last << false if text =~ /^-\s*end\b/ && !block_opened?
case_stmt = text =~ /^-\s*case\b/
block = block_opened? && !mid_block_keyword?(text)
push_and_tabulate([:script]) if block || case_stmt
push_and_tabulate(:nil) if block && case_stmt
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)
@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
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] == '!!!'
@ -247,10 +262,11 @@ END
end
end
# Returns whether or not the text is a silent script text with one
# of Ruby's mid-block keywords.
# If the text is a silent script text with one of Ruby's mid-block keywords,
# returns the name of that keyword.
# Otherwise, returns nil.
def mid_block_keyword?(text)
MID_BLOCK_KEYWORD_REGEX =~ text
text[MID_BLOCK_KEYWORD_REGEX, 1]
end
# Evaluates <tt>text</tt> in the context of the scope object, but
@ -398,7 +414,7 @@ END
end
# Closes a Ruby block.
def close_script(push_end = true)
def close_script(_1, _2, push_end = true)
push_silent("end", true) if push_end
@template_tabs -= 1
end
@ -433,7 +449,7 @@ END
@template_tabs -= 1
end
def close_nil
def close_nil(*args)
@template_tabs -= 1
end

View file

@ -232,6 +232,19 @@ HAML
SOURCE
end
def test_pre_code
assert_equal(<<HTML, render(<<HAML))
<pre><code>Foo&#x000A; bar&#x000A; baz</code></pre>
HTML
%pre
%code
:preserve
Foo
bar
baz
HAML
end
def test_boolean_attributes
assert_equal("<p bar baz='true' foo='bar'></p>\n",
render("%p{:foo => 'bar', :bar => true, :baz => 'true'}", :format => :html4))
@ -268,6 +281,36 @@ HTML
HAML
end
def test_whitespace_nuke_with_tags_and_else
assert_equal(<<HTML, render(<<HAML))
<a>
<b>foo</b>
</a>
HTML
%a
%b<
- if false
= "foo"
- else
foo
HAML
assert_equal(<<HTML, render(<<HAML))
<a>
<b>
foo
</b>
</a>
HTML
%a
%b
- if false
= "foo"
- else
foo
HAML
end
def test_both_case_indentation_work_with_deeply_nested_code
result = <<RESULT
<h2>
@ -334,6 +377,24 @@ HTML
HAML
end
def test_nested_end_with_method_call
assert_equal(<<HTML, render(<<HAML))
<p>
2|3|4
b-a-r
</p>
HTML
%p
= [1, 2, 3].map do |i|
- i + 1
- end.join("|")
= "bar".gsub(/./) do |s|
- s + "-"
- end.gsub(/-$/) do |s|
- ''
HAML
end
def test_silent_end_with_stuff
assert_equal(<<HTML, render(<<HAML))
e