[Compass Core] Fix a bug in the enumerate() function that was introduced during upgrade to sass 3. Added a test case that would have caught the regression.

This commit is contained in:
Chris Eppstein 2010-04-13 01:06:56 -07:00
parent 767882f10a
commit 0b994f3832
2 changed files with 24 additions and 3 deletions

View File

@ -1,6 +1,7 @@
module Compass::SassExtensions::Functions::Enumerate
def enumerate(prefix, from, through, separator = "-")
selectors = (from.value..through.value).map{|i| "#{prefix.value}#{separator}#{i}"}.join(", ")
def enumerate(prefix, from, through, separator = nil)
separator ||= Sass::Script::String.new("-", :string)
selectors = (from.value..through.value).map{|i| "#{prefix.value}#{separator.value}#{i}"}.join(", ")
Sass::Script::String.new(selectors)
end
end

View File

@ -20,12 +20,32 @@ class SassExtensionsTest < Test::Unit::TestCase
assert_equal "a b e, a b f, a c e, a c f, a d e, a d f", nest("a", "b, c, d", "e, f")
end
def test_enumerate
assert_equal ".grid-1, .grid-2, .grid-3", enumerate(".grid", 1, 3, "-")
end
def test_append_selector
assert_equal "div.bar", append_selector("div", ".bar")
assert_equal ".foo1.bar1, .foo1.bar2, .foo2.bar1, .foo2.bar2", append_selector(".foo1, .foo2", ".bar1, .bar2")
end
protected
def evaluation_content(options)
Sass::Script::Functions::EvaluationContext.new(options)
end
def nest(*arguments)
options = arguments.last.is_a?(Hash) ? arguments.pop : Hash.new
evaluation_content(options).nest(*arguments.map{|a| Sass::Script::String.new(a)}).to_s
evaluation_content(options).nest(*arguments.map{|a| Sass::Script::String.new(a, :string)}).to_s
end
def enumerate(prefix, from, through, separator = "-", options = {})
prefix = Sass::Script::String.new(prefix, :string)
from = Sass::Script::Number.new(from)
through = Sass::Script::Number.new(through)
separator = Sass::Script::String.new(separator, :string)
evaluation_content(options).enumerate(prefix, from, through, separator).to_s
end
def append_selector(*arguments)
options = arguments.last.is_a?(Hash) ? arguments.pop : Hash.new
evaluation_content(options).append_selector(*arguments.map{|a| Sass::Script::String.new(a, :string)}).to_s
end
end