only define the compass url helpers if they are not already defined.
This commit is contained in:
parent
f23bf58e8d
commit
210a1d4771
@ -1,8 +1,27 @@
|
|||||||
module Compass::SassExtensions::Functions::Urls
|
module Compass::SassExtensions::Functions::Urls
|
||||||
|
|
||||||
|
|
||||||
|
def self.has?(base, instance_method)
|
||||||
|
Sass::Util.has?(:instance_method, base, instance_method)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.included(base)
|
||||||
|
base.send(:include, StylesheetUrl) unless has?(base, :stylesheet_url)
|
||||||
|
base.send(:include, FontUrl) unless has?(base, :font_url)
|
||||||
|
base.send(:include, ImageUrl) unless has?(base, :image_url)
|
||||||
|
base.send(:include, GeneratedImageUrl) unless has?(base, :generated_image_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
module StylesheetUrl
|
||||||
|
def self.included(base)
|
||||||
|
if base.respond_to?(:declare)
|
||||||
|
base.declare :stylesheet_url, [:path]
|
||||||
|
base.declare :stylesheet_url, [:path, :only_path]
|
||||||
|
end
|
||||||
|
end
|
||||||
def stylesheet_url(path, only_path = Sass::Script::Bool.new(false))
|
def stylesheet_url(path, only_path = Sass::Script::Bool.new(false))
|
||||||
# Compute the path to the stylesheet, either root relative or stylesheet relative
|
# Compute the path to the stylesheet, either root relative or stylesheet relative
|
||||||
# or nil if the http_stylesheets_path is not set in the configuration.
|
# or nil if the http_images_path is not set in the configuration.
|
||||||
http_stylesheets_path = if relative?
|
http_stylesheets_path = if relative?
|
||||||
compute_relative_path(Compass.configuration.css_path)
|
compute_relative_path(Compass.configuration.css_path)
|
||||||
elsif Compass.configuration.http_stylesheets_path
|
elsif Compass.configuration.http_stylesheets_path
|
||||||
@ -18,9 +37,15 @@ module Compass::SassExtensions::Functions::Urls
|
|||||||
clean_url(path)
|
clean_url(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Sass::Script::Functions.declare :stylesheet_url, [:path]
|
end
|
||||||
Sass::Script::Functions.declare :stylesheet_url, [:path, :only_path]
|
|
||||||
|
|
||||||
|
module FontUrl
|
||||||
|
def self.included(base)
|
||||||
|
if base.respond_to?(:declare)
|
||||||
|
base.declare :font_url, [:path]
|
||||||
|
base.declare :font_url, [:path, :only_path]
|
||||||
|
end
|
||||||
|
end
|
||||||
def font_url(path, only_path = Sass::Script::Bool.new(false))
|
def font_url(path, only_path = Sass::Script::Bool.new(false))
|
||||||
path = path.value # get to the string value of the literal.
|
path = path.value # get to the string value of the literal.
|
||||||
|
|
||||||
@ -45,9 +70,16 @@ module Compass::SassExtensions::Functions::Urls
|
|||||||
clean_url(path)
|
clean_url(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Sass::Script::Functions.declare :font_url, [:path]
|
end
|
||||||
Sass::Script::Functions.declare :font_url, [:path, :only_path]
|
|
||||||
|
|
||||||
|
module ImageUrl
|
||||||
|
def self.included(base)
|
||||||
|
if base.respond_to?(:declare)
|
||||||
|
base.declare :image_url, [:path]
|
||||||
|
base.declare :image_url, [:path, :only_path]
|
||||||
|
base.declare :image_url, [:path, :only_path, :cache_buster]
|
||||||
|
end
|
||||||
|
end
|
||||||
def image_url(path, only_path = Sass::Script::Bool.new(false), cache_buster = Sass::Script::Bool.new(true))
|
def image_url(path, only_path = Sass::Script::Bool.new(false), cache_buster = Sass::Script::Bool.new(true))
|
||||||
path = path.value # get to the string value of the literal.
|
path = path.value # get to the string value of the literal.
|
||||||
|
|
||||||
@ -104,10 +136,15 @@ module Compass::SassExtensions::Functions::Urls
|
|||||||
clean_url(path)
|
clean_url(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Sass::Script::Functions.declare :image_url, [:path]
|
end
|
||||||
Sass::Script::Functions.declare :image_url, [:path, :only_path]
|
|
||||||
Sass::Script::Functions.declare :image_url, [:path, :only_path, :cache_buster]
|
|
||||||
|
|
||||||
|
module GeneratedImageUrl
|
||||||
|
def self.included(base)
|
||||||
|
if base.respond_to?(:declare)
|
||||||
|
base.declare :generated_image_url, [:path]
|
||||||
|
base.declare :generated_image_url, [:path, :cache_buster]
|
||||||
|
end
|
||||||
|
end
|
||||||
def generated_image_url(path, cache_buster = Sass::Script::Bool.new(false))
|
def generated_image_url(path, cache_buster = Sass::Script::Bool.new(false))
|
||||||
path = path.value # get to the string value of the literal.
|
path = path.value # get to the string value of the literal.
|
||||||
|
|
||||||
@ -160,8 +197,7 @@ module Compass::SassExtensions::Functions::Urls
|
|||||||
|
|
||||||
clean_url(path)
|
clean_url(path)
|
||||||
end
|
end
|
||||||
Sass::Script::Functions.declare :generated_image_url, [:path]
|
end
|
||||||
Sass::Script::Functions.declare :generated_image_url, [:path, :cache_buster]
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
@ -98,6 +98,20 @@ class SassExtensionsTest < Test::Unit::TestCase
|
|||||||
assert_equal "true", evaluate("prefixed(-css2, css2-fallback(css3, css2))")
|
assert_equal "true", evaluate("prefixed(-css2, css2-fallback(css3, css2))")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
%w(stylesheet_url font_url image_url generated_image_url).each do |helper|
|
||||||
|
class_eval %Q{
|
||||||
|
def test_#{helper}_helper_defers_to_existing_helper
|
||||||
|
c = Class.new do
|
||||||
|
def #{helper}(*args)
|
||||||
|
:original
|
||||||
|
end
|
||||||
|
end
|
||||||
|
c.send(:include, Compass::SassExtensions::Functions::Urls)
|
||||||
|
assert_equal :original, c.new.#{helper}("logo.png")
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def evaluate(value)
|
def evaluate(value)
|
||||||
Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new).to_s
|
Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new).to_s
|
||||||
|
Loading…
Reference in New Issue
Block a user