Module: Sprockets::Sass::Functions

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

Instance Method Summary collapse

Instance Method Details

#asset_data_uri(source) ⇒ Object

Using Sprockets::Context#asset_data_uri return a Base64-encoded ‘data:` URI with the contents of the asset at the specified path.

Examples

background: asset-data-uri("image.jpg"); // background: url(data:image/jpeg;base64,...);


84
85
86
# File 'lib/sprockets/sass/functions.rb', line 84

def asset_data_uri(source)
  ::Sass::Script::String.new "url(#{sprockets_context.asset_data_uri(source.value)})"
end

#asset_path(source, options = {}) ⇒ Object

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");


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

def asset_path(source, options = {})
  # Work with the Sass::Rails #asset_path API
  if options.respond_to? :value
    kind = options.value
    options = {}
  end
  
  if kind && sprockets_context.respond_to?("#{kind}_path")
    ::Sass::Script::String.new sprockets_context.send("#{kind}_path", source.value), :string
  else
    ::Sass::Script::String.new sprockets_context.asset_path(source.value, map_options(options)).to_s, :string
  end
end

#asset_url(source, options = {}) ⇒ Object

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");


38
39
40
# File 'lib/sprockets/sass/functions.rb', line 38

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

#image_path(source, options = {}) ⇒ Object

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");


51
52
53
# File 'lib/sprockets/sass/functions.rb', line 51

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

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

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");


64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/sprockets/sass/functions.rb', line 64

def image_url(source, options = {}, cache_buster = nil)
  # Work with the Compass #image_url API
  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