scrivener_html
scrivener_html copied to clipboard
Adding a pagination_info helper
It's pretty trivial, but I was thinking this library should included something like this:
iex> Scrivener.HTML.pagination_info(%Scrivener.Page{total_pages: 10, page_number: 5, total_entries: 100, page_size: 10}) |> Phoenix.HTML.safe_to_string()
"<div class="pagination_info">
Showing 51 to 60 of 100 entries
</div>"
It should be as simple as something like:
def pagination_info(paginator, name \\ "entries") do
text =
with first = (paginator.page_number - 1) * paginator.page_size + 1,
last = min(paginator.page_number * paginator.page_size, paginator.total_entries),
total = paginator.total_entries,
do: "Showing #{first} to #{last} of #{total} #{name}"
content_tag(:div, safe(text), class: "pagination_info")
end
But then what if the user wants this to be different text, or international? Its so simple to create my first thought is that this could cause more problems than it solves.