Skip to content

Commit

Permalink
Delegations
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed May 17, 2024
1 parent 7c1b425 commit 7dbfb9a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/propshaft/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions lib/propshaft/compiler/css_asset_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion lib/propshaft/compiler/source_mapping_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 7dbfb9a

Please sign in to comment.