Skip to content

Commit

Permalink
Allow/Fix precompiled assets with Propshaft pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
serggl committed Jun 11, 2024
1 parent 26bc414 commit 0db1405
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions lib/wicked_pdf/wicked_pdf_helper/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0db1405

Please sign in to comment.