From 7dbfb9a33ffab54d55dacab4f4a8ad8ebfb934f7 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 17 May 2024 15:45:07 -0700 Subject: [PATCH] Delegations --- lib/propshaft/compiler.rb | 3 ++- lib/propshaft/compiler/css_asset_urls.rb | 4 ++-- lib/propshaft/compiler/source_mapping_urls.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/propshaft/compiler.rb b/lib/propshaft/compiler.rb index 7a62934..74bccc4 100644 --- a/lib/propshaft/compiler.rb +++ b/lib/propshaft/compiler.rb @@ -3,6 +3,7 @@ # Base compiler from which other compilers can inherit class Propshaft::Compiler attr_reader :assembly + delegate :config, :load_path, to: :assembly def initialize(assembly) @assembly = assembly @@ -19,6 +20,6 @@ def referenced_by(asset) private def url_prefix - @url_prefix ||= File.join(assembly.config.relative_url_root.to_s, assembly.config.prefix.to_s).chomp("/") + @url_prefix ||= File.join(config.relative_url_root.to_s, config.prefix.to_s).chomp("/") end end diff --git a/lib/propshaft/compiler/css_asset_urls.rb b/lib/propshaft/compiler/css_asset_urls.rb index 775ea9e..265fc23 100644 --- a/lib/propshaft/compiler/css_asset_urls.rb +++ b/lib/propshaft/compiler/css_asset_urls.rb @@ -12,7 +12,7 @@ def compile(asset) def referenced_by(asset) Set.new.tap do |references| asset.content.scan(ASSET_URL_PATTERN).each do |referenced_asset_url, _| - referenced_asset = assembly.load_path.find(resolve_path(asset.logical_path.dirname, referenced_asset_url)) + referenced_asset = load_path.find(resolve_path(asset.logical_path.dirname, referenced_asset_url)) if references.exclude?(referenced_asset) references << referenced_asset @@ -34,7 +34,7 @@ def resolve_path(directory, filename) end def asset_url(resolved_path, logical_path, fingerprint, pattern) - if asset = assembly.load_path.find(resolved_path) + if asset = load_path.find(resolved_path) %[url("#{url_prefix}/#{asset.digested_path}#{fingerprint}")] else Propshaft.logger.warn "Unable to resolve '#{pattern}' for missing asset '#{resolved_path}' in #{logical_path}" diff --git a/lib/propshaft/compiler/source_mapping_urls.rb b/lib/propshaft/compiler/source_mapping_urls.rb index e09e685..56e8150 100644 --- a/lib/propshaft/compiler/source_mapping_urls.rb +++ b/lib/propshaft/compiler/source_mapping_urls.rb @@ -21,7 +21,7 @@ def asset_path(source_mapping_url, logical_path) end def source_mapping_url(logical_path, resolved_path, comment_start, comment_end) - if asset = assembly.load_path.find(resolved_path) + 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}"