mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Don't re-order rules in css2sass.
This commit is contained in:
parent
13d240e9e4
commit
08afa18cde
2 changed files with 32 additions and 6 deletions
|
@ -273,21 +273,25 @@ module Sass
|
|||
# color: blue
|
||||
#
|
||||
def parent_ref_rules(root)
|
||||
rules = OrderedHash.new
|
||||
current_rule = nil
|
||||
root.children.select { |c| Tree::RuleNode === c }.each do |child|
|
||||
root.children.delete child
|
||||
first, rest = child.rules.first.scan(/^(&?(?: .|[^ ])[^.#: \[]*)([.#: \[].*)?$/).first
|
||||
rules[first] ||= Tree::RuleNode.new(first, {})
|
||||
|
||||
if current_rule.nil? || current_rule.rules.first != first
|
||||
current_rule = Tree::RuleNode.new(first, {})
|
||||
root << current_rule
|
||||
end
|
||||
|
||||
if rest
|
||||
child.rules = ["&" + rest]
|
||||
rules[first] << child
|
||||
current_rule << child
|
||||
else
|
||||
rules[first].children += child.children
|
||||
current_rule.children += child.children
|
||||
end
|
||||
end
|
||||
|
||||
rules.values.each { |v| parent_ref_rules(v) }
|
||||
root.children += rules.values
|
||||
root.children.each { |v| parent_ref_rules(v) }
|
||||
end
|
||||
|
||||
# Remove useless parent refs so that
|
||||
|
|
|
@ -51,6 +51,28 @@ li a:hover {
|
|||
CSS
|
||||
end
|
||||
|
||||
def test_no_nesting_around_rules
|
||||
assert_equal(<<SASS, css2sass(<<CSS))
|
||||
div .warning
|
||||
:color #d21a19
|
||||
|
||||
|
||||
span .debug
|
||||
:cursor crosshair
|
||||
|
||||
|
||||
div .debug
|
||||
:cursor default
|
||||
SASS
|
||||
div .warning {
|
||||
color: #d21a19; }
|
||||
span .debug {
|
||||
cursor: crosshair;}
|
||||
div .debug {
|
||||
cursor: default; }
|
||||
CSS
|
||||
end
|
||||
|
||||
def test_comments_multiline
|
||||
css = <<CSS
|
||||
/* comment */
|
||||
|
|
Loading…
Add table
Reference in a new issue