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

Merge branch 'stable'

Conflicts:
	doc-src/SASS_CHANGELOG.md
	lib/sass/tree/node.rb
	lib/sass/tree/prop_node.rb
	test/sass/css2sass_test.rb
	test/sass/engine_test.rb
This commit is contained in:
Nathan Weizenbaum 2009-10-31 02:46:00 -07:00
commit eb7e448418
7 changed files with 87 additions and 13 deletions

View file

@ -51,6 +51,17 @@ Several bug fixes and minor improvements have been made, including:
* Displaying the expected strings as strings rather than regular expressions
whenever possible.
## 2.2.11 (Unreleased)
* Added a note to errors on properties that could be pseudo-classes (e.g. `:focus`)
indicating that they should be backslash-escaped.
* Automatically interpret properties that could be pseudo-classes as such
if {file:SASS_REFERENCE.md.html#property_syntax-option `:property_syntax`}
is set to `:new`.
* Fixed `css2sass`'s generation of pseudo-classes so that they're backslash-escaped.
## [2.2.10](http://github.com/nex3/haml/commit/2.2.10)
* Add support for attribute selectors with spaces around the `=`.

View file

@ -24,7 +24,9 @@ module Sass
class RuleNode
# @see Node#to_sass
def to_sass(tabs, opts = {})
str = "\n#{' ' * tabs}#{rules.first}#{children.any? { |c| c.is_a? PropNode } ? "\n" : ''}"
name = rules.first
name = "\\" + name if name[0] == ?:
str = "\n#{' ' * tabs}#{name}#{children.any? { |c| c.is_a? PropNode } ? "\n" : ''}"
children.each do |child|
str << "#{child.to_sass(tabs + 1, opts)}"

View file

@ -329,12 +329,16 @@ LONG
def parse_line(parent, line, root)
case line.text[0]
when PROPERTY_CHAR
if line.text[1] != PROPERTY_CHAR
parse_property(line, PROPERTY_OLD)
else
if line.text[1] == PROPERTY_CHAR ||
(@options[:property_syntax] == :new &&
line.text =~ PROPERTY_OLD && $3.empty?)
# Support CSS3-style pseudo-elements,
# which begin with ::
# which begin with ::,
# as well as pseudo-classes
# if we're using the new property syntax
Tree::RuleNode.new(line.text)
else
parse_property(line, PROPERTY_OLD)
end
when Script::VARIABLE_CHAR
parse_variable(line)

View file

@ -47,6 +47,16 @@ module Sass::Tree
self.class == other.class && name == other.name && value == other.value && super
end
# Returns a appropriate message indicating how to escape pseudo-class selectors.
# This only applies for old-style properties with no value,
# so returns the empty string if this is new-style.
#
# @return [String] The message
def pseudo_class_selector_message
return "" if @prop_syntax == :new || !value.empty?
"\nIf #{declaration.dump} should be a selector, use \"\\#{declaration}\" instead."
end
protected
# Computes the CSS for the property.
@ -62,7 +72,8 @@ module Sass::Tree
elsif value[-1] == ?;
raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no \";\" required at end-of-line).")
elsif value.empty?
raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no value).")
raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no value)." +
pseudo_class_selector_message)
end
to_return = ' ' * (tabs - 1 + indentation) + name + ":" +
@ -112,7 +123,7 @@ module Sass::Tree
private
def declaration
@prop_syntax == :new ? "#{name}: #{value}" : ":#{name} #{value}"
(@prop_syntax == :new ? "#{name}: #{value}" : ":#{name} #{value}").strip
end
end
end

View file

@ -40,8 +40,11 @@ module Sass
def _to_s(*args)
result = String.new
children.each do |child|
raise Sass::SyntaxError.new('Properties aren\'t allowed at the root of a document.',
:line => child.line) if child.is_a? PropNode
if child.is_a? PropNode
message = "Properties aren't allowed at the root of a document." +
child.pseudo_class_selector_message
raise Sass::SyntaxError.new(message, :line => child.line)
end
next if child.invisible?
child_str = child.to_s(1)

View file

@ -230,6 +230,19 @@ SASS
CSS
end
def test_pseudo_classes_are_escaped
assert_equal(<<SASS, css2sass(<<CSS))
\\:focus
a: b
\\:foo
bar: baz
SASS
:focus {a: b;}
:focus :foo {bar: baz;}
CSS
end
# Error reporting
def test_error_reporting

View file

@ -18,8 +18,11 @@ class SassEngineTest < Test::Unit::TestCase
":" => 'Invalid property: ":".',
": a" => 'Invalid property: ": a".',
":= a" => 'Invalid property: ":= a".',
"a\n :b" => 'Invalid property: ":b " (no value).',
"a\n b:" => 'Invalid property: "b: " (no value).',
"a\n :b" => <<MSG,
Invalid property: ":b" (no value).
If ":b" should be a selector, use "\\:b" instead.
MSG
"a\n b:" => 'Invalid property: "b:" (no value).',
"a\n :b: c" => 'Invalid property: ":b: c".',
"a\n :b:c d" => 'Invalid property: ":b:c d".',
"a\n :b=c d" => 'Invalid property: ":b=c d".',
@ -28,6 +31,12 @@ class SassEngineTest < Test::Unit::TestCase
"a\n b : c" => 'Invalid property: "b : c".',
"a\n b=c: d" => 'Invalid property: "b=c: d".',
"a: b" => 'Properties aren\'t allowed at the root of a document.',
":a b" => 'Properties aren\'t allowed at the root of a document.',
"a:" => 'Properties aren\'t allowed at the root of a document.',
":a" => <<MSG,
Properties aren't allowed at the root of a document.
If ":a" should be a selector, use "\\:a" instead.
MSG
"!" => 'Invalid variable: "!".',
"!a" => 'Invalid variable: "!a".',
"! a" => 'Invalid variable: "! a".',
@ -134,7 +143,7 @@ class SassEngineTest < Test::Unit::TestCase
rescue Sass::SyntaxError => err
value = [value] unless value.is_a?(Array)
assert_equal(value.first, err.message, "Line: #{key}")
assert_equal(value.first.rstrip, err.message, "Line: #{key}")
assert_equal(__FILE__, err.sass_filename)
assert_equal((value[1] || key.split("\n").length) + line - 1, err.sass_line, "Line: #{key}")
assert_match(/#{Regexp.escape(__FILE__)}:[0-9]+/, err.backtrace[0], "Line: #{key}")
@ -233,7 +242,7 @@ SASS
rescue Sass::SyntaxError => e
assert_equal(<<CSS, Sass::SyntaxError.exception_to_css(e, opts).split("\n")[0..15].join("\n"))
/*
Syntax error: Invalid property: "e: " (no value).
Syntax error: Invalid property: "e:" (no value).
on line 383 of test_exception_css_with_offset_inline.sass
378: a
@ -822,6 +831,27 @@ bang, bip, bop
SASS
end
def test_root_level_pseudo_class_with_new_properties
assert_equal(<<CSS, render(<<SASS, :property_syntax => :new))
:focus {
outline: 0; }
CSS
:focus
outline: 0
SASS
end
def test_pseudo_class_with_new_properties
assert_equal(<<CSS, render(<<SASS, :property_syntax => :new))
p :focus {
outline: 0; }
CSS
p
:focus
outline: 0
SASS
end
# Regression tests
def test_parens_in_mixins