diff --git a/lib/compass/sass_extensions/functions/enumerate.rb b/lib/compass/sass_extensions/functions/enumerate.rb index 48f89f73..016aba90 100644 --- a/lib/compass/sass_extensions/functions/enumerate.rb +++ b/lib/compass/sass_extensions/functions/enumerate.rb @@ -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 \ No newline at end of file diff --git a/test/sass_extensions_test.rb b/test/sass_extensions_test.rb index 797e235c..20773cb4 100644 --- a/test/sass_extensions_test.rb +++ b/test/sass_extensions_test.rb @@ -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