mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Make the Tree::RuleNode API a little more consistent.
This commit is contained in:
parent
c6344a3cb1
commit
a2cb35e0ca
2 changed files with 10 additions and 18 deletions
|
@ -19,7 +19,7 @@ module Sass
|
||||||
|
|
||||||
class RuleNode
|
class RuleNode
|
||||||
def to_sass(tabs, opts = {})
|
def to_sass(tabs, opts = {})
|
||||||
str = "\n#{' ' * tabs}#{rule}#{children.any? { |c| c.is_a? AttrNode } ? "\n" : ''}"
|
str = "\n#{' ' * tabs}#{rules.first}#{children.any? { |c| c.is_a? AttrNode } ? "\n" : ''}"
|
||||||
|
|
||||||
children.each do |child|
|
children.each do |child|
|
||||||
str << "#{child.to_sass(tabs + 1, opts)}"
|
str << "#{child.to_sass(tabs + 1, opts)}"
|
||||||
|
@ -229,8 +229,8 @@ module Sass
|
||||||
# but it's necessary to get nesting to work properly.
|
# but it's necessary to get nesting to work properly.
|
||||||
def expand_commas(root)
|
def expand_commas(root)
|
||||||
root.children.map! do |child|
|
root.children.map! do |child|
|
||||||
next child unless Tree::RuleNode === child && child.rule.include?(',')
|
next child unless Tree::RuleNode === child && child.rules.first.include?(',')
|
||||||
child.rule.split(',').map do |rule|
|
child.rules.first.split(',').map do |rule|
|
||||||
node = Tree::RuleNode.new(rule.strip, {})
|
node = Tree::RuleNode.new(rule.strip, {})
|
||||||
node.children = child.children
|
node.children = child.children
|
||||||
node
|
node
|
||||||
|
@ -276,10 +276,10 @@ module Sass
|
||||||
rules = OrderedHash.new
|
rules = OrderedHash.new
|
||||||
root.children.select { |c| Tree::RuleNode === c }.each do |child|
|
root.children.select { |c| Tree::RuleNode === c }.each do |child|
|
||||||
root.children.delete child
|
root.children.delete child
|
||||||
first, rest = child.rule.scan(/^(&?(?: .|[^ ])[^.#: \[]*)([.#: \[].*)?$/).first
|
first, rest = child.rules.first.scan(/^(&?(?: .|[^ ])[^.#: \[]*)([.#: \[].*)?$/).first
|
||||||
rules[first] ||= Tree::RuleNode.new(first, {})
|
rules[first] ||= Tree::RuleNode.new(first, {})
|
||||||
if rest
|
if rest
|
||||||
child.rule = "&" + rest
|
child.rules = ["&" + rest]
|
||||||
rules[first] << child
|
rules[first] << child
|
||||||
else
|
else
|
||||||
rules[first].children += child.children
|
rules[first].children += child.children
|
||||||
|
@ -305,7 +305,7 @@ module Sass
|
||||||
def remove_parent_refs(root)
|
def remove_parent_refs(root)
|
||||||
root.children.each do |child|
|
root.children.each do |child|
|
||||||
if child.is_a?(Tree::RuleNode)
|
if child.is_a?(Tree::RuleNode)
|
||||||
child.rule.gsub! /^& +/, ''
|
child.rules.first.gsub! /^& +/, ''
|
||||||
remove_parent_refs child
|
remove_parent_refs child
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -342,10 +342,10 @@ module Sass
|
||||||
while rule.children.size == 1 && rule.children.first.is_a?(Tree::RuleNode)
|
while rule.children.size == 1 && rule.children.first.is_a?(Tree::RuleNode)
|
||||||
child = rule.children.first
|
child = rule.children.first
|
||||||
|
|
||||||
if child.rule[0] == ?&
|
if child.rules.first[0] == ?&
|
||||||
rule.rule = child.rule.gsub /^&/, rule.rule
|
rule.rules = [child.rules.first.gsub(/^&/, rule.rules.first)]
|
||||||
else
|
else
|
||||||
rule.rule = "#{rule.rule} #{child.rule}"
|
rule.rules = ["#{rule.rules.first} #{child.rules.first}"]
|
||||||
end
|
end
|
||||||
|
|
||||||
rule.children = child.children
|
rule.children = child.children
|
||||||
|
@ -374,7 +374,7 @@ module Sass
|
||||||
next child unless child.is_a?(Tree::RuleNode)
|
next child unless child.is_a?(Tree::RuleNode)
|
||||||
|
|
||||||
if prev_rule && prev_rule.children == child.children
|
if prev_rule && prev_rule.children == child.children
|
||||||
prev_rule.rule << ", #{child.rule}"
|
prev_rule.rules.first << ", #{child.rules.first}"
|
||||||
next nil
|
next nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,6 @@ module Sass::Tree
|
||||||
super(options)
|
super(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rule
|
|
||||||
rules.first
|
|
||||||
end
|
|
||||||
|
|
||||||
def rule=(rule)
|
|
||||||
self.rules = [rule]
|
|
||||||
end
|
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
self.class == other.class && rules == other.rules && super
|
self.class == other.class && rules == other.rules && super
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue