[Haml] Allow regular expressions in :autoclose.
This commit is contained in:
parent
c331c3b8f9
commit
27f6df9208
|
@ -12,6 +12,11 @@ for a given object by implementing the `haml_object_ref` method on that object.
|
|||
This method should return a string that will be used in place of the class name of the object
|
||||
in the generated class and id.
|
||||
|
||||
### More Powerful `:autoclose` Option
|
||||
|
||||
The {file:HAML_REFERENCE.md#attributes_option `:attributes`} option
|
||||
can now take regular expressions that specify which tags to make self-closing.
|
||||
|
||||
### `--double-quote-attributes` Option
|
||||
|
||||
The Haml executable now has a `--double-quote-attributes` option (short form: `-q`)
|
||||
|
|
|
@ -173,6 +173,8 @@ Available options are:
|
|||
{#autoclose-option} `:autoclose`
|
||||
: A list of tag names that should be automatically self-closed
|
||||
if they have no content.
|
||||
This can also contain regular expressions that match tag names
|
||||
(or any object which responds to `#===`).
|
||||
Defaults to `['meta', 'img', 'link', 'br', 'hr', 'input', 'area', 'param', 'col', 'base']`.
|
||||
|
||||
{#preserve-option} `:preserve`
|
||||
|
|
|
@ -744,7 +744,7 @@ END
|
|||
raise SyntaxError.new("There's no Ruby code for #{action} to evaluate.", last_line - 1) if parse && value.empty?
|
||||
raise SyntaxError.new("Self-closing tags can't have content.", last_line - 1) if self_closing && !value.empty?
|
||||
|
||||
self_closing ||= !!( !block_opened? && value.empty? && @options[:autoclose].include?(tag_name) )
|
||||
self_closing ||= !!(!block_opened? && value.empty? && @options[:autoclose].any? {|t| t === tag_name})
|
||||
value = nil if value.empty? && (block_opened? || self_closing)
|
||||
|
||||
dont_indent_next_line =
|
||||
|
|
|
@ -764,13 +764,26 @@ HAML
|
|||
assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n", render("!!! XML", :attr_wrapper => '"'))
|
||||
end
|
||||
|
||||
def test_autoclose_option
|
||||
assert_equal("<flaz foo='bar' />\n", render("%flaz{:foo => 'bar'}", :autoclose => ["flaz"]))
|
||||
assert_equal(<<HTML, render(<<HAML, :autoclose => [/^flaz/]))
|
||||
<flaz />
|
||||
<flaznicate />
|
||||
<flan></flan>
|
||||
HTML
|
||||
%flaz
|
||||
%flaznicate
|
||||
%flan
|
||||
HAML
|
||||
end
|
||||
|
||||
def test_attrs_parsed_correctly
|
||||
assert_equal("<p boom=>biddly='bar => baz'></p>\n", render("%p{'boom=>biddly' => 'bar => baz'}"))
|
||||
assert_equal("<p foo,bar='baz, qux'></p>\n", render("%p{'foo,bar' => 'baz, qux'}"))
|
||||
assert_equal("<p escaped='quo
te'></p>\n", render("%p{ :escaped => \"quo\\nte\"}"))
|
||||
assert_equal("<p escaped='quo4te'></p>\n", render("%p{ :escaped => \"quo\#{2 + 2}te\"}"))
|
||||
end
|
||||
|
||||
|
||||
def test_correct_parsing_with_brackets
|
||||
assert_equal("<p class='foo'>{tada} foo</p>\n", render("%p{:class => 'foo'} {tada} foo"))
|
||||
assert_equal("<p class='foo'>deep {nested { things }}</p>\n", render("%p{:class => 'foo'} deep {nested { things }}"))
|
||||
|
|
Loading…
Reference in New Issue