$ show ddnexus/pagy
Pagy is a high-performance, agnostic pagination library for Ruby web applications (Rails, Sinatra, Rack) and any Ruby collection. It provides multiple pagination techniques: offset, keyset (cursor-based), countless (no total count), countish (cached count), calendar (time-based), and search backend integrations (Elasticsearch, Meilisearch, Searchkick, Typesense). The gem includes a rich set of view helpers for pagination navigation (series, input, limit, info) with Bootstrap, Bulma, and Tailwind CSS support, plus client-side JavaScript for responsive and interactive navs. Its architecture is modular: paginators and helpers are loaded on demand via a deferred loading pattern, and abilities (shiftable, rangeable, countable, linkable) are composed into paginator classes. The codebase is thoroughly tested (100% line/branch coverage, unit, API, and E2E tests) and highly optimized for speed and memory. It also provides a CLI, dev tools (PagyWand for CSS customization, Pagy AI assistant), and extensive documentation. The library is not a data research project; it is a production-ready software component.
The LLM identified 4 files worth highlighting for reuse:
A set of five self-contained Ruby modules (Shiftable, Rangeable, Countable, Linkable, Configurable) that encapsulate reusable pagination behaviors. Each module defines a single responsibility (e.g., Shiftable provides next/prev limits, Linkable builds anchor tags) and can be composed into any paginator class. They are isolated with no internal dependencies beyond basic Pagy constants, making them extractable for any pagination or enumeration component.
A complete, lightweight i18n implementation designed for small libraries. It loads YAML locale files with dot-flattened keys, supports pluralization via custom rule modules (Arabic, Polish, EastSlavic, WestSlavic, etc.), and uses thread-local configuration. The module is framework-agnostic and can be extracted for any Ruby library that needs minimal i18n without pulling in Rails' I18n.
A standalone ES module that powers Pagy's interactive frontend features: responsive series navigation (auto-collapse on narrow screens), keynav (keyboard-driven page navigation with cross-tab session sync via BroadcastChannel), input nav (page jump input), and limit tag (page size selector). It uses a data-driven pattern where page links carry a `data-pagy` attribute with Base64-encoded initialization data. The module is fully self-contained (zero dependencies) and can be reused in any web project needing performant pagination UI.
An adapter that extracts keyset (cursor-based) pagination attributes from an ActiveRecord relation. It implements `extract_keyset`, `keyset_attributes_from`, and `keyset_build_arel` methods to convert Pagy's generic keyset options into an optimized SQL query using tuple comparison. The adapter is decoupled from the main Keyset paginator via a simple interface, and can serve as a reference for implementing keyset adapters for any ORM (e.g., Sequel, ROM).