Module: Compass::SassExtensions::Functions::Urls

Included in:
Sass::Script::Functions
Defined in:
lib/compass/app_integration/rails/urls.rb,
lib/compass/sass_extensions/functions/urls.rb

Instance Method Summary collapse

Instance Method Details

#font_url(path) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/compass/sass_extensions/functions/urls.rb', line 17

def font_url(path)
  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_dir)
                    else
                      Compass.configuration.http_fonts_path
                    end

  url("#{http_fonts_path}/#{path}")
end

#image_url(path) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
# File 'lib/compass/sass_extensions/functions/urls.rb', line 36

def image_url(path)
  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 image, either root relative or stylesheet relative
  # or nil if the http_images_path is not set in the configuration.
  http_images_path = if relative?
    compute_relative_path(Compass.configuration.images_dir)
  elsif Compass.configuration.http_images_path
    Compass.configuration.http_images_path
  else
    Compass.configuration.http_root_relative(Compass.configuration.images_dir)
  end

  # Compute the real path to the image on the file stystem if the images_dir is set.
  real_path = if Compass.configuration.images_dir
    File.join(Compass.configuration.project_path, Compass.configuration.images_dir, path)
  end

  # prepend the path to the image if there's one
  if http_images_path
    http_images_path = "#{http_images_path}/" unless http_images_path[-1..-1] == "/"
    path = "#{http_images_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 buster = compute_cache_buster(path, real_path)
    path += "?#{buster}"
  end

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

  url(path)
end

#image_url_with_rails_integration(path) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/compass/app_integration/rails/urls.rb', line 2

def image_url_with_rails_integration(path)
  if (@controller = Sass::Plugin.rails_controller) && @controller.respond_to?(:request) && @controller.request
    begin
      Sass::Script::String.new "url(#{image_path(path.value)})"
    ensure
      @controller = nil
    end
  else
    image_url_without_rails_integration(path)
  end
end

#stylesheet_url(path) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/compass/sass_extensions/functions/urls.rb', line 3

def stylesheet_url(path)
  # Compute the path to the stylesheet, either root relative or stylesheet relative
  # or nil if the http_images_path is not set in the configuration.
  http_stylesheets_path = if relative?
    compute_relative_path(Compass.configuration.css_dir)
  elsif Compass.configuration.http_stylesheets_path
    Compass.configuration.http_stylesheets_path
  else
    Compass.configuration.http_root_relative(Compass.configuration.css_dir)
  end

  url("#{http_stylesheets_path}/#{path}")
end

#url(url) ⇒ Object

Emits a url, taking off any leading “./”



82
83
84
85
86
# File 'lib/compass/sass_extensions/functions/urls.rb', line 82

def url(url)
  url = url.to_s
  url = url[0..1] == "./" ? url[2..-1] : url
  Sass::Script::String.new("url('#{url}')")
end