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

Support webpacker assets #896

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Metrics/BlockLength:
Exclude:
- 'wicked_pdf.gemspec'

Metrics/ModuleLength:
Exclude:
# Excluding to keep the logic in one module for the time being.
- 'lib/wicked_pdf/wicked_pdf_helper/assets.rb'

# I'd like wicked_pdf to keep Ruby 1.8 compatibility for now
Style/HashSyntax:
EnforcedStyle: hash_rockets
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ Using wicked_pdf_helpers with asset pipeline raises `Asset names passed to helpe

#### Webpacker usage

wicked_pdf supports webpack stylesheets and javascript assets.
wicked_pdf supports webpack assets.

Use `wicked_pdf_stylesheet_pack_tag` for stylesheets
Use `wicked_pdf_javascript_pack_tag` for javascripts

Use `wicked_pdf_asset_pack_path` to access an asset directly, for example: `image_tag wicked_pdf_asset_pack_path("media/images/foobar.png")`

#### Asset pipeline usage

It is best to precompile assets used in PDF views. This will help avoid issues when it comes to deploying, as Rails serves asset files differently between development and production (`config.assets.compile = false`), which can make it look like your PDFs work in development, but fail to load assets in production.
Expand Down
10 changes: 10 additions & 0 deletions lib/wicked_pdf/wicked_pdf_helper/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ def wicked_pdf_asset_path(asset)
end
end

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

if running_in_development?
asset_pack_path(asset)
else
wicked_pdf_asset_path webpacker_source_url(asset)
end
end

private

# borrowed from actionpack/lib/action_view/helpers/asset_url_helper.rb
Expand Down