actionpager 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.ja.md +72 -0
- data/README.md +42 -2
- data/lib/action_pager/pager.rb +44 -3
- data/lib/action_pager/pagination.rb +14 -0
- data/lib/action_pager/version.rb +1 -1
- data/lib/actionpager.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 876f031e85f180e04e799d237f79330a3cc0eb31a7ffde45778a46c2f1077128
|
4
|
+
data.tar.gz: 454bc22c406a1e108feb8b3792e187f8a6d72c25d417d7c103a5323b88a8b6f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f216700001f0bd47fd43101bca418ab239407d0805159973abe37516d2d315aea19eb53948bc9a71486ed25fb31c9ac2449af5e199fccf7684e324a958611f0
|
7
|
+
data.tar.gz: 8b60339780300597182e3b8d041315ed8e05d57d3098d220ec5949fb1be3b0defa6167402ab404eb1b930c92fa48195b8fa503264ca5f7640a8ee426cdd00394
|
data/Gemfile.lock
CHANGED
data/README.ja.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Action Pager
|
2
|
+
|
3
|
+
コレクション(Array, ActiveRecord::Relationなど)で使用できるシンプルで軽量なページネーターです。
|
4
|
+
|
5
|
+
## 特徴
|
6
|
+
|
7
|
+
- シンプルな`pager`オブジェクトがページネーションで使用されます。
|
8
|
+
- 元のコレクションを汚染しません。
|
9
|
+
- 他のGem (Kaminari, Will Paginateなど)に比べるとメモリ消費が非常に少ないです。
|
10
|
+
- カスタマイズが簡単です。
|
11
|
+
- ページネーターのビューとヘルパのファイルがアプリ内に生成されます。
|
12
|
+
- 用途に応じてカスタマイズできます。
|
13
|
+
|
14
|
+
## インストール
|
15
|
+
|
16
|
+
アプリケーションのGemfile以下の行を追加します。
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem "actionpager"
|
20
|
+
```
|
21
|
+
|
22
|
+
以下を実行します。
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
または、以下のようにインストールします。
|
27
|
+
|
28
|
+
$ gem install actionpager
|
29
|
+
|
30
|
+
Railsで使用するには以下のコマンドを実行します
|
31
|
+
|
32
|
+
$ rails g action_pager:install
|
33
|
+
|
34
|
+
2つのファイルが生成され、カスタマイズすることができます。
|
35
|
+
|
36
|
+
- `app/helpers/action_pager/pagination_helper.rb`
|
37
|
+
- `app/views/action_pager/_pager.html.erb`
|
38
|
+
|
39
|
+
## 使い方
|
40
|
+
|
41
|
+
シンプルな配列で使う場合
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
collection = (1..128).to_a
|
45
|
+
pager = ActionPager::Pager.new(collection, page: 3, per: 10)
|
46
|
+
|
47
|
+
pager.current_collection # => [21, ..., 30]
|
48
|
+
```
|
49
|
+
|
50
|
+
ActiveRecordのコレクションで使う場合
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
resources = Book.recent_published
|
54
|
+
@pager = ActionPager::Pager.new(resources, page: 2, per: 25)
|
55
|
+
@books = pager.current_collection
|
56
|
+
```
|
57
|
+
|
58
|
+
Railsのビューでページャーを表示するには、以下のようにコードを記述します。
|
59
|
+
|
60
|
+
```erb
|
61
|
+
<%= render_pager @pager %>
|
62
|
+
```
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
69
|
+
|
70
|
+
## Code of Conduct
|
71
|
+
|
72
|
+
Everyone interacting in the Actionpager project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/actionpager/blob/master/CODE_OF_CONDUCT.md).
|
data/README.md
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
# Action Pager
|
2
2
|
|
3
|
-
Simple and
|
3
|
+
Simple, lightweight and easy to customize paginator for collections (Array, ActiveRecord::Relation etc.)
|
4
|
+
|
5
|
+
# Features
|
6
|
+
|
7
|
+
- A simple `pager` object is used for pagination.
|
8
|
+
- It does not pollute the original collection.
|
9
|
+
- Consumes less memory than other gems (i.e. Kaminari, Will Paginate etc.).
|
10
|
+
- Easy to customize.
|
11
|
+
- Paginator view and helper files are generated in your app.
|
12
|
+
- You can customize for your own purpose.
|
4
13
|
|
5
14
|
## Installation
|
6
15
|
|
@@ -18,9 +27,40 @@ Or install it yourself as:
|
|
18
27
|
|
19
28
|
$ gem install actionpager
|
20
29
|
|
30
|
+
Use with Rails
|
31
|
+
|
32
|
+
$ rails g action_pager:install
|
33
|
+
|
34
|
+
It generates two files and you can customize.
|
35
|
+
|
36
|
+
- `app/helpers/action_pager/pagination_helper.rb`
|
37
|
+
- `app/views/action_pager/_pager.html.erb`
|
38
|
+
|
21
39
|
## Usage
|
22
40
|
|
23
|
-
|
41
|
+
Use with a simple array:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
collection = (1..128).to_a
|
45
|
+
pager = ActionPager::Pager.new(collection, page: 3, per: 10)
|
46
|
+
|
47
|
+
pager.current_collection # => [21, ..., 30]
|
48
|
+
```
|
49
|
+
|
50
|
+
Use with an ActiveRecord collection
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
resources = Book.recent_published
|
54
|
+
@pager = ActionPager::Pager.new(resources, page: 2, per: 25)
|
55
|
+
@books = pager.current_collection
|
56
|
+
```
|
57
|
+
|
58
|
+
To show the pager in your Rails app's view, add code like below:
|
59
|
+
|
60
|
+
```erb
|
61
|
+
<%= render_pager @pager %>
|
62
|
+
```
|
63
|
+
|
24
64
|
|
25
65
|
## License
|
26
66
|
|
data/lib/action_pager/pager.rb
CHANGED
@@ -20,7 +20,8 @@ module ActionPager
|
|
20
20
|
current_collection
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def collection_at(page)
|
24
|
+
offset = offset_at(page)
|
24
25
|
if collection.is_a?(Array)
|
25
26
|
collection.drop(offset).first(per_page)
|
26
27
|
else # for ActiveRecord::Relation and other OR mapper collections
|
@@ -28,8 +29,48 @@ module ActionPager
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
|
-
def
|
32
|
-
(current_page
|
32
|
+
def current_collection
|
33
|
+
collection_at(current_page)
|
34
|
+
end
|
35
|
+
|
36
|
+
def first_collection
|
37
|
+
collection_at(first_page)
|
38
|
+
end
|
39
|
+
|
40
|
+
def last_collection
|
41
|
+
collection_at(last_page)
|
42
|
+
end
|
43
|
+
|
44
|
+
def prev_collection
|
45
|
+
collection_at(prev_page)
|
46
|
+
end
|
47
|
+
|
48
|
+
def next_collection
|
49
|
+
collection_at(next_page)
|
50
|
+
end
|
51
|
+
|
52
|
+
def offset_at(page)
|
53
|
+
(page - 1) * per_page
|
54
|
+
end
|
55
|
+
|
56
|
+
def current_offset
|
57
|
+
offset_at(current_page)
|
58
|
+
end
|
59
|
+
|
60
|
+
def first_offset
|
61
|
+
offset_at(first_page)
|
62
|
+
end
|
63
|
+
|
64
|
+
def last_offset
|
65
|
+
offset_at(last_page)
|
66
|
+
end
|
67
|
+
|
68
|
+
def prev_offset
|
69
|
+
offset_at(prev_page)
|
70
|
+
end
|
71
|
+
|
72
|
+
def next_offset
|
73
|
+
offset_at(next_page)
|
33
74
|
end
|
34
75
|
|
35
76
|
def collection_count
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ActionPager
|
2
|
+
module Pagination
|
3
|
+
DEFAULTS = { page: 1, per: 5 }.freeze
|
4
|
+
|
5
|
+
def pager_for(collection, options={})
|
6
|
+
opts = DEFAULTS.merge(options.reject { |_k, v| v.to_i.zero? })
|
7
|
+
ActionPager::Pager.new(
|
8
|
+
collection,
|
9
|
+
page: opts[:page].to_i,
|
10
|
+
per: opts[:per].to_i
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/action_pager/version.rb
CHANGED
data/lib/actionpager.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionpager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Hashimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -65,10 +65,12 @@ files:
|
|
65
65
|
- Gemfile
|
66
66
|
- Gemfile.lock
|
67
67
|
- LICENSE
|
68
|
+
- README.ja.md
|
68
69
|
- README.md
|
69
70
|
- Rakefile
|
70
71
|
- actionpager.gemspec
|
71
72
|
- lib/action_pager/pager.rb
|
73
|
+
- lib/action_pager/pagination.rb
|
72
74
|
- lib/action_pager/version.rb
|
73
75
|
- lib/actionpager.rb
|
74
76
|
- lib/generators/action_pager/install_generator.rb
|