module Compass::SassExtensions::Functions::Urls::FontUrl

Public Class Methods

included(base) click to toggle source
# File lib/compass/sass_extensions/functions/urls.rb, line 43
def self.included(base)
  if base.respond_to?(:declare)
    base.declare :font_url,       [:path]
    base.declare :font_url,       [:path, :only_path]
  end
end

Public Instance Methods

font_url(path, only_path = Sass::Script::Bool.new(false)) click to toggle source
# File lib/compass/sass_extensions/functions/urls.rb, line 49
def font_url(path, only_path = Sass::Script::Bool.new(false))
  path = path.value # get to the string value of the literal.

  # Short curcuit if they have provided an absolute url.
  if absolute_path?(path)
    return Sass::Script::String.new("url(#{path})")
  end

  # Compute the path to the font file, either root relative or stylesheet relative
  # or nil if the http_fonts_path cannot be determined from the configuration.
  http_fonts_path = if relative?
                      compute_relative_path(Compass.configuration.fonts_path)
                    else
                      Compass.configuration.http_fonts_path
                    end

  path = "#{http_fonts_path}/#{path}"

  if only_path.to_bool
    Sass::Script::String.new(clean_path(path))
  else
    clean_url(path)
  end
end