haml-edge 2.3.215 → 2.3.216
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/EDGE_GEM_VERSION +1 -1
- data/VERSION +1 -1
- data/lib/haml/util/subset_map.rb +1 -1
- data/lib/haml/util.rb +41 -1
- data/lib/sass/selector/sequence.rb +6 -5
- data/lib/sass/selector/simple_sequence.rb +3 -2
- data/test/haml/util_test.rb +44 -0
- metadata +1 -1
data/EDGE_GEM_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3.
|
1
|
+
2.3.216
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3.
|
1
|
+
2.3.216
|
data/lib/haml/util/subset_map.rb
CHANGED
data/lib/haml/util.rb
CHANGED
@@ -189,7 +189,7 @@ module Haml
|
|
189
189
|
# # [2, 4, 5]]
|
190
190
|
def paths(arrs)
|
191
191
|
arrs.inject([[]]) do |paths, arr|
|
192
|
-
arr.map {|e| paths.map {|path| path + [e]}}
|
192
|
+
flatten(arr.map {|e| paths.map {|path| path + [e]}}, 1)
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
@@ -370,6 +370,14 @@ module Haml
|
|
370
370
|
Haml::Util::RUBY_VERSION[0] == 1 && Haml::Util::RUBY_VERSION[1] < 9
|
371
371
|
end
|
372
372
|
|
373
|
+
# Whether or not this is running under Ruby 1.8.6 or lower.
|
374
|
+
# Note that lower versions are not officially supported.
|
375
|
+
#
|
376
|
+
# @return [Boolean]
|
377
|
+
def ruby1_8_6?
|
378
|
+
ruby1_8? && Haml::Util::RUBY_VERSION[2] < 7
|
379
|
+
end
|
380
|
+
|
373
381
|
# Checks that the encoding of a string is valid in Ruby 1.9
|
374
382
|
# and cleans up potential encoding gotchas like the UTF-8 BOM.
|
375
383
|
# If it's not, yields an error string describing the invalid character
|
@@ -458,6 +466,38 @@ MSG
|
|
458
466
|
ruby1_8? ? c[0] : c.ord
|
459
467
|
end
|
460
468
|
|
469
|
+
# Flattens the first `n` nested arrays in a cross-version manner.
|
470
|
+
#
|
471
|
+
# @param arr [Array] The array to flatten
|
472
|
+
# @param n [Fixnum] The number of levels to flatten
|
473
|
+
# @return [Array] The flattened array
|
474
|
+
def flatten(arr, n)
|
475
|
+
return arr.flatten(n) unless ruby1_8_6?
|
476
|
+
return arr if n == 0
|
477
|
+
arr.inject([]) {|res, e| e.is_a?(Array) ? res.concat(flatten(e, n - 1)) : res << e}
|
478
|
+
end
|
479
|
+
|
480
|
+
# Returns the hash code for a set in a cross-version manner.
|
481
|
+
# Aggravatingly, this is order-dependent in Ruby 1.8.6.
|
482
|
+
#
|
483
|
+
# @param set [Set]
|
484
|
+
# @return [Fixnum] The order-independent hashcode of `set`
|
485
|
+
def set_hash(set)
|
486
|
+
return set.hash unless ruby1_8_6?
|
487
|
+
set.map {|e| e.hash}.uniq.sort.hash
|
488
|
+
end
|
489
|
+
|
490
|
+
# Tests the hash-equality of two sets in a cross-version manner.
|
491
|
+
# Aggravatingly, this is order-dependent in Ruby 1.8.6.
|
492
|
+
#
|
493
|
+
# @param set1 [Set]
|
494
|
+
# @param set2 [Set]
|
495
|
+
# @return [Boolean] Whether or not the sets are hashcode equal
|
496
|
+
def set_eql?(set1, set2)
|
497
|
+
return set1.eql?(set2) unless ruby1_8_6?
|
498
|
+
set1.to_a.uniq.sort_by {|e| e.hash}.eql?(set2.to_a.uniq.sort_by {|e| e.hash})
|
499
|
+
end
|
500
|
+
|
461
501
|
## Static Method Stuff
|
462
502
|
|
463
503
|
# The context in which the ERB for \{#def\_static\_method} will be run.
|
@@ -77,10 +77,11 @@ module Sass
|
|
77
77
|
# These correspond to a {CommaSequence}'s {CommaSequence#members members array}.
|
78
78
|
# @see CommaSequence#do_extend
|
79
79
|
def do_extend(extends, supers = [])
|
80
|
-
Haml::Util.paths(members.map do |sseq_or_op|
|
80
|
+
paths = Haml::Util.paths(members.map do |sseq_or_op|
|
81
81
|
next [[sseq_or_op]] unless sseq_or_op.is_a?(SimpleSequence)
|
82
82
|
[[sseq_or_op], *sseq_or_op.do_extend(extends, supers).map {|seq| seq.members}]
|
83
|
-
end)
|
83
|
+
end)
|
84
|
+
Haml::Util.flatten(paths.map {|path| weave(path)}, 1).map {|p| Sequence.new(p)}
|
84
85
|
end
|
85
86
|
|
86
87
|
# @see Simple#to_a
|
@@ -134,9 +135,9 @@ module Sass
|
|
134
135
|
while !current.empty? && last_current.first.is_a?(String) || current.last.is_a?(String)
|
135
136
|
last_current.unshift(current.pop)
|
136
137
|
end
|
137
|
-
befores = befores.map do |before|
|
138
|
-
|
139
|
-
|
138
|
+
befores = Haml::Util.flatten(befores.map do |before|
|
139
|
+
subweave(before, current).map {|seqs| seqs + last_current}
|
140
|
+
end, 1)
|
140
141
|
return befores if afters.empty?
|
141
142
|
end
|
142
143
|
end
|
@@ -119,7 +119,7 @@ module Sass
|
|
119
119
|
#
|
120
120
|
# @return [Fixnum]
|
121
121
|
def hash
|
122
|
-
[base, rest].hash
|
122
|
+
[base, Haml::Util.set_hash(rest)].hash
|
123
123
|
end
|
124
124
|
|
125
125
|
# Checks equality between this and another object.
|
@@ -127,7 +127,8 @@ module Sass
|
|
127
127
|
# @param other [Object] The object to test equality against
|
128
128
|
# @return [Boolean] Whether or not this is equal to `other`
|
129
129
|
def eql?(other)
|
130
|
-
other.class == self.class && other.base.eql?(self.base) &&
|
130
|
+
other.class == self.class && other.base.eql?(self.base) &&
|
131
|
+
Haml::Util.set_eql?(other.rest, self.rest)
|
131
132
|
end
|
132
133
|
|
133
134
|
private
|
data/test/haml/util_test.rb
CHANGED
@@ -144,6 +144,50 @@ class UtilTest < Test::Unit::TestCase
|
|
144
144
|
assert_equal(98, ord("bar"))
|
145
145
|
end
|
146
146
|
|
147
|
+
def test_flatten
|
148
|
+
assert_equal([1, 2, 3], flatten([1, 2, 3], 0))
|
149
|
+
assert_equal([1, 2, 3], flatten([1, 2, 3], 1))
|
150
|
+
assert_equal([1, 2, 3], flatten([1, 2, 3], 2))
|
151
|
+
|
152
|
+
assert_equal([[1, 2], 3], flatten([[1, 2], 3], 0))
|
153
|
+
assert_equal([1, 2, 3], flatten([[1, 2], 3], 1))
|
154
|
+
assert_equal([1, 2, 3], flatten([[1, 2], 3], 2))
|
155
|
+
|
156
|
+
assert_equal([[[1], 2], [3], 4], flatten([[[1], 2], [3], 4], 0))
|
157
|
+
assert_equal([[1], 2, 3, 4], flatten([[[1], 2], [3], 4], 1))
|
158
|
+
assert_equal([1, 2, 3, 4], flatten([[[1], 2], [3], 4], 2))
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_set_hash
|
162
|
+
assert(set_hash(Set[1, 2, 3]) == set_hash(Set[3, 2, 1]))
|
163
|
+
assert(set_hash(Set[1, 2, 3]) == set_hash(Set[1, 2, 3]))
|
164
|
+
|
165
|
+
s1 = Set[]
|
166
|
+
s1 << 1
|
167
|
+
s1 << 2
|
168
|
+
s1 << 3
|
169
|
+
s2 = Set[]
|
170
|
+
s2 << 3
|
171
|
+
s2 << 2
|
172
|
+
s2 << 1
|
173
|
+
assert(set_hash(s1) == set_hash(s2))
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_set_eql
|
177
|
+
assert(set_eql?(Set[1, 2, 3], Set[3, 2, 1]))
|
178
|
+
assert(set_eql?(Set[1, 2, 3], Set[1, 2, 3]))
|
179
|
+
|
180
|
+
s1 = Set[]
|
181
|
+
s1 << 1
|
182
|
+
s1 << 2
|
183
|
+
s1 << 3
|
184
|
+
s2 = Set[]
|
185
|
+
s2 << 3
|
186
|
+
s2 << 2
|
187
|
+
s2 << 1
|
188
|
+
assert(set_eql?(s1, s2))
|
189
|
+
end
|
190
|
+
|
147
191
|
def test_caller_info
|
148
192
|
assert_equal(["/tmp/foo.rb", 12, "fizzle"], caller_info("/tmp/foo.rb:12: in `fizzle'"))
|
149
193
|
assert_equal(["/tmp/foo.rb", 12, nil], caller_info("/tmp/foo.rb:12"))
|