Skip to content

Commit

Permalink
Remove cache_buster from args to #font_url.
Browse files Browse the repository at this point in the history
  • Loading branch information
petebrowne committed Jun 24, 2012
1 parent 26df8c7 commit 9e995d2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 34 deletions.
38 changes: 18 additions & 20 deletions lib/sprockets/sass/functions.rb
Expand Up @@ -3,6 +3,17 @@
module Sprockets
module Sass
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+.
Expand Down Expand Up @@ -80,24 +91,24 @@ def image_url(source, options = {}, cache_buster = nil)
#
# === Examples
#
# background: url(font-path("font.ttf")); // background: url("/assets/font.ttf");
# background: url(font-path("font.ttf", $digest: true)); // background: url("/assets/font-27a8f1f96afd8d4c67a59eb9447f45bd.ttf");
# 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");
#
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#image_path, return the url CSS
# 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
#
# background: font-url("font.ttf"); // background: url("/assets/font.ttf");
# background: font-url("image.jpg", $digest: true); // background: url("/assets/font-27a8f1f96afd8d4c67a59eb9447f45bd.ttf");
# src: font-url("font.ttf"); // src: url("/assets/font.ttf");
# src: font-url("image.jpg", $digest: true); // src: url("/assets/font-27a8f1f96afd8d4c67a59eb9447f45bd.ttf");
#
def font_url(source, options = {}, cache_buster = nil)
# Work with the Compass #image_url API
def font_url(source, options = {})
# Work with the Compass #font_url API
if options.respond_to? :value
case options.value
when true
Expand All @@ -108,18 +119,6 @@ def font_url(source, options = {}, cache_buster = nil)
end
::Sass::Script::String.new "url(#{font_path(source, options)})"
end


# 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

protected

Expand Down Expand Up @@ -160,6 +159,5 @@ module Sass::Script::Functions
declare :font_path, [:source], :var_kwargs => true
declare :font_url, [:source], :var_kwargs => true
declare :font_url, [:source, :only_path]
declare :font_url, [:source, :only_path, :cache_buster]
declare :asset_data_uri, [:source]
end
19 changes: 6 additions & 13 deletions spec/sprockets-sass_spec.rb
Expand Up @@ -284,12 +284,10 @@
it "mirrors Compass's #font_url helper" do
@assets.file 'font_path.css.scss', %(@font-face { src: url(font-url("font.ttf", true)); })
@assets.file 'font_url.css.scss', %(@font-face { src: font-url("font.ttf", false); })
@assets.file 'font_cache_buster.css.scss', %(@font-face { src: font-url("font.ttf", false, true); })
@assets.file 'font.ttf'

@env['font_path.css'].to_s.should == %(@font-face {\n src: url("/assets/font.ttf"); }\n)
@env['font_url.css'].to_s.should == %(@font-face {\n src: url("/assets/font.ttf"); }\n)
@env['font_cache_buster.css'].to_s.should == %(@font-face {\n src: url("/assets/font.ttf"); }\n)
end

it "mirrors Sass::Rails's #asset_path helpers" do
Expand All @@ -301,28 +299,23 @@
@env['asset_url.css'].to_s.should == %(body {\n background: url("/images/icon.jpg"); }\n)
end

it "compresses css" do
css = <<-CSS
div {
color: red;
}
CSS

it 'compresses css' do
css = "div {\n color: red;\n}\n"
Sprockets::Sass::Compressor.new.compress(css).should == "div{color:red}\n"
end

describe Sprockets::Sass::SassTemplate do
describe "initialize_engine" do
let(:template) { Sprockets::Sass::SassTemplate.new{} }

it "initializes super if super is uninitinalized" do
describe 'initialize_engine' do
it 'initializes super if super is uninitinalized' do
Tilt::SassTemplate.stub(:engine_initialized?).and_return false
template = Sprockets::Sass::SassTemplate.new {}
template.should_receive(:require_template_library) # called from Tilt::SassTemplate.initialize
template.initialize_engine
end

it "does not initializes super if super is initinalized to silence warnings" do
Tilt::SassTemplate.stub(:engine_initialized?).and_return true
template = Sprockets::Sass::SassTemplate.new {}
template.should_not_receive(:require_template_library) # called from Tilt::SassTemplate.initialize
template.initialize_engine
end
Expand Down
2 changes: 1 addition & 1 deletion sprockets-sass.gemspec
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'appraisal', '~> 0.4'
s.add_development_dependency 'rspec', '~> 2.6'
s.add_development_dependency 'test-construct', '~> 1.2'
s.add_development_dependency 'sprockets-helpers', '~> 0.3'
s.add_development_dependency 'sprockets-helpers', '~> 0.6'
s.add_development_dependency 'sass', '~> 3.1'
s.add_development_dependency 'compass', '~> 0.11'
s.add_development_dependency 'rake'
Expand Down

0 comments on commit 9e995d2

Please sign in to comment.