From c882b2d33275b574615fded8516f9d02da34d710 Mon Sep 17 00:00:00 2001 From: nex3 Date: Sun, 16 Dec 2007 22:22:56 +0000 Subject: [PATCH] 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 --- lib/sass/css.rb | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/sass/css.rb b/lib/sass/css.rb index fbff0391..dc619c16 100644 --- a/lib/sass/css.rb +++ b/lib/sass/css.rb @@ -118,6 +118,7 @@ module Sass whitespace directives root rules root + expand_commas root nest_rules root flatten_rules root root @@ -194,6 +195,34 @@ module Sass whitespace 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 # # foo @@ -214,8 +243,7 @@ module Sass # def nest_rules(root) rules = OrderedHash.new - root.children.dup.each do |child| - next unless child.is_a? Tree::RuleNode + root.children.select { |c| Tree::RuleNode === c }.each do |child| root.children.delete child first, rest = child.rule.split(' ', 2) rules[first] ||= Tree::RuleNode.new(first, nil)