Skip to content

Commit

Permalink
docs fixes and additions (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Feb 24, 2019
1 parent bd88866 commit 4c7b50a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![MIT license](https://img.shields.io/badge/license-MIT-mit.svg?colorA=1f7a1f&colorB=2aa22a)](http://opensource.org/licenses/MIT)
![Commits](https://img.shields.io/github/commit-activity/y/ddnexus/pagy.svg?label=commits&colorA=004d99&colorB=0073e6)
![Downloads](https://img.shields.io/gem/dt/pagy.svg?colorA=004d99&colorB=0073e6)
[![Chat](http://img.shields.io/badge/gitter-ddnexus/pagy-purple.svg?colorA=800080&colorB=b300b3)](https://gitter.im/ruby-pagy/Lobby)
[![Chat](http://img.shields.io/badge/gitter-ruby--pagy-purple.svg?colorA=800080&colorB=b300b3)](https://gitter.im/ruby-pagy/Lobby)

Pagy is the ultimate pagination gem that outperforms the others in each and every benchmark and comparison.

Expand Down Expand Up @@ -189,7 +189,7 @@ Pagy follows the [Semantic Versioning 2.0.0](https://semver.org/). Please, check

Pagy follows the [GitFlow](https://datasift.github.io/gitflow/IntroducingGitFlow.html) branching model with `master` and `dev`.

The `master` branch is the latest rubygem-published release (plus the changes that don't affect the gem behavior, e.g. doc, tests).
The `master` branch is the latest rubygem-published release.

The `dev` branch is the development branch with the new code that will be merged in the next release.

Expand Down
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: API
---
# API

[![Gem Version](https://badge.fury.io/rb/pagy.svg)](https://badge.fury.io/rb/pagy)
[![Gem Version](https://img.shields.io/gem/v/pagy.svg?label=pagy&colorA=99004d&colorB=cc0066)](https://rubygems.org/gems/pagy)

The whole core structure of Pagy is very simple: it is organized around 3 small modules of just ~100 lines of code in total:

Expand Down
41 changes: 39 additions & 2 deletions docs/extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ If you use any of them you should load the [pagy.js](https://github.com/ddnexus/

### In rails apps

Add the assets-path in the `pagy.rb` initializer:
#### With the asset pipeline

If your app uses the sprocket asset-pipeline, add the assets-path in the `pagy.rb` initializer:

```ruby
Rails.application.config.assets.paths << Pagy.root.join('javascripts')
Expand All @@ -71,6 +73,42 @@ Add an event listener for turbolinks:
window.addEventListener("turbolinks:load", Pagy.init);
```

or a generic one if your app doesn't use turbolinks:
```js
window.addEventListener("load", Pagy.init);
```

#### With Webpacker

If your app uses Webpacker, ensure that the webpacker `erb` loader is installed:

```sh
bundle exec rails webpacker:install:erb
```

Then create a `pagy.js.erb` to render the content of `pagy.js` and add the event listener into it:

```
// app/javascript/src/javascripts/pagy.js.erb
<%= Pagy.root.join('javascripts', 'pagy.js').read %>
window.addEventListener("load", Pagy.init)
```
and import it:
```js
// app/javascript/application.js
import '../src/javascripts/pagy.js.erb'
```

**Notice**:

- You may want to use `turbolinks:load` if your app uses turbolinks despite webpacker
- or you may want just `export { Pagy, PagyInit }` from the `pagy.js.erb` file and import and use it somewhere else.
- You may want to expose the `Pagy` and `PagyInit` namespaces, if you need them available elsewhere (e.g. in js.erb templates):
```js
global.Pagy = Pagy
global.PagyInit = PagyInit
```

### In non-rails apps

Ensure the `pagy/extras/javascripts/pagy.js` script gets served with the page and add an event listener like:
Expand All @@ -87,7 +125,6 @@ $( window ).load(function() {
});
```


### Using AJAX with javascript-enabled helpers

If you AJAX-render any of the helpers using javascript mentioned above, you should also execute `Pagy.init(container_element);` in the javascript template. Here is an example for a `pagy_bootstrap_responsive_nav` AJAX-render:
Expand Down
2 changes: 1 addition & 1 deletion docs/extras/elasticsearch_rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extend Pagy::Search

The `Pagy::Search` adds the `pagy_search` class method that you must use in place of the standard `search` method when you want to paginate the search response.

### pagy_search(term, options={})
### pagy_search(query_or_payload, options={})

This method accepts the same arguments of the `search` method and you must use it in its place. This extra uses it in order to capture the arguments, automatically merging the calculated `:from` and `:size` options before passing them to the standard `search` method internally.

Expand Down
2 changes: 1 addition & 1 deletion docs/extras/searchkick.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extend Pagy::Search

The `Pagy::Search` adds the `pagy_search` class method that you must use in place of the standard `search` method when you want to paginate the search response.

### pagy_search(query_or_payload, options={})
### pagy_search(term, options={})

This method accepts the same arguments of the `search` method and you must use it in its place. This extra uses it in order to capture the arguments, automatically merging the calculated `:page` and `:per_page` options before passing them to the standard `search` method internally.

Expand Down
4 changes: 2 additions & 2 deletions lib/config/pagy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
# require 'pagy/extras/countless'
# Pagy::VARS[:cycle] = false # default

# Elasticsearch Rails extra: Paginate `ElasticsearchRails::Results` objects efficiently, avoiding expensive object-wrapping and without overriding.
# Elasticsearch Rails extra: Paginate `ElasticsearchRails::Results` objects
# See https://ddnexus.github.io/pagy/extras/elasticsearch_rails
# require 'pagy/extras/elasticsearch_rails'

# Searchkick extra: Paginate `Searchkick::Results` objects efficiently, avoiding expensive object-wrapping and without overriding.
# Searchkick extra: Paginate `Searchkick::Results` objects
# See https://ddnexus.github.io/pagy/extras/searchkick
# require 'pagy/extras/searchkick'

Expand Down

0 comments on commit 4c7b50a

Please sign in to comment.