Try to be better about preserving commas in css2sass.

git-svn-id: svn://hamptoncatlin.com/haml/trunk@702 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2007-12-16 22:50:59 +00:00
parent c882b2d332
commit acda22070f
1 changed files with 32 additions and 0 deletions

View File

@ -121,6 +121,7 @@ module Sass
expand_commas root
nest_rules root
flatten_rules root
fold_commas root
root
end
@ -284,5 +285,36 @@ module Sass
flatten_rules(rule)
end
# Transform
#
# foo
# bar
# color: blue
# baz
# color: blue
#
# into
#
# foo
# bar, baz
# color: blue
#
def fold_commas(root)
prev_rule = nil
root.children.map! do |child|
next child unless Tree::RuleNode === child
if prev_rule && prev_rule.children == child.children
prev_rule.rule << ", #{child.rule}"
next nil
end
fold_commas(child)
prev_rule = child
child
end
root.children.compact!
end
end
end