Module: AssetsBooster::Mixin::Css
Instance Method Summary
collapse
Methods included from Url
#absolute_url?, #external_url?, #path_difference
Instance Method Details
#adjust_relative_urls(css, source_folder, target_folder) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/assets_booster/mixin/css.rb', line 11
def adjust_relative_urls(css, source_folder, target_folder)
url_prepend = path_difference(source_folder, target_folder)
return css if url_prepend == ""
css.gsub(/url\(([^)]+)\)/i) do |match|
url, quotes = unquote($1.strip)
next match if absolute_url?(url) || external_url?(url)
"url(#{quotes}#{url_prepend}/#{url}#{quotes})"
end
end
|
#hostify_urls(base_url, css) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/assets_booster/mixin/css.rb', line 25
def hostify_urls(base_url, css)
css.gsub(/url\(([^)]+)\)/i) do |match|
url, quotes = unquote($1.strip)
next match if external_url?(url)
url = url[1..-1] if url[0].chr == "/"
"url(#{quotes}#{base_url}/#{url}#{quotes})"
end
end
|
#unquote(quoted) ⇒ Object
7
8
9
|
# File 'lib/assets_booster/mixin/css.rb', line 7
def unquote(quoted)
(quoted[0].chr =~ /["']/) ? [quoted.slice(1, quoted.length-2), quoted[0].chr] : [quoted, ""]
end
|