Skip to content

Add assets helpers to rails views#38

Merged
excid3 merged 4 commits intoexcid3:mainfrom
javierav:assets-helper
Jul 14, 2025
Merged

Add assets helpers to rails views#38
excid3 merged 4 commits intoexcid3:mainfrom
javierav:assets-helper

Conversation

@javierav
Copy link
Contributor

When generating PDFs using Chrome we have to take into account certain limitations as documented in a post on Nathan Friend's blog. Perhaps the most relevant is that headers and footers can't use external resources, which forces us to add them inline if they are CSS styles or JavaScript code or to add them in base64 if they are images.

To simplify all this operations, this PR adds three helpers to help us in this task:

  • ferrum_pdf_inline_stylesheet
  • ferrum_pdf_inline_javascript
  • ferrum_pdf_base64_asset

For example:

<!doctype html>
<html lang="es">
  <head>
    <meta charset="utf-8">
    <%= ferrum_pdf_inline_stylesheet("tailwind.css") %>
  </head>
  <body>
    <%= yield %>
  </body>
</html>
<header>
  <div>
    <%= image_tag ferrum_pdf_base64_asset("logo.svg") %>
  </div>
</header>

Initially it only has support for assets managed by Propshaft or Sprockets, but it can be extended to other libraries.

I am delighted to collaborate on this project and open to any ideas or suggestions for improvement.

@excid3 excid3 merged commit 6673333 into excid3:main Jul 14, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants