Sha256: 88be040e42ee32b5dff27b984b30799c3f10d3bcc72d760ab20c1378983029a4

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

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

  def enumerate(prefix, from, through)
    selectors = (from.value..through.value).map{|i| "#{prefix.value}-#{i}"}.join(", ")
    Sass::Script::String.new(selectors)
  end

  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
    if http_images_path
      http_images_path = "#{http_images_path}/" unless http_images_path[-1..-1] == "/"
      path = "#{http_images_path}#{path}"
    end
    Sass::Script::String.new("url(#{path})")
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chriseppstein-compass-0.6.0 lib/sass_extensions.rb
chriseppstein-compass-0.6.1 lib/sass_extensions.rb
chriseppstein-compass-0.6.2 lib/sass_extensions.rb