Skip to content

Kurisu3/numerator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Numerator

Build Status Coverage Status

Numerator does calculate paginations without creating any markup. Building markup based on the returned list of elements is up to the user.

Usage

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}
]

Options

  • :show_prev: Include a prev. page element. Default true
  • :show_next: Include a next page element. Default true
  • :prev_next_unavailable_mode: :remove or :disable unavailable prev. or next page elements. Default :remove
  • :show_first: Always show first page. Default false
  • :show_last: Always show last page. Default false
  • :num_pages_shown: How many numbers for pages to be shown at least. Default 5

Bootstrap

Example implementation using the Twitter Bootstrap UI framework.

<ul class="pagination">
	<%= for element <- pagination_data do %>
		<%= case element do %>
			<% %{type: :ellipsis} -> %>
				<li class="page-item disabled"><span class="page-link">…</span></li>
			<% %{type: :current, page: page} -> %>
				<li class="page-item active" aria-current="page">
					<span class="page-link"><%= page %><span class="sr-only">(current)</span></span>
				</li>
			<% %{type: :page, page: page} -> %>
				<li class="page-item">
					<%= link page, to: Routes.index_path(@conn, :index, %{page: page}) %>
				</li>
			<% %{type: :prev, page: :disabled} -> %>
				<li class="page-item disabled"><span class="page-link"><%= dgettext("pagination", "Prev. Page") %></span></li>
			<% %{type: :prev, page: page} -> %>
				<li class="page-item">
					<%= link dgettext("pagination", "Prev. Page"), to: Routes.index_path(@conn, :index, %{page: page}) %>
				</li>
			<% %{type: :next, page: :disabled} -> %>
				<li class="page-item disabled"><span class="page-link"><%= dgettext("pagination", "Next Page") %></span></li>
			<% %{type: :next, page: page} -> %>
				<li class="page-item">
					<%= link dgettext("pagination", "Next Page"), to: Routes.index_path(@conn, :index, %{page: page}) %>
				</li>
		<% end %>
	<% end %>
</ul>

Installation

The package can be installed by adding numerator to your list of dependencies in mix.exs:

def deps do
  [
    {:numerator, git: "https://github.com/Kurisu3/numerator.git"}
  ]
end

About

A tool for customizable pagination calculations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 100.0%