Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow/Fix precompiled assets with Propshaft pipeline #1120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading