roku_pages 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6e853aef80f1db89df86894812a675ed62ad6b4
4
- data.tar.gz: 8912c58ac9f849c57f108f35ce4bb0f75344daeb
3
+ metadata.gz: 6d213effc36f44a85e7b2c97ca98a7c02418e235
4
+ data.tar.gz: 9bc7819e44721545e083e56e71c7d044b4f306a0
5
5
  SHA512:
6
- metadata.gz: 8cef1b0483e56ab0ef410421d7b86284ee990278e18c730c0a3a7b4c78890fc5a2f43e69ee9626a3cfcbe559d1e503f9d698d4dbc034442009236fa298d8243c
7
- data.tar.gz: 7225ad696acb4cf4a2a562ad4029290f3b5808d05570eac4ac418cc394ffb28340a6f484a9e187c25d682f9e986e3494d547289f45ded606c090d33434d96bd8
6
+ metadata.gz: 1c81ff1be3ebbb7882df73b8284fc3868f92fbd17ae9314ba80038de71b13bbf98a9714fca553f39f1865b0ac7b70cf7d16c05370d862d056429631671699975
7
+ data.tar.gz: b1264e268189fa9a1a4875fce67e525d544b73add8ae40134c2c33c7345af50c148d5eadfd98cd4e31740cdcb88b9f7310f3553c4b58ca4df87c4044b6ea2cd1
@@ -3,9 +3,13 @@ Dumb idea for adding pagination to header.
3
3
  Only page numbers and total, no other.
4
4
 
5
5
  = Install
6
- gem 'roku_pages', '~> 0.0.4'
6
+ gem 'roku_pages', '0.0.7'
7
7
 
8
8
  = Usage
9
+ use <tt>params[:page]</tt> and <tt>params[:per_page]</tt>
10
+
11
+ default <tt>page: 1</tt> and <tt>per_page: 25</tt>
12
+
9
13
  just replace render
10
14
  paginate json: articles
11
15
 
@@ -13,5 +17,18 @@ result
13
17
  Pagination:{"first":1,"prev":1,"current":1,"next":2,"last":4}
14
18
  Total:4
15
19
 
20
+ you can also override by this
21
+ paginate json: articles, page: 2, per_page: 2
22
+
23
+ result
24
+ Pagination:{"first":1,"prev":1,"current":2,"next":2,"last":2}
25
+ Total:4
26
+
27
+ you can use +json+ or +xml+
28
+ paginate json: articles
29
+ or
30
+ paginate xml: articles
31
+ but respond is request format
32
+
16
33
 
17
34
  This project rocks and uses MIT-LICENSE.
@@ -1,8 +1,8 @@
1
1
  module RokuPages
2
2
  module Pagination
3
3
  def paginate(options)
4
- page = options[:page] || params[:page] || 1
5
- per_page = options[:per_page] || params[:per_page] || 25
4
+ page = options[:page] || params[:page] || paginate_page
5
+ per_page = options[:per_page] || params[:per_page] || paginate_per_page
6
6
  if %w(json xml).include?(request.format)
7
7
  respond_format = "#{request.format}".split('/').last.to_sym
8
8
  else
@@ -19,21 +19,41 @@ module RokuPages
19
19
  collection = collection.page(page).per(per_page)
20
20
  options.delete(:xml)
21
21
  options.delete(:json)
22
- p "options: #{options}"
23
22
  options[respond_format] = collection
24
23
 
24
+ pages_key = paginate_hash
25
+
25
26
  pages = {}
26
- pages[:first] = 1
27
- pages[:prev] = collection.current_page - 1 > 1 ? collection.current_page - 1 : 1
28
- pages[:current] = collection.current_page
29
- pages[:next] = collection.current_page + 1 < collection.total_pages ? collection.current_page + 1 : collection.total_pages
30
- pages[:last] = collection.total_pages
27
+ pages[pages_key[:first]] = 1
28
+ pages[pages_key[:prev]] = collection.current_page - 1 > 1 ? collection.current_page - 1 : 1
29
+ pages[pages_key[:current]] = collection.current_page
30
+ pages[pages_key[:next]] = collection.current_page + 1 < collection.total_pages ? collection.current_page + 1 : collection.total_pages
31
+ pages[pages_key[:last]] = collection.total_pages
32
+ pages[pages_key[:total]] = collection.total_count.to_s
31
33
  headers['Pagination'] = pages.to_json
32
- headers['Total'] = collection.total_count.to_s
33
34
  end
34
35
 
35
36
  render options
36
37
  end
38
+
39
+ def paginate_page
40
+ 1
41
+ end
42
+
43
+ def paginate_per_page
44
+ 25
45
+ end
46
+
47
+ def paginate_hash
48
+ {
49
+ first: :first,
50
+ prev: :prev,
51
+ current: :current,
52
+ next: :next,
53
+ last: :last,
54
+ total: :total
55
+ }
56
+ end
37
57
  end
38
58
  end
39
59
 
@@ -43,4 +63,4 @@ module RokuPages
43
63
  ActionController::Base.send :include, RokuPages::Pagination
44
64
  end
45
65
  end
46
- end
66
+ end
@@ -1,3 +1,3 @@
1
1
  module RokuPages
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roku_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - rokugou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-04 00:00:00.000000000 Z
11
+ date: 2014-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails