From 0db14056872c94cce65a2a074129466dfe119184 Mon Sep 17 00:00:00 2001 From: Sergey Glukhov Date: Tue, 11 Jun 2024 13:10:42 +0300 Subject: [PATCH] Allow/Fix precompiled assets with Propshaft pipeline --- lib/wicked_pdf/wicked_pdf_helper/assets.rb | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/lib/wicked_pdf/wicked_pdf_helper/assets.rb b/lib/wicked_pdf/wicked_pdf_helper/assets.rb index 77163265..d596dcb9 100644 --- a/lib/wicked_pdf/wicked_pdf_helper/assets.rb +++ b/lib/wicked_pdf/wicked_pdf_helper/assets.rb @@ -28,20 +28,6 @@ def initialize(url, response) end end - class PropshaftAsset < SimpleDelegator - def content_type - super.to_s - end - - def to_s - content - end - - def filename - path.to_s - end - end - class SprocketsEnvironment def self.instance @instance ||= Sprockets::Railtie.build_environment(Rails.application) @@ -72,6 +58,12 @@ def filename end end + class PropshaftAsset < LocalAsset + def to_s + Rails.application.assets.resolver.read(path) + end + end + def wicked_pdf_asset_base64(path) asset = find_asset(path) raise MissingLocalAsset, path if asset.nil? @@ -200,7 +192,7 @@ def find_asset(path) if Rails.application.assets.respond_to?(:find_asset) Rails.application.assets.find_asset(path, :base_path => Rails.application.root.to_s) elsif defined?(Propshaft::Assembly) && Rails.application.assets.is_a?(Propshaft::Assembly) - PropshaftAsset.new(Rails.application.assets.load_path.find(path)) + PropshaftAsset.new(path) elsif Rails.application.respond_to?(:assets_manifest) asset_path = File.join(Rails.application.assets_manifest.dir, Rails.application.assets_manifest.assets[path]) LocalAsset.new(asset_path) if File.file?(asset_path)