From 9c0d3efca02a488ecc0c6a02c86ad8d3fed59d71 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 17 May 2024 15:58:22 -0700 Subject: [PATCH] Have to keep building the input --- benchmarks/css_asset_urls | 2 +- lib/propshaft/compiler/css_asset_urls.rb | 4 ++-- lib/propshaft/compiler/source_mapping_urls.rb | 4 ++-- lib/propshaft/compilers.rb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/benchmarks/css_asset_urls b/benchmarks/css_asset_urls index 063e326..bea017e 100755 --- a/benchmarks/css_asset_urls +++ b/benchmarks/css_asset_urls @@ -25,5 +25,5 @@ compiler = Propshaft::Compiler::CssAssetUrls.new(assembly) Benchmark.ips do |x| x.config(time: 5, warmup: 2) - x.report("compile") { compiler.compile(asset.logical_path, asset.content) } + x.report("compile") { compiler.compile(asset, asset.content) } end diff --git a/lib/propshaft/compiler/css_asset_urls.rb b/lib/propshaft/compiler/css_asset_urls.rb index 265fc23..d15bd50 100644 --- a/lib/propshaft/compiler/css_asset_urls.rb +++ b/lib/propshaft/compiler/css_asset_urls.rb @@ -5,8 +5,8 @@ class Propshaft::Compiler::CssAssetUrls < Propshaft::Compiler ASSET_URL_PATTERN = /url\(\s*["']?(?!(?:\#|%23|data|http|\/\/))([^"'\s?#)]+)([#?][^"')]+)?\s*["']?\)/ - def compile(asset) - asset.content.gsub(ASSET_URL_PATTERN) { asset_url resolve_path(asset.logical_path.dirname, $1), asset.logical_path, $2, $1 } + def compile(asset, input) + input.gsub(ASSET_URL_PATTERN) { asset_url resolve_path(asset.logical_path.dirname, $1), asset.logical_path, $2, $1 } end def referenced_by(asset) diff --git a/lib/propshaft/compiler/source_mapping_urls.rb b/lib/propshaft/compiler/source_mapping_urls.rb index 56e8150..d15e862 100644 --- a/lib/propshaft/compiler/source_mapping_urls.rb +++ b/lib/propshaft/compiler/source_mapping_urls.rb @@ -5,8 +5,8 @@ class Propshaft::Compiler::SourceMappingUrls < Propshaft::Compiler SOURCE_MAPPING_PATTERN = %r{(//|/\*)# sourceMappingURL=(.+\.map)(\s*?\*\/)?\s*?\Z} - def compile(asset) - asset.content.gsub(SOURCE_MAPPING_PATTERN) { source_mapping_url(asset.logical_path, asset_path($2, asset.logical_path), $1, $3) } + 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 diff --git a/lib/propshaft/compilers.rb b/lib/propshaft/compilers.rb index 86e3cb8..9afd1a9 100644 --- a/lib/propshaft/compilers.rb +++ b/lib/propshaft/compilers.rb @@ -23,7 +23,7 @@ def compile(asset) if relevant_registrations = registrations[asset.content_type.to_s] asset.content.dup.tap do |input| relevant_registrations.each do |compiler| - input.replace compiler.new(assembly).compile(asset) + input.replace compiler.new(assembly).compile(asset, input) end end else