2008-11-29 09:08:07 +00:00
|
|
|
require 'sass'
|
|
|
|
|
|
|
|
module Sass::Script::Functions
|
|
|
|
COMMA_SEPARATOR = /\s*,\s*/
|
2009-04-05 10:13:42 +00:00
|
|
|
|
2008-11-29 09:08:07 +00:00
|
|
|
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
|
2009-04-05 10:13:42 +00:00
|
|
|
|
|
|
|
def image_url(path)
|
|
|
|
http_images_path = if Compass.configuration.http_images_path == :relative
|
|
|
|
if (target_css_file = options[:css_filename])
|
|
|
|
images_path = File.join(Compass.configuration.project_path, Compass.configuration.images_dir)
|
|
|
|
Pathname.new(images_path).relative_path_from(Pathname.new(File.dirname(target_css_file))).to_s
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Compass.configuration.http_images_path
|
|
|
|
end
|
|
|
|
path = "#{http_images_path}/#{path}" if http_images_path
|
|
|
|
Sass::Script::String.new("url(#{path})")
|
|
|
|
end
|
2008-11-29 09:08:07 +00:00
|
|
|
end
|