mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
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:
parent
0f41f43e76
commit
c882b2d332
1 changed files with 30 additions and 2 deletions
|
@ -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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue