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

[Haml] Allow CSS-style classes and ids to contain colons.

Closes gh-206
This commit is contained in:
Nathan Weizenbaum 2010-07-05 14:20:26 -07:00
parent fca8f48bc2
commit d66f088e5f
4 changed files with 22 additions and 2 deletions

View file

@ -3,6 +3,10 @@
* Table of contents
{:toc}
## 3.0.14 (Unreleased)
* Allow CSS-style classes and ids to contain colons.
## 3.0.13
[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.12).

View file

@ -491,7 +491,7 @@ END
# that can then be merged with another attributes hash.
def self.parse_class_and_id(list)
attributes = {}
list.scan(/([#.])([-_a-zA-Z0-9]+)/) do |type, property|
list.scan(/([#.])([-:_a-zA-Z0-9]+)/) do |type, property|
case type
when '.'
if attributes['class']
@ -573,7 +573,7 @@ END
# Parses a line into tag_name, attributes, attributes_hash, object_ref, action, value
def parse_tag(line)
raise SyntaxError.new("Invalid tag: \"#{line}\".") unless match = line.scan(/%([-:\w]+)([-\w\.\#]*)(.*)/)[0]
raise SyntaxError.new("Invalid tag: \"#{line}\".") unless match = line.scan(/%([-:\w]+)([-:\w\.\#]*)(.*)/)[0]
tag_name, attributes, rest = match
new_attributes_hash = old_attributes_hash = last_line = object_ref = nil
attributes_hashes = []

View file

@ -165,6 +165,14 @@ MESSAGE
assert_equal("<p id='html_a_b'>foo</p>\n", render("%p(id='html'){:id => %w[a b]} foo")) # html attrs
end
def test_colon_in_class_attr
assert_equal("<p class='foo:bar' />\n", render("%p.foo:bar/"))
end
def test_colon_in_id_attr
assert_equal("<p id='foo:bar' />\n", render("%p#foo:bar/"))
end
def test_dynamic_attributes_with_no_content
assert_equal(<<HTML, render(<<HAML))
<p>

View file

@ -180,6 +180,10 @@ HAML
assert_equal("<p id='some_id'></p>\n", render("- haml_tag 'p#some_id'"))
end
def test_haml_tag_name_attribute_with_colon_id
assert_equal("<p id='some:id'></p>\n", render("- haml_tag 'p#some:id'"))
end
def test_haml_tag_without_name_but_with_id
assert_equal("<div id='some_id'></div>\n", render("- haml_tag '#some_id'"))
end
@ -188,6 +192,10 @@ HAML
assert_equal("<div class='foo'></div>\n", render("- haml_tag '.foo'"))
end
def test_haml_tag_without_name_but_with_colon_class
assert_equal("<div class='foo:bar'></div>\n", render("- haml_tag '.foo:bar'"))
end
def test_haml_tag_name_with_id_and_class
assert_equal("<p class='foo' id='some_id'></p>\n", render("- haml_tag 'p#some_id.foo'"))
end