class Propshaft::Compiler::SourceMappingUrls

Constants

SOURCE_MAPPING_PATTERN

Public Instance Methods

compile(asset, input) click to toggle source
# File lib/propshaft/compiler/source_mapping_urls.rb, line 8
def compile(asset, input)
  input.gsub(SOURCE_MAPPING_PATTERN) { source_mapping_url(asset.logical_path, asset_path($2, asset.logical_path), $1, $3) }
end

Private Instance Methods

asset_path(source_mapping_url, logical_path) click to toggle source
# File lib/propshaft/compiler/source_mapping_urls.rb, line 13
def asset_path(source_mapping_url, logical_path)
  source_mapping_url.gsub!(/^(.+\/)?#{url_prefix}\//, "")

  if logical_path.dirname.to_s == "."
    source_mapping_url
  else
    logical_path.dirname.join(source_mapping_url).to_s
  end
end
source_mapping_url(logical_path, resolved_path, comment_start, comment_end) click to toggle source
# File lib/propshaft/compiler/source_mapping_urls.rb, line 23
def source_mapping_url(logical_path, resolved_path, comment_start, comment_end)
  if asset = load_path.find(resolved_path)
    "#{comment_start}# sourceMappingURL=#{url_prefix}/#{asset.digested_path}#{comment_end}"
  else
    Propshaft.logger.warn "Removed sourceMappingURL comment for missing asset '#{resolved_path}' from #{logical_path}"
    "#{comment_start}#{comment_end}"
  end
end