Skip to content

Commit

Permalink
Merge pull request #1010 from serggl/propshaft
Browse files Browse the repository at this point in the history
Add support for Propshaft asset pipeline
  • Loading branch information
unixmonkey authored Apr 17, 2022
2 parents dfd990b + b8c54dc commit 077f0b3
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 077f0b3

Please sign in to comment.