Skip to content

Commit

Permalink
Update README for new first/last feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgwidmann committed Apr 14, 2017
1 parent 27dec42 commit b5a9ebc
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,31 @@ end
You would need to pass in the `:locale` parameter and `:path` option like so:

```elixir
<%= pagination_links @page, ["en"], path: &pages_path/4 %>
<%= pagination_links @conn, @page, ["en"], path: &pages_path/4 %>
```

With a nested resource, simply add it to the list:

```elixir
<%= pagination_links @page, ["en", @page_id], path: &page_path/4, action: :show %>
<%= pagination_links @conn, @page, ["en", @page_id], path: &page_path/4, action: :show %>
```

#### Query String Parameters

Any additional query string parameters can be passed in as well.

```elixir
<%= pagination_links @page, ["en"], some_parameter: "data" %>
<%= pagination_links @conn, @page, ["en"], some_parameter: "data" %>
<%# OR IF NO URL PARAMETERS %>
<%= pagination_links @page, some_parameter: "data" %>
<%= pagination_links @conn, @page, some_parameter: "data" %>
```

### Custom Actions

If you need to hit a different action other than `:index`, simply pass the action name to use in the url helper.

```elixir
<%= pagination_links @page, action: :show %>
<%= pagination_links @conn, @page, action: :show %>
```

## Customizing Output
Expand All @@ -122,26 +122,35 @@ Below are the defaults which are used without passing in any options.
To prevent HTML escaping (i.e. seeing things like `&lt;` on the page), simply use `Phoenix.HTML.raw/1` for any `&amp;` strings passed in, like so:

```elixir
<%= pagination_links @page, previous: Phoenix.HTML.raw("&leftarrow;"), next: Phoenix.HTML.raw("&rightarrow;") %>
<%= pagination_links @conn, @page, previous: Phoenix.HTML.raw("&leftarrow;"), next: Phoenix.HTML.raw("&rightarrow;") %>
```

To show icons instead of text, simply render custom html templates, like:

<%= pagination_links @page, render(MyPhoenixApp.MyView, "prev_link.html", []), next: render(MyPhoenixApp.MyView, "next_link.html", []) %>
_(this example uses materialize icons)_

And in prev_link.html.eex (this example use materialize icons)
<i class="material-icons">chevron_left</i>
```elixir
<%= pagination_links @conn, @page, previous: ~E(<i class="material-icons">chevron_left</i>), next: ~E(<i class="material-icons">chevron_right</i>) %>
```

The same can be done for first/last links as well (`v1.7.0` or higher).

_(this example uses materialize icons)_

```elixir
<%= pagination_links @conn, @page, first: ~E(<i class="material-icons">chevron_left</i>), last: ~E(<i class="material-icons">chevron_right</i>) %>
```

There are five view styles currently supported:

- `:bootstrap` (the default) This styles the pagination links in a manner that
is expected by Bootstrap 3.x.
- `:bootstrap_v4` This styles the pagination links in a manner that
is expected by Bootstrap 4.x.
- `:foundation` This styles the pagination links in a manner that is expected
by Foundation for Sites 6.x.
- `:semantic` This styles the pagination links in a manner that is expected by
Semantic UI 2.x.
- `:bootstrap_v4` This styles the pagination links in a manner that
is expected by Bootstrap 4.x.
- `:materialize` This styles the pagination links in a manner that
is expected by Materialize css 0.x.

Expand All @@ -152,21 +161,21 @@ See `Scrivener.HTML.raw_pagination_links/2` for option descriptions.
Scrivener.HTML can be included in your view and then just used with a simple call to `pagination_links/1`.

```elixir
iex> Scrivener.HTML.pagination_links(%Scrivener.Page{total_pages: 10, page_number: 5})
{:safe,
["<nav>",
["<ul class=\"pagination\">",
[["<li>", ["<a class=\"\" href=\"?page=4\">", "&lt;&lt;", "</a>"], "</li>"],
["<li>", ["<a class=\"\" href=\"?page=1\">", "1", "</a>"], "</li>"],
["<li>", ["<a class=\"\" href=\"?page=2\">", "2", "</a>"], "</li>"],
["<li>", ["<a class=\"\" href=\"?page=3\">", "3", "</a>"], "</li>"],
["<li>", ["<a class=\"\" href=\"?page=4\">", "4", "</a>"], "</li>"],
["<li>", ["<a class=\"active\" href=\"?page=5\">", "5", "</a>"], "</li>"],
["<li>", ["<a class=\"\" href=\"?page=6\">", "6", "</a>"], "</li>"],
["<li>", ["<a class=\"\" href=\"?page=7\">", "7", "</a>"], "</li>"],
["<li>", ["<a class=\"\" href=\"?page=8\">", "8", "</a>"], "</li>"],
["<li>", ["<a class=\"\" href=\"?page=9\">", "9", "</a>"], "</li>"],
["<li>", ["<a class=\"\" href=\"?page=10\">", "10", "</a>"], "</li>"],
["<li>", ["<a class=\"\" href=\"?page=6\">", "&gt;&gt;", "</a>"], "</li>"]],
"</ul>"], "</nav>"]}
iex> Scrivener.HTML.pagination_links(%Scrivener.Page{total_pages: 10, page_number: 5}) |> Phoenix.HTML.safe_to_string()
"<nav>
<ul class=\"pagination\">
<li class=\"\"><a class=\"\" href=\"?page=4\">&lt;&lt;</a></li>
<li class=\"\"><a class=\"\" href=\"?page=1\">1</a></li>
<li class=\"\"><a class=\"\" href=\"?page=2\">2</a></li>
<li class=\"\"><a class=\"\" href=\"?page=3\">3</a></li>
<li class=\"\"><a class=\"\" href=\"?page=4\">4</a></li>
<li class=\"active\"><a class=\"\" href=\"?page=5\">5</a></li>
<li class=\"\"><a class=\"\" href=\"?page=6\">6</a></li>
<li class=\"\"><a class=\"\" href=\"?page=7\">7</a></li>
<li class=\"\"><a class=\"\" href=\"?page=8\">8</a></li>
<li class=\"\"><a class=\"\" href=\"?page=9\">9</a></li>
<li class=\"\"><a class=\"\" href=\"?page=10\">10</a></li>
<li class=\"\"><a class=\"\" href=\"?page=6\">&gt;&gt;</a></li>
</ul>
</nav>"
```

0 comments on commit b5a9ebc

Please sign in to comment.