haml-edge 2.1.4 → 2.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/EDGE_GEM_VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.4
1
+ 2.1.5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.4
1
+ 2.1.5
data/lib/sass/css.rb CHANGED
@@ -273,21 +273,25 @@ module Sass
273
273
  # color: blue
274
274
  #
275
275
  def parent_ref_rules(root)
276
- rules = OrderedHash.new
276
+ current_rule = nil
277
277
  root.children.select { |c| Tree::RuleNode === c }.each do |child|
278
278
  root.children.delete child
279
279
  first, rest = child.rules.first.scan(/^(&?(?: .|[^ ])[^.#: \[]*)([.#: \[].*)?$/).first
280
- rules[first] ||= Tree::RuleNode.new(first, {})
280
+
281
+ if current_rule.nil? || current_rule.rules.first != first
282
+ current_rule = Tree::RuleNode.new(first, {})
283
+ root << current_rule
284
+ end
285
+
281
286
  if rest
282
287
  child.rules = ["&" + rest]
283
- rules[first] << child
288
+ current_rule << child
284
289
  else
285
- rules[first].children += child.children
290
+ current_rule.children += child.children
286
291
  end
287
292
  end
288
293
 
289
- rules.values.each { |v| parent_ref_rules(v) }
290
- root.children += rules.values
294
+ root.children.each { |v| parent_ref_rules(v) }
291
295
  end
292
296
 
293
297
  # Remove useless parent refs so that
@@ -5,7 +5,7 @@ module Sass::Tree
5
5
  # The character used to include the parent selector
6
6
  PARENT = '&'
7
7
 
8
- attr_accessor :rules
8
+ attr_accessor :rules, :parsed_rules
9
9
 
10
10
  def initialize(rule, options)
11
11
  @rules = [rule]
@@ -25,7 +25,7 @@ module Sass::Tree
25
25
  end
26
26
 
27
27
  def to_s(tabs, super_rules = nil)
28
- resolve_parent_refs!(super_rules)
28
+ resolved_rules = resolve_parent_refs(super_rules)
29
29
 
30
30
  attributes = []
31
31
  sub_rules = []
@@ -35,7 +35,7 @@ module Sass::Tree
35
35
  rule_indent = ' ' * (tabs - 1)
36
36
  per_rule_indent, total_indent = [:nested, :expanded].include?(@style) ? [rule_indent, ''] : ['', rule_indent]
37
37
 
38
- total_rule = total_indent + @rules.map do |line|
38
+ total_rule = total_indent + resolved_rules.map do |line|
39
39
  per_rule_indent + line.join(rule_separator)
40
40
  end.join(line_separator)
41
41
 
@@ -86,7 +86,7 @@ module Sass::Tree
86
86
 
87
87
  tabs += 1 unless attributes.empty? || @style != :nested
88
88
  sub_rules.each do |sub|
89
- to_return << sub.to_s(tabs, @rules)
89
+ to_return << sub.to_s(tabs, resolved_rules)
90
90
  end
91
91
 
92
92
  to_return
@@ -94,28 +94,27 @@ module Sass::Tree
94
94
 
95
95
  protected
96
96
 
97
- def resolve_parent_refs!(super_rules)
97
+ def resolve_parent_refs(super_rules)
98
98
  if super_rules.nil?
99
- @rules.each do |line|
100
- line.map! do |rule|
99
+ return @parsed_rules.map do |line|
100
+ line.map do |rule|
101
101
  if rule.include?(:parent)
102
102
  raise Sass::SyntaxError.new("Base-level rules cannot contain the parent-selector-referencing character '#{PARENT}'.", self.line)
103
103
  end
104
104
 
105
105
  rule.join
106
- end.compact!
106
+ end.compact
107
107
  end
108
- return
109
108
  end
110
109
 
111
110
  new_rules = []
112
111
  super_rules.each do |super_line|
113
- @rules.each do |line|
112
+ @parsed_rules.each do |line|
114
113
  new_rules << []
115
114
 
116
115
  super_line.each do |super_rule|
117
116
  line.each do |rule|
118
- rule.unshift(:parent, " ") unless rule.include?(:parent)
117
+ rule = [:parent, " ", *rule] unless rule.include?(:parent)
119
118
 
120
119
  new_rules.last << rule.map do |segment|
121
120
  next segment unless segment == :parent
@@ -125,11 +124,11 @@ module Sass::Tree
125
124
  end
126
125
  end
127
126
  end
128
- @rules = new_rules
127
+ new_rules
129
128
  end
130
129
 
131
130
  def perform!(environment)
132
- @rules = @rules.map {|r| parse_selector(interpolate(r, environment))}
131
+ @parsed_rules = @rules.map {|r| parse_selector(interpolate(r, environment))}
133
132
  super
134
133
  end
135
134
 
@@ -51,6 +51,28 @@ li a:hover {
51
51
  CSS
52
52
  end
53
53
 
54
+ def test_no_nesting_around_rules
55
+ assert_equal(<<SASS, css2sass(<<CSS))
56
+ div .warning
57
+ :color #d21a19
58
+
59
+
60
+ span .debug
61
+ :cursor crosshair
62
+
63
+
64
+ div .debug
65
+ :cursor default
66
+ SASS
67
+ div .warning {
68
+ color: #d21a19; }
69
+ span .debug {
70
+ cursor: crosshair;}
71
+ div .debug {
72
+ cursor: default; }
73
+ CSS
74
+ end
75
+
54
76
  def test_comments_multiline
55
77
  css = <<CSS
56
78
  /* comment */
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml-edge
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum