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

[Sass] Fix a bug with comments that shouldn't be rendered.

Closes gh-4
This commit is contained in:
Nathan Weizenbaum 2009-05-08 13:42:39 -07:00
parent 95c2e6fd4d
commit 83ac8c4a69
6 changed files with 62 additions and 2 deletions

View file

@ -35,6 +35,7 @@ module Sass::Tree
end
children.each do |kid|
next if kid.invisible?
to_return << kid.to_s(tabs, real_name) << join_string
end

View file

@ -20,11 +20,22 @@ module Sass::Tree
end
def to_s(tabs = 0, parent_name = nil)
return if (@style == :compressed || silent?)
return if invisible?
spaces = ' ' * (tabs - 1)
spaces + "/* " + ([value] + lines.map {|l| l.text}).
map{|l| l.sub(%r{ ?\*/ *$},'')}.join(@style == :compact ? ' ' : "\n#{spaces} * ") + " */"
end
def invisible?
@style == :compressed || silent?
end
protected
def _perform(environment)
return [] if silent?
self
end
end
end

View file

@ -19,6 +19,7 @@ module Sass::Tree
was_attr = false
first = true
children.each do |child|
next if child.invisible?
if @style == :compact
if child.is_a?(AttrNode)
result << "#{child.to_s(first || was_attr ? 1 : tabs + 1)} "

View file

@ -27,14 +27,16 @@ module Sass
self.class == other.class && other.children == children
end
def invisible?; false; end
def to_s
result = String.new
children.each do |child|
if child.is_a? AttrNode
raise Sass::SyntaxError.new('Attributes aren\'t allowed at the root of a document.', child.line)
else
next if child.invisible?
child_str = child.to_s(1)
next unless child_str && child_str.length > 0
result << child_str + (@style == :compressed ? '' : "\n")
end
end

View file

@ -40,6 +40,7 @@ module Sass::Tree
end.join(line_separator)
children.each do |child|
next if child.invisible?
if child.is_a? RuleNode
sub_rules << child
else

View file

@ -681,6 +681,50 @@ a
SASS
end
# Regression tests
def test_comment_beneath_attr
assert_equal(<<RESULT, render(<<SOURCE))
.box {
border-style: solid; }
RESULT
.box
:border
//:color black
:style solid
SOURCE
assert_equal(<<RESULT, render(<<SOURCE))
.box {
/* :color black */
border-style: solid; }
RESULT
.box
:border
/*:color black
:style solid
SOURCE
assert_equal(<<RESULT, render(<<SOURCE, :style => :compressed))
.box{border-style:solid}
RESULT
.box
:border
/*:color black
:style solid
SOURCE
end
def test_compressed_comment_beneath_directive
assert_equal(<<RESULT, render(<<SOURCE, :style => :compressed))
@foo{a:b}
RESULT
@foo
a: b
/*b: c
SOURCE
end
private
def render(sass, options = {})