Module: Compass::Core::SassExtensions::Functions::Urls::FontUrl

Defined in:
lib/compass/core/sass_extensions/functions/urls.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/compass/core/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]
    base.declare :font_url,       [:path, :only_path, :cache_buster]
  end
end

Instance Method Details

#font_url(path, only_path = bool(false), cache_buster = bool(true)) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/compass/core/sass_extensions/functions/urls.rb', line 50

def font_url(path, only_path = bool(false), cache_buster = bool(true))
  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 unquoted_string("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

  # Compute the real path to the font on the file system if the fonts_dir is set.
  real_path = if Compass.configuration.fonts_dir
    File.join(Compass.configuration.fonts_path, path.gsub(/[?#].*$/,""))
  end

  # prepend the path to the font if there's one
  if http_fonts_path
    http_fonts_path = "#{http_fonts_path}/" unless http_fonts_path[-1..-1] == "/"
    path = "#{http_fonts_path}#{path}"
  end

  # Compute the asset host unless in relative mode.
  asset_host = if !relative? && Compass.configuration.asset_host
    Compass.configuration.asset_host.call(path)
  end

  # Compute and append the cache buster if there is one.
  if cache_buster.to_bool
    path, anchor = path.split("#", 2)
    if cache_buster.is_a?(Sass::Script::Value::String)
      path += "#{path["?"] ? "&" : "?"}#{cache_buster.value}"
    else
      path = cache_busted_path(path, real_path)
    end
    path = "#{path}#{"#" if anchor}#{anchor}"
  end

  # prepend the asset host if there is one.
  path = "#{asset_host}#{'/' unless path[0..0] == "/"}#{path}" if asset_host

  if only_path.to_bool
    unquoted_string(clean_path(path))
  else
    clean_url(path)
  end
end