From b8c54dc5a3652e395832cff24f479253b9b433be Mon Sep 17 00:00:00 2001 From: Sergey Glukhov Date: Fri, 18 Feb 2022 10:49:40 +0300 Subject: [PATCH] Support Propshaft in find_asset helper --- lib/wicked_pdf/wicked_pdf_helper/assets.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/wicked_pdf/wicked_pdf_helper/assets.rb b/lib/wicked_pdf/wicked_pdf_helper/assets.rb index ff2defd3..0691aaf0 100644 --- a/lib/wicked_pdf/wicked_pdf_helper/assets.rb +++ b/lib/wicked_pdf/wicked_pdf_helper/assets.rb @@ -5,6 +5,20 @@ module WickedPdfHelper module Assets ASSET_URL_REGEX = /url\(['"]?([^'"]+?)['"]?\)/ + class PropshaftAsset < SimpleDelegator + def content_type + super.to_s + end + + def to_s + content + end + + def filename + path.to_s + end + end + def wicked_pdf_asset_base64(path) asset = find_asset(path) raise "Could not find asset '#{path}'" if asset.nil? @@ -132,6 +146,8 @@ def asset_pathname(source) 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)) else Sprockets::Railtie.build_environment(Rails.application).find_asset(path, :base_path => Rails.application.root.to_s) end