Module: Sprockets::Sass::Functions

Included in:
Sass::Script::Functions
Defined in:
lib/sprockets/sass/functions.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) asset_path(source, options = {})

Using Sprockets::Helpers#asset_path, return the full path for the given source as a Sass String. This supports keyword arguments that mirror the options.

Examples

background: url(asset-path("image.jpg"));                // background: url("/assets/image.jpg");
background: url(asset-path("image.jpg", $digest: true)); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sprockets/sass/functions.rb', line 16

def asset_path(source, options = {})
  # Check for the Sass::Rails' #asset_path API,
  # and work with it. We want to make Rails assets work
  # just fine with Machined.
  if options.respond_to? :value
    kind = options.value
    options = {}
  end
  
  if kind && context.respond_to?("#{kind}_path")
    ::Sass::Script::String.new context.send("#{kind}_path", source.value), :string
  else
    ::Sass::Script::String.new context.asset_path(source.value, map_options(options)), :string
  end
end

- (Object) asset_url(source, options = {})

Using Sprockets::Helpers#asset_path, return the url CSS for the given source as a Sass String. This supports keyword arguments that mirror the options.

Examples

background: asset-url("image.jpg");                // background: url("/assets/image.jpg");
background: asset-url("image.jpg", $digest: true); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");


41
42
43
# File 'lib/sprockets/sass/functions.rb', line 41

def asset_url(source, options = {})
  ::Sass::Script::String.new "url(#{asset_path(source, options)})"
end

- (Object) image_path(source, options = {})

Using Sprockets::Helpers#image_path, return the full path for the given source as a Sass String. This supports keyword arguments that mirror the options.

Examples

background: url(image-path("image.jpg"));                // background: url("/assets/image.jpg");
background: url(image-path("image.jpg", $digest: true)); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");


54
55
56
# File 'lib/sprockets/sass/functions.rb', line 54

def image_path(source, options = {})
  ::Sass::Script::String.new context.image_path(source.value, map_options(options)), :string
end

- (Object) image_url(source, options = {}, cache_buster = nil)

Using Sprockets::Helpers#image_path, return the url CSS for the given source as a Sass String. This supports keyword arguments that mirror the options.

Examples

background: asset-url("image.jpg");                // background: url("/assets/image.jpg");
background: asset-url("image.jpg", $digest: true); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");


67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/sprockets/sass/functions.rb', line 67

def image_url(source, options = {}, cache_buster = nil)
  # Check for the Compass #image_url API,
  # and work with it. We don't want to break
  # the Compass mixins that expect it.
  if options.respond_to? :value
    case options.value
    when true
      return image_path source
    else
      options = {}
    end
  end
  ::Sass::Script::String.new "url(#{image_path(source, options)})"
end