class Propshaft::Compilers::CssAssetUrls

Constants

ASSET_URL_PATTERN

Attributes

assembly[R]

Public Class Methods

new(assembly) click to toggle source
# File lib/propshaft/compilers/css_asset_urls.rb, line 8
def initialize(assembly)
  @assembly = assembly
end

Public Instance Methods

compile(logical_path, input) click to toggle source
# File lib/propshaft/compilers/css_asset_urls.rb, line 12
def compile(logical_path, input)
  input.gsub(ASSET_URL_PATTERN) { asset_url resolve_path(logical_path.dirname, $1), logical_path, $1 }
end

Private Instance Methods

asset_url(resolved_path, logical_path, pattern) click to toggle source
# File lib/propshaft/compilers/css_asset_urls.rb, line 27
def asset_url(resolved_path, logical_path, pattern)
  if asset = assembly.load_path.find(resolved_path)
    %[url("#{assembly.config.prefix}/#{asset.digested_path}")]
  else
    Propshaft.logger.warn "Unable to resolve '#{pattern}' for missing asset '#{resolved_path}' in #{logical_path}"
    %[url("#{pattern}")]
  end
end
resolve_path(directory, filename) click to toggle source
# File lib/propshaft/compilers/css_asset_urls.rb, line 17
def resolve_path(directory, filename)
  if filename.start_with?("../")
    Pathname.new(directory + filename).relative_path_from("").to_s
  elsif filename.start_with?("/")
    filename.delete_prefix("/").to_s
  else
    (directory + filename.delete_prefix("./")).to_s
  end
end