For pagination many people (like me) use scrivener
and scrivener_ecto
, which works great for offset based pagination. What never really fit my work though was scrivener_html
, because I often don’t use frameworks and it took over link generation and styles so extensively.
A thread here on the forums today made me clean up some code I wrote a few days ago for a new project and release it on hex:
The package does not generate any markup at all, but instead creates a list of elements, which describe the pagination. You need to keep GET parameters on the urls, because the paginated content is filtered? Numerator doesn’t care. You want to use custom styles? Go ahead. You need to display the pagination in a CLI? No problem.
iex(1)> Numerator.build(%{page: 6, last: 17}, show_first: true, show_last: true)
[
%{page: 5, type: :prev},
%{page: 1, type: :page},
%{type: :ellipsis},
%{page: 4, type: :page},
%{page: 5, type: :page},
%{page: 6, type: :current},
%{page: 7, type: :page},
%{page: 8, type: :page},
%{type: :ellipsis},
%{page: 17, type: :page},
%{page: 7, type: :next}
]
It does support a scrivener page struct as first argument as well, so there’s no need to convert the map parameters manually.
I’ve also added an example implementation for bootstrap in the readme: https://github.com/madeitGmbH/numerator/blob/master/README.md#bootstrap