Skip to content

Commit

Permalink
Support Propshaft in find_asset helper
Browse files Browse the repository at this point in the history
  • Loading branch information
serggl committed Feb 18, 2022
1 parent 769f9df commit b8c54dc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/wicked_pdf/wicked_pdf_helper/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b8c54dc

Please sign in to comment.