compass/lib/sass_extensions.rb
Chris Eppstein 39265bafc3 Added a Sass Function called nest that performs a nesting operation on (possibly) comma delimited selectors and emits the result as a string.
For example:

nest(".foo", "a, em, b")

would render:

.foo a, .foo em, .foo b

The nest function can take any number of arguments and each argument can have any number of comma-delimited selectors.
2008-11-29 01:08:07 -08:00

13 lines
388 B
Ruby

require 'sass'
module Sass::Script::Functions
COMMA_SEPARATOR = /\s*,\s*/
def nest(*arguments)
nested = arguments.map{|a| a.value}.inject do |memo,arg|
ancestors = memo.split(COMMA_SEPARATOR)
descendants = arg.split(COMMA_SEPARATOR)
ancestors.map{|a| descendants.map{|d| "#{a} #{d}"}.join(", ")}.join(", ")
end
Sass::Script::String.new(nested)
end
end