Skip to content

Commit

Permalink
deprecated and renamed bootstrap navs in code, tests and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Nov 30, 2018
1 parent 04ec860 commit 35078ab
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 68 deletions.
14 changes: 7 additions & 7 deletions docs/extras/bootstrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Render the navigation links in some view...
with a fast helper:

```erb
<%== pagy_nav_bootstrap(@pagy) %>
<%== pagy_nav_responsive_bootstrap(@pagy) %>
<%== pagy_nav_compact_bootstrap(@pagy) %>
<%== pagy_bootstrap_nav(@pagy) %>
<%== pagy_bootstrap_responsive_nav(@pagy) %>
<%== pagy_bootstrap_compact_nav(@pagy) %>
```

or with a template:
Expand All @@ -30,7 +30,7 @@ or with a template:
<%== render 'pagy/nav_bootstrap', locals: {pagy: @pagy} %>
```

Configure [javascript](../extras.md#javascript) if you use `pagy_nav_responsive_bootstrap` or `pagy_nav_compact_bootstrap`.
Configure [javascript](../extras.md#javascript) if you use `pagy_bootstrap_responsive_nav` or `pagy_bootstrap_compact_nav`.

## Files

Expand All @@ -45,13 +45,13 @@ This extra is composed of 4 files:

This extra adds 3 nav helpers to the `Pagy::Frontend` module. You can customize them by overriding it directly in your own view helper.

### pagy_nav_bootstrap(pagy)
### pagy_bootstrap_nav(pagy)

This method is the same as the `pagy_nav`, but customized for Bootstrap.

The `nav_bootstrap.*` templates produce the same output, and can be used as an easier (but slower) starting point to override it.

### pagy_nav_compact_bootstrap(pagy, ...)
### pagy_bootstrap_compact_nav(pagy, ...)

This method is the same as the `pagy_nav_compact`, but customized for the Bootstrap framework.

Expand All @@ -61,7 +61,7 @@ Here is an example:

See more details in the [compact navs](navs.md#compact-navs) documentation.

### pagy_nav_responsive_bootstrap(pagy, ...)
### pagy_bootstrap_responsive_nav(pagy, ...)

This method is the same as the `pagy_nav_responsive`, but customized for the Bootstrap framework.

Expand Down
4 changes: 2 additions & 2 deletions docs/extras/navs.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Use the responsive helper(s) in any view:
Other extras provide also the following framework-styled helpers:

```erb
<%== pagy_nav_compact_bootstrap(@pagy) %>
<%== pagy_bootstrap_compact_nav(@pagy) %>
<%== pagy_nav_compact_bulma(@pagy) %>
<%== pagy_nav_compact_foundation(@pagy) %>
<%== pagy_nav_compact_materialize(@pagy) %>
Expand Down Expand Up @@ -79,7 +79,7 @@ Use the responsive helper(s) in any view:
Other extras provide also the following framework-styled helpers:

```erb
<%== pagy_nav_responsive_bootstrap(@pagy) %>
<%== pagy_bootstrap_responsive_nav(@pagy) %>
<%== pagy_nav_responsive_bulma(@pagy) %>
<%== pagy_nav_responsive_foundation(@pagy) %>
<%== pagy_nav_responsive_materialize(@pagy) %>
Expand Down
4 changes: 2 additions & 2 deletions docs/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ These helpers take the Pagy object and return the HTML string with the paginatio

| Extra | Helpers |
| ------------------------------------ | ----------------------------------------------------------------------------------------- |
| [bootstrap](extras/bootstrap.md) | `pagy_nav_bootstrap`, `pagy_nav_responsive_bootstrap`, `pagy_nav_compact_bootstrap` |
| [bootstrap](extras/bootstrap.md) | `pagy_bootstrap_nav`, `pagy_bootstrap_responsive_nav`, `pagy_bootstrap_compact_nav` |
| [bulma](extras/bulma.md) | `pagy_nav_bulma`, `pagy_nav_responsive_bulma`, `pagy_nav_compact_bulma` |
| [foundation](extras/foundation.md) | `pagy_nav_foundation`, `pagy_nav_responsive_foundation`, `pagy_nav_compact_foundation` |
| [materialize](extras/materialize.md) | `pagy_nav_materialize`, `pagy_nav_responsive_materialize`, `pagy_nav_compact_materialize` |
Expand All @@ -328,7 +328,7 @@ By default Pagy generates all the page links including the `page` param. If you

The `pagy_nav*` helpers are optimized for speed, and they are really fast. On the other hand editing a template might be easier when you have to customize the rendering, however every template system adds some inevitable overhead and it will be about 40-80% slower than using the related helper. That will still be dozens of times faster than the other gems, but... you should choose wisely.

Pagy provides the replacement templates for the `pagy_nav`, `pagy_nav_bootstrap`, `pagy_nav_bulma` and the `pagy_nav_foundation` helpers (available with the relative extras) in 3 flavors: `erb`, `haml` and `slim`.
Pagy provides the replacement templates for the `pagy_nav`, `pagy_bootstrap_nav`, `pagy_nav_bulma` and the `pagy_nav_foundation` helpers (available with the relative extras) in 3 flavors: `erb`, `haml` and `slim`.

They produce exactly the same output of the helpers, but since they are slower, using them wouldn't make any sense unless you need to change something. In that case customize a copy in your app, then use it as any other template: just remember to pass the `:pagy` local set to the `@pagy` object. Here are the links to the sources to copy:

Expand Down
2 changes: 1 addition & 1 deletion docs/migration-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Please take a look at the topics in the [how-to](how-to.md) documentation: that

### CSSs

If the app uses the bootstrap pagination, the same CSSs should work seamlessly with `pagy_nav_bootstrap` or with any of the bootstrap templates. If the app doesn't use bootstrap, you may need to rename some rule in your CSSs.
If the app uses the bootstrap pagination, the same CSSs should work seamlessly with `pagy_bootstrap_nav` or with any of the bootstrap templates. If the app doesn't use bootstrap, you may need to rename some rule in your CSSs.

### I18n

Expand Down
15 changes: 9 additions & 6 deletions lib/pagy/extras/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Pagy
module Frontend

# Pagination for bootstrap: it returns the html with the series of links to the pages
def pagy_nav_bootstrap(pagy)
def pagy_bootstrap_nav(pagy)
html, link, p_prev, p_next = +'', pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next

html << (p_prev ? %(<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
Expand All @@ -20,15 +20,16 @@ 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-bootstrap pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></nav>)
%(<nav class="pagy-nav-bootstrap pagy-bootstrap-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></nav>)
end
Pagy.deprecate self, :pagy_nav_bootstrap, :pagy_bootstrap_nav

# 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_compact_bootstrap(pagy, id=caller(1,1)[0].hash)
def pagy_bootstrap_compact_nav(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-compact-bootstrap pagination" role="navigation" aria-label="pager">)
html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact-bootstrap pagy-bootstrap-compact-nav pagination" role="navigation" aria-label="pager">)
html << link.call(MARKER, '', %(style="display: none;" ))
(html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
html << %(<div class="btn-group" role="group">)
Expand All @@ -40,10 +41,11 @@ def pagy_nav_compact_bootstrap(pagy, id=caller(1,1)[0].hash)
: %(<a class="next btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
html << %(</div></nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
end
Pagy.deprecate self, :pagy_nav_compact_bootstrap, :pagy_bootstrap_compact_nav

# 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_responsive_bootstrap(pagy, id=caller(1,1)[0].hash)
def pagy_bootstrap_responsive_nav(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['before'] = +'<ul class="pagination">'
Expand All @@ -59,8 +61,9 @@ def pagy_nav_responsive_bootstrap(pagy, id=caller(1,1)[0].hash)
: %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li>))
tags['after'] << '</ul>'
script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
%(<nav id="pagy-nav-#{id}" class="pagy-nav-responsive-bootstrap pagination" role="navigation" aria-label="pager"></nav>#{script})
%(<nav id="pagy-nav-#{id}" class="pagy-nav-responsive-bootstrap pagy-bootstrap-responsive-nav pagination" role="navigation" aria-label="pager"></nav>#{script})
end
Pagy.deprecate self, :pagy_nav_responsive_bootstrap, :pagy_bootstrap_responsive_nav

end
end
Loading

0 comments on commit 35078ab

Please sign in to comment.