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,...);


13
14
15
# File 'lib/sprockets/sass/functions.rb', line 13

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


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sprockets/sass/functions.rb', line 26

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


49
50
51
# File 'lib/sprockets/sass/functions.rb', line 49

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

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

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

Examples

src: url(font-path("font.ttf"));                // src: url("/assets/font.ttf");
src: url(font-path("font.ttf", $digest: true)); // src: url("/assets/font-27a8f1f96afd8d4c67a59eb9447f45bd.ttf");


97
98
99
# File 'lib/sprockets/sass/functions.rb', line 97

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

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

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

Examples

src: font-url("font.ttf");                  // src: url("/assets/font.ttf");
src: font-url("image.jpg", $digest: true);  // src: url("/assets/font-27a8f1f96afd8d4c67a59eb9447f45bd.ttf");


110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/sprockets/sass/functions.rb', line 110

def font_url(source, options = {})
  # Work with the Compass #font_url API
  if options.respond_to? :value
    case options.value
    when true
      return font_path source
    else
      options = {}
    end
  end
  ::Sass::Script::String.new "url(#{font_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");


62
63
64
# File 'lib/sprockets/sass/functions.rb', line 62

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: image-url("image.jpg");                // background: url("/assets/image.jpg");
background: image-url("image.jpg", $digest: true); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");


75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/sprockets/sass/functions.rb', line 75

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