-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pagy_nav_foundation helpers and templates
- Loading branch information
Showing
14 changed files
with
435 additions
and
12 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
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: Foundation | ||
--- | ||
# Foundation Extra | ||
|
||
This extra adds nav helper and templates for Foundation pagination. | ||
|
||
## Synopsys | ||
|
||
See [extras](../extras.md) for general usage info. | ||
|
||
Render the navigation links in some view... | ||
with a fast helper: | ||
|
||
```erb | ||
<%== pagy_nav_foundation(@pagy) %> | ||
``` | ||
|
||
or with a template: | ||
|
||
```erb | ||
<%== render 'pagy/nav_foundation', locals: {pagy: @pagy} %> | ||
``` | ||
|
||
## Files | ||
|
||
This extra is composed of 4 files: | ||
|
||
- [foundation.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/foundation.rb) | ||
- [nav_foundation.html.erb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/templates/nav_foundation.html.erb) (optional template) | ||
- [nav_foundation.html.haml](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/templates/nav_foundation.html.haml) (optional template) | ||
- [nav_foundation.html.slim](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/templates/nav_foundation.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_foundation(pagy) | ||
|
||
This method is the same as the `pagy_nav`, but customized for Foundation. | ||
|
||
The `nav_foundation.*` 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,26 @@ | ||
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/foundation | ||
# frozen_string_literal: true | ||
|
||
class Pagy | ||
# Add nav helper for foundation pagination | ||
module Frontend | ||
|
||
# Pagination for foundation: it returns the html with the series of links to the pages | ||
def pagy_nav_foundation(pagy) | ||
html, link, p_prev, p_next = +'', pagy_link_proc(pagy), pagy.prev, pagy.next | ||
|
||
html << (p_prev ? %(<li class="prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>) | ||
: %(<li class="prev disabled">#{pagy_t('pagy.nav.prev')}</li>)) | ||
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] | ||
html << if item.is_a?(Integer); %(<li>#{link.call item}</li>) # page link | ||
elsif item.is_a?(String) ; %(<li class="current"><span class="show-for-sr">You're on page</span>#{item}</li>) # active page | ||
elsif item == :gap ; %(<li class="ellipsis" aria-hidden="true"></li>) # page gap | ||
end | ||
end | ||
html << (p_next ? %(<li class="next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>) | ||
: %(<li class="next disabled">#{pagy_t('pagy.nav.next')}</li>)) | ||
%(<nav class="pagy-nav-foundation" role="navigation" aria-label="Pagination"><ul class="pagination">#{html}</ul></nav>) | ||
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-foundation" role="navigation" aria-label="Pagination"> | ||
<%# -%> <ul class="pagination"> | ||
<% if pagy.prev -%> <li class="prev"><%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"') %></li> | ||
<% else -%> <li class="prev disabled"><%== pagy_t('pagy.nav.prev') %></li> | ||
<% end -%> | ||
<% 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) %></li> | ||
<% elsif item.is_a?(String) -%> <li class="current"><span class="show-for-sr">You're on page</span><%= item %></li> | ||
<% elsif item == :gap -%> <li class="disabled gap"><%== pagy_t('pagy.nav.gap') %></li> | ||
<% end -%> | ||
<% end -%> | ||
<% if pagy.next -%> <li class="next"><%== link.call(pagy.next, pagy_t('pagy.nav.next'), 'aria-label="next"') %></li> | ||
<% else -%> <li class="next disabled"><%== pagy_t('pagy.nav.next') %></li> | ||
<% 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,36 @@ | ||
-# 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-foundation{"role" => "navigation", "aria-label" => "Pagination"} | ||
|
||
%ul.pagination | ||
|
||
- if pagy.prev | ||
%li.prev!= link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"') | ||
- else | ||
%li.prev.disabled | ||
!= pagy_t('pagy.nav.prev') | ||
|
||
- 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) | ||
|
||
- elsif item.is_a?(String) # current page | ||
%li.current | ||
%span.show-for-sr You're on page | ||
!= item | ||
|
||
- elsif item == :gap # page gap | ||
%li.disabled.gap | ||
!= pagy_t('pagy.nav.gap') | ||
|
||
- if pagy.next | ||
%li.next!= link.call(pagy.next, pagy_t('pagy.nav.next'), 'aria-label="next"') | ||
- else | ||
%li.next.disabled | ||
!= pagy_t('pagy.nav.next') |
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,36 @@ | ||
/ 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-foundation role="navigation" aria-label="Pagination" | ||
|
||
ul.pagination | ||
|
||
- if pagy.prev | ||
li.prev == link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"') | ||
- else | ||
li.prev.disabled | ||
== pagy_t('pagy.nav.prev') | ||
|
||
- 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) | ||
|
||
- elsif item.is_a?(String) # current page | ||
li.current | ||
span.show-for-sr You're on page | ||
= item | ||
|
||
- elsif item == :gap # page gap | ||
li.disabled.gap | ||
== pagy_t('pagy.nav.gap') | ||
|
||
- if pagy.next | ||
li.next == link.call(pagy.next, pagy_t('pagy.nav.next'), 'aria-label="next"') | ||
- else | ||
li.next.disabled | ||
== pagy_t('pagy.nav.next') |
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
Oops, something went wrong.