Class: Sprockets::Rails::AssetUrlProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/sprockets/rails/asset_url_processor.rb

Overview

Resolve assets referenced in CSS ‘url()` calls and replace them with the digested paths

Constant Summary collapse

REGEX =
/url\(\s*["']?(?!(?:\#|data|http))(?<relativeToCurrentDir>\.\/)?(?<path>[^"'\s)]+)\s*["']?\)/

Class Method Summary collapse

Class Method Details

.call(input) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/sprockets/rails/asset_url_processor.rb', line 6

def self.call(input)
  context = input[:environment].context_class.new(input)
  data    = input[:data].gsub(REGEX) do |_match|
    path = Regexp.last_match[:path]
    "url(#{context.asset_path(path)})"
  end

  context..merge(data: data)
end