Expand commas in css2sass so that at least they'll render properly. Not a perfect solution.

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

View File

@ -118,6 +118,7 @@ module Sass
whitespace whitespace
directives root directives root
rules root rules root
expand_commas root
nest_rules root nest_rules root
flatten_rules root flatten_rules root
root root
@ -194,6 +195,34 @@ module Sass
whitespace whitespace
end end
# Transform
#
# foo, bar, baz
# color: blue
#
# into
#
# foo
# color: blue
# bar
# color: blue
# baz
# color: blue
#
# Yes, this expands the amount of code,
# but it's necessary to get nesting to work properly.
def expand_commas(root)
root.children.map! do |child|
next child unless Tree::RuleNode === child && child.rule.include?(',')
child.rule.split(',').map do |rule|
node = Tree::RuleNode.new(rule, nil)
node.children = child.children
node
end
end
root.children.flatten!
end
# Nest rules so that # Nest rules so that
# #
# foo # foo
@ -214,8 +243,7 @@ module Sass
# #
def nest_rules(root) def nest_rules(root)
rules = OrderedHash.new rules = OrderedHash.new
root.children.dup.each do |child| root.children.select { |c| Tree::RuleNode === c }.each do |child|
next unless child.is_a? Tree::RuleNode
root.children.delete child root.children.delete child
first, rest = child.rule.split(' ', 2) first, rest = child.rule.split(' ', 2)
rules[first] ||= Tree::RuleNode.new(first, nil) rules[first] ||= Tree::RuleNode.new(first, nil)