lib/sprockets/sass/functions.rb in sprockets-sass-0.9.0 vs lib/sprockets/sass/functions.rb in sprockets-sass-0.9.1

- old
+ new

@@ -5,17 +5,17 @@ module Functions # 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,...); # def asset_data_uri(source) ::Sass::Script::String.new "url(#{sprockets_context.asset_data_uri(source.value)})" end - + # 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 @@ -27,18 +27,18 @@ # 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 - + # 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 @@ -47,11 +47,11 @@ # background: asset-url("image.jpg", $digest: true); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg"); # def asset_url(source, options = {}) ::Sass::Script::String.new "url(#{asset_path(source, options)})" end - + # 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 @@ -60,11 +60,11 @@ # background: url(image-path("image.jpg", $digest: true)); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg"); # def image_path(source, options = {}) ::Sass::Script::String.new sprockets_context.image_path(source.value, map_options(options)).to_s, :string end - + # 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 @@ -95,11 +95,11 @@ # src: url(font-path("font.ttf", $digest: true)); // src: url("/assets/font-27a8f1f96afd8d4c67a59eb9447f45bd.ttf"); # def font_path(source, options = {}) ::Sass::Script::String.new sprockets_context.font_path(source.value, map_options(options)).to_s, :string end - + # 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 @@ -117,19 +117,19 @@ options = {} end end ::Sass::Script::String.new "url(#{font_path(source, options)})" end - + protected - + # Returns a reference to the Sprocket's context through # the importer. def sprockets_context # :nodoc: - options[:importer].context + options[:custom][:sprockets_context] end - + # Returns an options hash where the keys are symbolized # and the values are unwrapped Sass literals. def map_options(options = {}) # :nodoc: ::Sass::Util.map_hash(options) do |key, value| [key.to_sym, value.respond_to?(:value) ? value.value : value] @@ -139,16 +139,16 @@ end end module Sass::Script::Functions include Sprockets::Sass::Functions - + # Hack to ensure previous API declarations (by Compass or whatever) # don't take precedence. [:asset_path, :asset_url, :image_path, :image_url, :font_path, :font_url, :asset_data_uri].each do |method| defined?(@signatures) && @signatures.delete(method) end - + declare :asset_path, [:source], :var_kwargs => true declare :asset_path, [:source, :kind] declare :asset_url, [:source], :var_kwargs => true declare :asset_url, [:source, :kind] declare :image_path, [:source], :var_kwargs => true