Skip to content

Commit

Permalink
breaking change for compact and responsive extras: renaming of pagy_n…
Browse files Browse the repository at this point in the history
…av_bootstrap_* helpers to pagy_nav_*_bootstrap, consistent with extras structure
  • Loading branch information
ddnexus committed Jun 27, 2018
1 parent 7d1a573 commit ea7c22b
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 44 deletions.
6 changes: 3 additions & 3 deletions docs/extras/compact.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Then use the responsive helper(s) in any view:

```erb
<%== pagy_nav_compact(@pagy) %>
<%== pagy_nav_bootstrap_compact(@pagy) %>
<%== pagy_nav_compact_bootstrap(@pagy) %>
```

## Files
Expand All @@ -36,8 +36,8 @@ This extra adds a couple of nav helpers to the `Pagy::Frontend` module. You can

Renders a compact navigation with a style similar to the `pagy_nav` helper.

It can take an extra `id` argument, which is used to build the `id` attribute of the `nav` tag. Since the internal automatic id assignation is based on the code line where you use the helper, you should pass an explicit id only if you are going to use more than one `pagy_nav_compact` or `pagy_nav_bootstrap_compact` call in the same line for the same page.
It can take an extra `id` argument, which is used to build the `id` attribute of the `nav` tag. Since the internal automatic id assignation is based on the code line where you use the helper, you should pass an explicit id only if you are going to use more than one `pagy_nav_compact` or `pagy_nav_compact_bootstrap` call in the same line for the same page.

### pagy_nav_bootstrap_compact(pagy, ...)
### pagy_nav_compact_bootstrap(pagy, ...)

This method is the same as the `pagy_nav_compact`, but customized for Bootstrap.
10 changes: 5 additions & 5 deletions docs/extras/responsive.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Then use the responsive helper(s) in any view:

```erb
<%== pagy_nav_responsive(@pagy) %>
<%== pagy_nav_bootstrap_responsive(@pagy) %>
<%== pagy_nav_responsive_bootstrap(@pagy) %>
```

## Files
Expand Down Expand Up @@ -57,16 +57,16 @@ The `reponsive` extra adds an instance method to the `Pagy` class and couple of

### responsive

**Notice**: Unless you are going to override a `pagy_nav_responsive` or `pagy_nav_bootstrap_responsive` helper you can ignore this method.
**Notice**: Unless you are going to override a `pagy_nav_responsive` or `pagy_nav_responsive_bootstrap` helper you can ignore this method.

This is a `Pagy` instance method that returns the data structure used by the `pagy_nav_responsive` and `pagy_nav_bootstrap_responsive` helpers in order to build the html and the javascript codes needed to make Pagy responsive to different widths.
This is a `Pagy` instance method that returns the data structure used by the `pagy_nav_responsive` and `pagy_nav_responsive_bootstrap` helpers in order to build the html and the javascript codes needed to make Pagy responsive to different widths.

### pagy_nav_responsive(pagy, ...)

Similar to the `pagy_nav` helper, with added responsiveness.

It can take an extra `id` argument, which is used to build the `id` attribute of the `nav` tag. Since the internal automatic id assignation is based on the code line where you use the helper, you should pass an explicit id if you are going to use more than one `pagy_nav_responsive` or `pagy_nav_bootstrap_responsive` call in the same line for the same page.
It can take an extra `id` argument, which is used to build the `id` attribute of the `nav` tag. Since the internal automatic id assignation is based on the code line where you use the helper, you should pass an explicit id if you are going to use more than one `pagy_nav_responsive` or `pagy_nav_responsive_bootstrap` call in the same line for the same page.

### pagy_nav_bootstrap_responsive(pagy, ...)
### pagy_nav_responsive_bootstrap(pagy, ...)

This method is the same as the `pagy_nav_responsive`, but customized for Bootstrap.
4 changes: 2 additions & 2 deletions docs/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ These helpers take the Pagy object and returns the HTML string with the paginati
| Extra | Helpers |
| ---------------------------------- | ------------------------------------------------------ |
| [bootstrap](extras/bootstrap.md) | `pagy_nav_bootstrap` |
| [responsive](extras/responsive.md) | `pagy_nav_responsive`, `pagy_nav_bootstrap_responsive` |
| [compact](extras/compact.md) | `pagy_nav_compact`, `pagy_nav_bootstrap_compact` |
| [responsive](extras/responsive.md) | `pagy_nav_responsive`, `pagy_nav_responsive_bootstrap` |
| [compact](extras/compact.md) | `pagy_nav_compact`, `pagy_nav_compact_bootstrap` |

Helpers are the preferred choice (over templates) for their performance. If you need to override a `pagy_nav*` helper you can copy and paste it in your helper end edit it there. It is a simple concatenation of strings with a very simple logic.

Expand Down
2 changes: 1 addition & 1 deletion lib/pagy/extras/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def pagy_nav_bootstrap(pagy)
end
html << (p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
: %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li>))
%(<nav class="pagy-nav-boostrap pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></nav>)
%(<nav class="pagy-nav-bootstrap pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></nav>)
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/pagy/extras/compact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def pagy_nav_compact(pagy, id=caller(1,1)[0].hash)

# Compact pagination for bootstrap: it returns the html with the series of links to the pages
# we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
def pagy_nav_bootstrap_compact(pagy, id=caller(1,1)[0].hash)
def pagy_nav_compact_bootstrap(pagy, id=caller(1,1)[0].hash)
html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages

html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-bootstrap-compact pagination" role="navigation" aria-label="pager">)
html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact-bootstrap pagination" role="navigation" aria-label="pager">)
html << link.call(MARKER, '', %(style="display: none;" ))
html << %(<div class="btn-group" role="group">)
html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous" class="prev btn btn-primary"')
Expand Down
8 changes: 4 additions & 4 deletions lib/pagy/extras/responsive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ def pagy_nav_responsive(pagy, id=caller(1,1)[0].hash)

# Responsive pagination for bootstrap: it returns the html with the series of links to the pages
# rendered by the Pagy.responsive javascript
def pagy_nav_bootstrap_responsive(pagy, id=caller(1,1)[0].hash)
def pagy_nav_responsive_bootstrap(pagy, id=caller(1,1)[0].hash)
tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next, pagy.responsive

tags['prev'] = (p_prev ? %(<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
: %(<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev')}</a></li>))
responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
tags[item.to_s] = if item.is_a?(Integer); %(<li class="page-item">#{link.call item}</li>) # page link
elsif item.is_a?(String) ; %(<li class="page-item active">#{link.call item}</li>) # active page
tags[item.to_s] = if item.is_a?(Integer); %(<li class="page-item">#{link.call item}</li>) # page link
elsif item.is_a?(String) ; %(<li class="page-item active">#{link.call item}</li>) # active page
elsif item == :gap ; %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap')}</a></li>) # page gap
end
end
tags['next'] = (p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
: %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li>))
script = %(<script type="application/json" class="pagy-responsive">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
%(<nav id="pagy-nav-#{id}" class="pagy-nav-bootstrap-responsive pagination" role="navigation" aria-label="pager"><ul class="pagination"></ul></nav>#{script})
%(<nav id="pagy-nav-#{id}" class="pagy-nav-responsive-bootstrap pagination" role="navigation" aria-label="pager"><ul class="pagination"></ul></nav>#{script})
end

end
Expand Down
8 changes: 4 additions & 4 deletions test/pagy/extras/bootstrap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_pagy_nav_bootstrap_page_1
pagy, _ = @array.pagy(1)

assert_equal(
'<nav class="pagy-nav-boostrap pagination" role="navigation" aria-label="pager">' \
'<nav class="pagy-nav-bootstrap pagination" role="navigation" aria-label="pager">' \
'<ul class="pagination">' \
'<li class="page-item prev disabled"><a href="#" class="page-link">&lsaquo;&nbsp;Prev</a></li>' \
'<li class="page-item active"><a href="/foo?page=1" class="page-link" >1</a></li>'\
Expand All @@ -36,7 +36,7 @@ def test_pagy_nav_bootstrap_page_3
pagy, _ = @array.pagy(3)

assert_equal(
'<nav class="pagy-nav-boostrap pagination" role="navigation" aria-label="pager">' \
'<nav class="pagy-nav-bootstrap pagination" role="navigation" aria-label="pager">' \
'<ul class="pagination">' \
'<li class="page-item prev"><a href="/foo?page=2" class="page-link" rel="prev" aria-label="previous">&lsaquo;&nbsp;Prev</a></li>' \
'<li class="page-item"><a href="/foo?page=1" class="page-link" >1</a></li>' \
Expand All @@ -57,7 +57,7 @@ def test_pagy_nav_bootstrap_page_6
pagy, _ = @array.pagy(6)

assert_equal(
'<nav class="pagy-nav-boostrap pagination" role="navigation" aria-label="pager">' \
'<nav class="pagy-nav-bootstrap pagination" role="navigation" aria-label="pager">' \
'<ul class="pagination">' \
'<li class="page-item prev"><a href="/foo?page=5" class="page-link" rel="prev" aria-label="previous">&lsaquo;&nbsp;Prev</a></li>' \
'<li class="page-item"><a href="/foo?page=1" class="page-link" >1</a></li>' \
Expand All @@ -78,7 +78,7 @@ def test_pagy_nav_bootstrap_page_10
pagy, _ = @array.pagy(10)

assert_equal(
'<nav class="pagy-nav-boostrap pagination" role="navigation" aria-label="pager">' \
'<nav class="pagy-nav-bootstrap pagination" role="navigation" aria-label="pager">' \
'<ul class="pagination">' \
'<li class="page-item prev"><a href="/foo?page=9" class="page-link" rel="prev" aria-label="previous">&lsaquo;&nbsp;Prev</a></li>' \
'<li class="page-item"><a href="/foo?page=1" class="page-link" >1</a></li>' \
Expand Down
20 changes: 10 additions & 10 deletions test/pagy/extras/compact_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ def test_pagy_nav_compact_page_6

end

describe "#pagy_nav_bootstrap_compact" do
describe "#pagy_nav_compact_bootstrap" do
before do
@array = (1..103).to_a.extend(Pagy::Array::PageMethod)
end

def test_pagy_nav_bootstrap_compact_page_1
def test_pagy_nav_compact_bootstrap_page_1
pagy, _ = @array.pagy(1)
html, id = frontend.pagy_nav_bootstrap_compact(pagy), caller(0,1)[0].hash
html, id = frontend.pagy_nav_compact_bootstrap(pagy), caller(0,1)[0].hash

assert_equal(
%(<nav id="pagy-nav-#{id}" class="pagy-nav-bootstrap-compact pagination" role="navigation" aria-label="pager">) +
%(<nav id="pagy-nav-#{id}" class="pagy-nav-compact-bootstrap pagination" role="navigation" aria-label="pager">) +
%(<a href="/foo?page=#{Pagy::Frontend::MARKER}" style="display: none;" ></a>) +
%(<div class="btn-group" role="group">) +
%(<a class="prev btn btn-primary disabled" href="#">&lsaquo;&nbsp;Prev</a>) +
Expand All @@ -89,12 +89,12 @@ def test_pagy_nav_bootstrap_compact_page_1
)
end

def test_pagy_nav_bootstrap_compact_page_3
def test_pagy_nav_compact_bootstrap_page_3
pagy, _ = @array.pagy(3)
html, id = frontend.pagy_nav_bootstrap_compact(pagy), caller(0,1)[0].hash
html, id = frontend.pagy_nav_compact_bootstrap(pagy), caller(0,1)[0].hash

assert_equal(
%(<nav id="pagy-nav-#{id}" class="pagy-nav-bootstrap-compact pagination" role="navigation" aria-label="pager">) +
%(<nav id="pagy-nav-#{id}" class="pagy-nav-compact-bootstrap pagination" role="navigation" aria-label="pager">) +
%(<a href="/foo?page=#{Pagy::Frontend::MARKER}" style="display: none;" ></a>) +
%(<div class="btn-group" role="group">) +
%(<a href="/foo?page=2" rel="prev" aria-label="previous" class="prev btn btn-primary">&lsaquo;&nbsp;Prev</a>) +
Expand All @@ -111,12 +111,12 @@ def test_pagy_nav_bootstrap_compact_page_3
)
end

def test_pagy_nav_bootstrap_compact_page_6
def test_pagy_nav_compact_bootstrap_page_6
pagy, _ = @array.pagy(6)
html, id = frontend.pagy_nav_bootstrap_compact(pagy), caller(0,1)[0].hash
html, id = frontend.pagy_nav_compact_bootstrap(pagy), caller(0,1)[0].hash

assert_equal(
%(<nav id="pagy-nav-#{id}" class="pagy-nav-bootstrap-compact pagination" role="navigation" aria-label="pager">) +
%(<nav id="pagy-nav-#{id}" class="pagy-nav-compact-bootstrap pagination" role="navigation" aria-label="pager">) +
%(<a href="/foo?page=#{Pagy::Frontend::MARKER}" style="display: none;" ></a>) +
%(<div class="btn-group" role="group">) +
%(<a href="/foo?page=5" rel="prev" aria-label="previous" class="prev btn btn-primary">&lsaquo;&nbsp;Prev</a>) +
Expand Down
Loading

0 comments on commit ea7c22b

Please sign in to comment.