JavaScript
Add the oj gem to your gemfile
It is not a requirement, but if present, the pagy JSON generation will be faster.
Setup
Good for apps with a minifier (Sprockets, builers, ...)
Make Pagy available in your JavaScript environment with...
application.js
import Pagy from "pagy.mjs"
Good for apps without a minifier (Propshaft, Importmaps, ...)
Make Pagy available in your JavaScript environment with...
ERB template / HTML page
<%= javascript_include_tag "pagy.min.js" ...%>
<!-- or if your app does not provide helpers -->
<script src="/path/to/pagy.min.js"></script>
Use it only for development / debugging of Pagy itself.
Works with any app
The following statement will copy and keep synced the pagy* file in your own app/javascript dir (or any dir you may want use).
It will become and processed exactly like one of your own files.
# Replace 'pagy*' with the file you picked
Pagy.sync(:javascript, Rails.root.join('app/javascript'), 'pagy*') if Rails.development?
If you prefer to sync manually or during an automation step, you can define your own task with a single line in the Rakefile, or any *.rake file:
# Pagy::SyncTask.new(resource, destination, *targets)
# Replace 'pagy*' with the file you picked
Pagy::SyncTask.new(:javascript, Rails.root.join('app/javascript'), 'pagy*')
and exec it with...
bundle exec rake pagy:sync:javascript
Works only with apps with an assets pipeline
Rails.application.config.assets.paths << Pagy::ROOT.join('javascripts')
Pagy.init to an event...
window.addEventListener("load", Pagy.init)
window.addEventListener("turbo:load", Pagy.init)
window.addEventListener("turbolinks:load", Pagy.init)
window.addEventListener("your-event", Pagy.init)