Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a pagination_info helper #82

Open
JohnKacz opened this issue Feb 4, 2019 · 1 comment
Open

Adding a pagination_info helper #82

JohnKacz opened this issue Feb 4, 2019 · 1 comment

Comments

@JohnKacz
Copy link

JohnKacz commented Feb 4, 2019

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
@mgwidmann
Copy link
Owner

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.

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

No branches or pull requests

2 participants