Skip to content

Commit ada880b

Browse files
authored
Merge pull request #57 from b-murphy/feature/add-bulma
add bulma 0.4.x support
2 parents ab197ee + 85557af commit ada880b

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ _(this example uses materialize icons)_
141141
<%= pagination_links @conn, @page, first: ~E(<i class="material-icons">chevron_left</i>), last: ~E(<i class="material-icons">chevron_right</i>) %>
142142
```
143143

144-
There are five view styles currently supported:
144+
There are six view styles currently supported:
145145

146146
- `:bootstrap` (the default) This styles the pagination links in a manner that
147147
is expected by Bootstrap 3.x.
@@ -153,6 +153,7 @@ There are five view styles currently supported:
153153
Semantic UI 2.x.
154154
- `:materialize` This styles the pagination links in a manner that
155155
is expected by Materialize css 0.x.
156+
- `:bulma` This styles the pagination links in a manner that is expected by Bulma 0.4.x, using the `is-centered` as a default.
156157

157158
For custom HTML output, see `Scrivener.HTML.raw_pagination_links/2`.
158159

lib/scrivener/html.ex

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Scrivener.HTML do
22
use Phoenix.HTML
33
@defaults [view_style: :bootstrap, action: :index, page_param: :page]
4-
@view_styles [:bootstrap, :semantic, :foundation, :bootstrap_v4, :materialize]
4+
@view_styles [:bootstrap, :semantic, :foundation, :bootstrap_v4, :materialize, :bulma]
55
@raw_defaults [distance: 5, next: ">>", previous: "<<", first: true, last: true, ellipsis: raw("&hellip;")]
66
@moduledoc """
77
For use with Phoenix.HTML, configure the `:routes_helper` module like the following:
@@ -186,6 +186,17 @@ defmodule Scrivener.HTML do
186186
end
187187
end
188188

189+
# Bulma implementation
190+
defp _pagination_links(paginator, [view_style: :bulma, path: path, args: args, page_param: page_param, params: params]) do
191+
url_params = Keyword.drop params, Keyword.keys(@raw_defaults)
192+
content_tag :nav, class: "pagination is-centered" do
193+
content_tag :ul, class: "pagination-list" do
194+
raw_pagination_links(paginator, params)
195+
|> Enum.map(&page(&1, url_params, args, page_param, path, paginator, :bulma))
196+
end
197+
end
198+
end
199+
189200
defp page({:ellipsis, true}, url_params, args, page_param, path, paginator, style) do
190201
page({:ellipsis, unquote(@raw_defaults[:ellipsis])}, url_params, args, page_param, path, paginator, style)
191202
end
@@ -244,13 +255,20 @@ defmodule Scrivener.HTML do
244255
defp li_classes_for_style(paginator, page_number, :materialize) do
245256
if(paginator.page_number == page_number, do: ["active"], else: ["waves-effect"])
246257
end
258+
defp li_classes_for_style(_paginator, :ellipsis, :bulma), do: []
259+
defp li_classes_for_style(_paginator, _page_number, :bulma), do: []
247260

248261
defp link_classes_for_style(_paginator, _page_number, :bootstrap), do: []
249262
defp link_classes_for_style(_paginator, _page_number, :bootstrap_v4), do: ["page-link"]
250263
defp link_classes_for_style(_paginator, _page_number, :foundation), do: []
251264
defp link_classes_for_style(_paginator, _page_number, :materialize), do: []
265+
defp link_classes_for_style(paginator, page_number, :bulma) do
266+
if(paginator.page_number == page_number, do: ["pagination-link", "is-current"], else: ["pagination-link"])
267+
end
268+
252269
defp link_classes_for_style(_paginator, :ellipsis, :semantic), do: ["disabled", "item"]
253270
defp link_classes_for_style(_paginator, :ellipsis, :materialize), do: []
271+
defp link_classes_for_style(_paginator, :ellipsis, :bulma), do: ["pagination-ellipsis"]
254272

255273
defp ellipsis_tag(:semantic), do: :div
256274
defp ellipsis_tag(_), do: :span

test/scrivener/html_test.exs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ defmodule Scrivener.HTMLTest do
192192

193193
test "uses application config" do
194194
Application.put_env(:scrivener_html, :view_style, :another_style)
195-
assert_raise RuntimeError, "Scrivener.HTML: View style :another_style is not a valid view style. Please use one of [:bootstrap, :semantic, :foundation, :bootstrap_v4, :materialize]", fn ->
195+
assert_raise RuntimeError, "Scrivener.HTML: View style :another_style is not a valid view style. Please use one of [:bootstrap, :semantic, :foundation, :bootstrap_v4, :materialize, :bulma]", fn ->
196196
HTML.pagination_links(%Page{total_pages: 10, page_number: 5})
197197
end
198198
end
@@ -362,7 +362,7 @@ defmodule Scrivener.HTMLTest do
362362
end
363363
end
364364

365-
describe "Materialize css" do
365+
describe "Materialize css" do
366366
test "renders materialize css styling" do
367367
use Phoenix.ConnTest
368368
Application.put_env(:scrivener_html, :view_style, :materialize)
@@ -382,4 +382,22 @@ defmodule Scrivener.HTMLTest do
382382
end
383383
end
384384

385+
describe "Bulma css" do
386+
test "renders bulma css styling" do
387+
use Phoenix.ConnTest
388+
Application.put_env(:scrivener_html, :view_style, :bulma)
389+
Application.put_env(:scrivener_html, :routes_helper, MyApp.Router.Helpers)
390+
391+
assert(
392+
{:safe, [60, "nav", [[32, "class", 61, 34, "pagination is-centered", 34]], 62,
393+
[60, "ul", [[32, "class", 61, 34, "pagination-list", 34]], 62,
394+
[[60, "li", [[32, "class", 61, 34, "", 34]], 62,
395+
[60, "a", [[32, "class", 61, 34, "pagination-link is-current", 34]], 62, "1", 60, 47, "a", 62], 60, 47,
396+
"li", 62], [60, "li", [[32, "class", 61, 34, "", 34]], 62, [60, "a", [[32, "class", 61, 34, "pagination-link", 34]],
397+
62, "2", 60, 47, "a", 62], 60, 47, "li", 62], [60, "li", [[32, "class", 61, 34, "", 34]], 62, [60, "a", [[32, "class", 61, 34, "pagination-link", 34]],
398+
62, "&gt;&gt;", 60, 47, "a", 62], 60, 47, "li", 62]], 60, 47, "ul", 62], 60, 47, "nav", 62]
399+
}
400+
) == HTML.pagination_links(build_conn(), %Page{entries: [], page_number: 1, page_size: 10, total_entries: 2, total_pages: 2})
401+
end
402+
end
385403
end

0 commit comments

Comments
 (0)