Class: Propshaft::Compiler::CssAssetUrls

Inherits:
Propshaft::Compiler show all
Defined in:
lib/propshaft/compiler/css_asset_urls.rb

Constant Summary collapse

ASSET_URL_PATTERN =
/url\(\s*["']?(?!(?:\#|%23|data|http|\/\/))([^"'\s?#)]+)([#?][^"')]+)?\s*["']?\)/

Instance Attribute Summary

Attributes inherited from Propshaft::Compiler

#assembly

Instance Method Summary collapse

Methods inherited from Propshaft::Compiler

#initialize

Constructor Details

This class inherits a constructor from Propshaft::Compiler

Instance Method Details

#compile(asset, input) ⇒ Object



8
9
10
# File 'lib/propshaft/compiler/css_asset_urls.rb', line 8

def compile(asset, input)
  input.gsub(ASSET_URL_PATTERN) { asset_url resolve_path(asset.logical_path.dirname, $1), asset.logical_path, $2, $1 }
end

#referenced_by(asset, references: Set.new) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/propshaft/compiler/css_asset_urls.rb', line 12

def referenced_by(asset, references: Set.new)
  asset.content.scan(ASSET_URL_PATTERN).each do |referenced_asset_url, _|
    referenced_asset = load_path.find(resolve_path(asset.logical_path.dirname, referenced_asset_url))

    if referenced_asset && references.exclude?(referenced_asset)
      references << referenced_asset
      references.merge referenced_by(referenced_asset, references: references)
    end
  end

  references
end