Skip to content

Commit 9b5931f

Browse files
authored
Merge pull request #1120 from serggl/propshaft_fix
Allow/Fix precompiled assets with Propshaft pipeline
2 parents 2bf120d + 0db1405 commit 9b5931f

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

lib/wicked_pdf/wicked_pdf_helper/assets.rb

+7-15
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,6 @@ def initialize(url, response)
3030
end
3131
end
3232

33-
class PropshaftAsset < SimpleDelegator
34-
def content_type
35-
super.to_s
36-
end
37-
38-
def to_s
39-
content
40-
end
41-
42-
def filename
43-
path.to_s
44-
end
45-
end
46-
4733
class SprocketsEnvironment
4834
def self.instance
4935
@instance ||= Sprockets::Railtie.build_environment(Rails.application)
@@ -74,6 +60,12 @@ def filename
7460
end
7561
end
7662

63+
class PropshaftAsset < LocalAsset
64+
def to_s
65+
Rails.application.assets.resolver.read(path)
66+
end
67+
end
68+
7769
def wicked_pdf_asset_base64(path)
7870
asset = find_asset(path)
7971
raise MissingLocalAsset, path if asset.nil?
@@ -202,7 +194,7 @@ def find_asset(path)
202194
if Rails.application.assets.respond_to?(:find_asset)
203195
Rails.application.assets.find_asset(path, :base_path => Rails.application.root.to_s)
204196
elsif defined?(Propshaft::Assembly) && Rails.application.assets.is_a?(Propshaft::Assembly)
205-
PropshaftAsset.new(Rails.application.assets.load_path.find(path))
197+
PropshaftAsset.new(path)
206198
elsif Rails.application.respond_to?(:assets_manifest)
207199
relative_asset_path = get_asset_path_from_manifest(path)
208200
return unless relative_asset_path

0 commit comments

Comments
 (0)