Class: Torba::CssUrlToErbAssetPath
- Inherits:
-
Object
- Object
- Torba::CssUrlToErbAssetPath
- Defined in:
- lib/torba/css_url_to_erb_asset_path.rb
Overview
Parses content of CSS file and converts its image assets paths into Sprockets’ logical paths.
Constant Summary collapse
- URL_RE =
/ url\( # url( \s* # optional space (?!data) # no data URIs ['"]? # optional quote (?!\/) # only relative location ([^'"]+?) # location ['"]? # optional quote \s* # optional space \) # ) /xm
Class Method Summary collapse
-
.call(content, file_path) {|image_file_path| ... } ⇒ String
CSS file content where image “url(…)” paths are replaced by ERB interpolations “url(<%= asset_path(…) %>)”.
Class Method Details
.call(content, file_path) {|image_file_path| ... } ⇒ String
Returns CSS file content where image “url(…)” paths are replaced by ERB interpolations “url(<%= asset_path(…) %>)”.
43 44 45 46 47 48 49 |
# File 'lib/torba/css_url_to_erb_asset_path.rb', line 43 def self.call(content, file_path) content.gsub(URL_RE) do absolute_image_file_path = File.($1, File.dirname(file_path)) sprockets_file_path = yield absolute_image_file_path "url('<%= asset_path('#{sprockets_file_path}') %>')" end end |