From 0b1d5c48d9c55d7d2e7c7cbafc4512c01e1392fb Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Tue, 29 Apr 2008 15:09:07 -0700 Subject: [PATCH] Fix a css2sass bug. Rule-flattening wasn't working quite properly. foo.bar { baz: boom } would render as foo &.bar baz: boom --- lib/sass/css.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/sass/css.rb b/lib/sass/css.rb index 11989670..fa2b6e57 100644 --- a/lib/sass/css.rb +++ b/lib/sass/css.rb @@ -313,6 +313,17 @@ module Sass # foo bar baz # color: red # + # and + # + # foo + # &.bar + # color: blue + # + # becomes + # + # foo.bar + # color: blue + # def flatten_rules(root) root.children.each { |child| flatten_rule(child) if child.is_a?(Tree::RuleNode) } end @@ -320,7 +331,13 @@ module Sass def flatten_rule(rule) while rule.children.size == 1 && rule.children.first.is_a?(Tree::RuleNode) child = rule.children.first - rule.rule = "#{rule.rule} #{child.rule}" + + if child.rule[0] == ?& + rule.rule = child.rule.gsub /^&/, rule.rule + else + rule.rule = "#{rule.rule} #{child.rule}" + end + rule.children = child.children end