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

assets: improve compatibility with Shakapacker 8 #1134

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
25 changes: 15 additions & 10 deletions lib/wicked_pdf/wicked_pdf_helper/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def wicked_pdf_stylesheet_link_tag(*sources)
end

def wicked_pdf_stylesheet_pack_tag(*sources)
return unless defined?(Webpacker)
return unless webpacker_class

if running_in_development?
stylesheet_pack_tag(*sources)
Expand All @@ -126,7 +126,7 @@ def wicked_pdf_stylesheet_pack_tag(*sources)
end

def wicked_pdf_javascript_pack_tag(*sources)
return unless defined?(Webpacker)
return unless webpacker_class

if running_in_development?
javascript_pack_tag(*sources)
Expand Down Expand Up @@ -163,7 +163,7 @@ def wicked_pdf_asset_path(asset)
end

def wicked_pdf_asset_pack_path(asset)
return unless defined?(Webpacker)
return unless webpacker_class

if running_in_development?
asset_pack_path(asset)
Expand Down Expand Up @@ -310,23 +310,28 @@ def webpacker_source_url(source)
end

def running_in_development?
return unless webpacker_version
return unless webpacker_class

# :dev_server method was added in webpacker 3.0.0
if Webpacker.respond_to?(:dev_server)
Webpacker.dev_server.running?
if webpacker_class.respond_to?(:dev_server)
webpacker_class.dev_server.running?
else
Rails.env.development? || Rails.env.test?
end
end

def webpacker_version
return unless webpacker_class

require "#{webpacker_class.to_s.downcase}/version"
webpacker_class.const_get('VERSION')
end

def webpacker_class
if defined?(Shakapacker)
require 'shakapacker/version'
Shakapacker::VERSION
Shakapacker
elsif defined?(Webpacker)
require 'webpacker/version'
Webpacker::VERSION
Webpacker
end
end
end
Expand Down