-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Bulma extra helper * Added templates for Bulma extra * Added documentation for Bulma extra * Added Bulma support for responsive extra * Added Bulma support for compact extra * Added information about bulma extra into README
- Loading branch information
Showing
15 changed files
with
424 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: Bulma | ||
--- | ||
# Bulma Extra | ||
|
||
This extra adds nav helper and templates for Bulma CSS framework [pagination component](https://bulma.io/documentation/components/pagination). | ||
|
||
## Synopsys | ||
|
||
See [extras](../extras.md) for general usage info. | ||
|
||
Render the navigation links in some view... | ||
with a fast helper: | ||
|
||
```erb | ||
<%== pagy_nav_bulma(@pagy) %> | ||
``` | ||
|
||
or with a template: | ||
|
||
```erb | ||
<%== render 'pagy/nav_bulma', locals: {pagy: @pagy} %> | ||
``` | ||
|
||
## Files | ||
|
||
This extra is composed of 4 files: | ||
|
||
- [bulma.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/bulma.rb) | ||
- [nav_bulma.html.erb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/templates/nav_bulma.html.erb) (optional template) | ||
- [nav_bulma.html.haml](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/templates/nav_bulma.html.haml) (optional template) | ||
- [nav_bulma.html.slim](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/templates/nav_bulma.html.slim) (optional template) | ||
|
||
## Methods | ||
|
||
This extra adds one nav helpers to the `Pagy::Frontend` module. You can customize it by overriding it directly in your own view helper. | ||
|
||
### pagy_nav_bulma(pagy) | ||
|
||
This method is the same as the `pagy_nav`, but customized for Bulma. | ||
|
||
The `nav_bulma.*` templates produce the same output, and can be used as an easier (but slower) starting point to override it. | ||
|
||
### Optional Template Files | ||
|
||
See [Using Templates](../how-to.md#using-templates). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/bulma | ||
# frozen_string_literal: true | ||
|
||
class Pagy | ||
# Add nav helper for Bulma pagination | ||
module Frontend | ||
|
||
def pagy_nav_bulma(pagy) | ||
html, link, p_prev, p_next = +'', pagy_link_proc(pagy), pagy.prev, pagy.next | ||
|
||
html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"') | ||
: %(<a class="pagination-previous" disabled>#{pagy_t('pagy.nav.prev')}</a>)) | ||
html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"') | ||
: %(<a class="pagination-next" disabled>#{pagy_t('pagy.nav.next')}</a>)) | ||
html << '<ul class="pagination-list">' | ||
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] | ||
html << pagy_nav_bulma_item(link, item) | ||
end | ||
html << '</ul>' | ||
%(<nav class="pagy-nav-bulma pagination is-centered" role="navigation" aria-label="pagination">#{html}</nav>) | ||
end | ||
|
||
private | ||
|
||
def pagy_nav_bulma_item(link, item) | ||
if item.is_a?(Integer) # page link | ||
aria = %( area-label="goto page #{item}") | ||
%(<li>#{link.call item, item, 'class="pagination-link"' + aria}</li>) | ||
elsif item.is_a?(String) # active page | ||
aria = %( area-label="page #{item}" area-current="page") | ||
%(<li>#{link.call item, item, 'class="pagination-link is-current"' + aria}</li>) | ||
elsif item == :gap # page gap | ||
%(<li><span class="pagination-ellipsis">#{pagy_t('pagy.nav.gap')}</span></li>) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<%# | ||
This template is i18n-ready: if you don't use i18n, then you can replace the pagy_t | ||
calls with the actual strings ("‹ Prev", "Next ›", "…"). | ||
The link variable is set to a proc that returns the link tag. | ||
Usage: link.call( page_number [, text [, extra_attributes_string ]]) | ||
-%> | ||
<% link = pagy_link_proc(pagy) -%> | ||
<%# -%><nav class="pagy-nav-bulma pagination is-centered" role="navigation" aria-label="pagination"> | ||
<% if pagy.prev -%> <%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"') %> | ||
<% else -%> <a class="pagination-previous" disabled><%== pagy_t('pagy.nav.prev') %></a> | ||
<% end -%> | ||
<% if pagy.next -%> <%== link.call(pagy.next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"') %> | ||
<% else -%> <a class="pagination-next" disabled><%== pagy_t('pagy.nav.next') %></a> | ||
<% end -%> | ||
<%# -%> <ul class="pagination-list"> | ||
<% pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] -%> | ||
<% if item.is_a?(Integer) -%> <li><%== link.call item, item, %(class="pagination-link" area-label="goto page #{item}") %></li> | ||
<% elsif item.is_a?(String) -%> <li><%== link.call item, item, %(class="pagination-link is-current" area-label="page #{item}" area-current="page") %></li> | ||
<% elsif item == :gap -%> <li><span class="pagination-ellipsis"><%== pagy_t('pagy.nav.gap') %></span></li> | ||
<% end -%> | ||
<% end -%> | ||
<%# -%> </ul> | ||
<%# -%></nav> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-# This template is i18n-ready: if you don't use i18n, then you can replace the pagy_t | ||
-# calls with the actual strings ("‹ Prev", "Next ›", "…"). | ||
-# The link variable is set to a proc that returns the link tag. | ||
-# Usage: link.call( page_number [, text [, extra_attributes_string ]]) | ||
- link = pagy_link_proc(pagy) | ||
|
||
%nav.pagy-nav-bulma.pagination.is-centered{:role => "navigation", "aria-label" => "pagination"} | ||
|
||
- if pagy.prev | ||
!= link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"') | ||
- else | ||
%a.pagination-previous{:disabled => "disabled"}!= pagy_t('pagy.nav.prev') | ||
|
||
- if pagy.next | ||
!= link.call(pagy.next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"') | ||
- else | ||
%a.pagination-next{:disabled => "disabled"}!= pagy_t('pagy.nav.next') | ||
|
||
%ul.pagination-list | ||
|
||
- pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] | ||
- if item.is_a?(Integer) # page link | ||
%li!= link.call item, item, %(class="pagination-link" area-label="goto page #{item}") | ||
|
||
- elsif item.is_a?(String) # current page | ||
%li!= link.call item, item, %(class="pagination-link is-current" area-label="page #{item}" area-current="page") | ||
|
||
- elsif item == :gap # page gap | ||
%li | ||
%span.pagination-ellipsis!= pagy_t('pagy.nav.gap') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/ This template is i18n-ready: if you don't use i18n, then you can replace the pagy_t | ||
/ calls with the actual strings ("‹ Prev", "Next ›", "…"). | ||
/ The link variable is set to a proc that returns the link tag. | ||
/ Usage: link.call( page_number [, text [, extra_attributes_string ]]) | ||
- link = pagy_link_proc(pagy) | ||
|
||
nav.pagy-nav-bulma.pagination.is-centered role="navigation" aria-label="pagination" | ||
|
||
- if pagy.prev | ||
== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"') | ||
- else | ||
a.pagination-previous disabled="disabled" == pagy_t('pagy.nav.prev') | ||
|
||
- if pagy.next | ||
== link.call(pagy.next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"') | ||
- else | ||
a.pagination-next disabled="disabled" == pagy_t('pagy.nav.next') | ||
|
||
ul.pagination-list | ||
|
||
- pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] | ||
- if item.is_a?(Integer) # page link | ||
li == link.call item, item, %(class="pagination-link" area-label="goto page #{item}") | ||
|
||
- elsif item.is_a?(String) # current page | ||
li == link.call item, item, %(class="pagination-link is-current" area-label="page #{item}" area-current="page") | ||
|
||
- elsif item == :gap # page gap | ||
li | ||
span.pagination-ellipsis == pagy_t('pagy.nav.gap') |
Oops, something went wrong.