kaminari 0.9.8 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kaminari might be problematic. Click here for more details.
- data/CHANGELOG +9 -0
- data/README.rdoc +8 -4
- data/VERSION +1 -1
- data/kaminari.gemspec +1 -1
- data/lib/kaminari/helpers.rb +3 -1
- data/lib/kaminari/tags.rb +30 -16
- data/spec/helpers/helpers_spec.rb +8 -2
- metadata +3 -3
data/CHANGELOG
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
== 0.9.9
|
2
|
+
|
3
|
+
* :params option for the helper [yomukaku_memo]
|
4
|
+
You can override each link's url_for option by this option
|
5
|
+
Example:
|
6
|
+
= paginate @users, :params => {:controller => 'users', :action => 'index2'}
|
7
|
+
|
8
|
+
* refactor tags
|
9
|
+
|
1
10
|
== 0.9.8
|
2
11
|
|
3
12
|
* I18n for the partials
|
data/README.rdoc
CHANGED
@@ -12,10 +12,10 @@ Does not globally pollute Array, Hash, Object or AR::Base.
|
|
12
12
|
Just bundle the gem, then your models are ready to be paginated. No configuration. Don't have to define anything in your models or helpers.
|
13
13
|
|
14
14
|
* Scope based simple API
|
15
|
-
Everything is method chainable with less Hasheritis. You know, that's the Rails 3 way.
|
15
|
+
Everything is method chainable with less "Hasheritis". You know, that's the Rails 3 way.
|
16
16
|
No special collection class or something for the paginated values but uses a general AR::Relation instance. So, of course you can chain any other conditions before or after the paginator scope.
|
17
17
|
|
18
|
-
* Engine based customizable helper
|
18
|
+
* Engine based I18n aware customizable helper
|
19
19
|
As the whole pagination helper is basically just a collection of links and non-links, Kaminari renders each of them through its own partial template inside the Engine. So, you can easily modify their behaviour or style or whatever by overriding partial templates.
|
20
20
|
|
21
21
|
* Modern
|
@@ -85,14 +85,18 @@ This would output something like 1 2 3 4 ...(snip)... 17 18 19 20 while having 2
|
|
85
85
|
This would output something like 1 ...(snip)... 18 19 20 while having 20 pages in total.
|
86
86
|
<%= paginate @users, :left => 0, :right => 2 %>
|
87
87
|
|
88
|
+
* extra parameters (:params) for the links
|
89
|
+
This would modify each link's url_option. :controller and :action would be the usual keys.
|
90
|
+
<%= paginate @users, :params => {:controller => 'foo', :action => 'bar'}
|
91
|
+
|
88
92
|
* Ajax links (crazy simple, but works perfectly!)
|
89
93
|
This would add data-remote="true" to all the links inside.
|
90
94
|
<%= paginate @users, :remote => true %>
|
91
95
|
|
92
96
|
=== I18n and labels
|
93
97
|
|
94
|
-
The default labels for 'previous', '...' and 'next' are rendered through I18n API.
|
95
|
-
|
98
|
+
The default labels for 'previous', '...' and 'next' are stored in the I18n yaml inside the engine, and rendered through I18n API. You can switch the label value per I18n.locale for your internationalized application.
|
99
|
+
Keys and the default values are the following. You can override them by adding to a YAML file in your Rails.root/config/locales directory.
|
96
100
|
|
97
101
|
en:
|
98
102
|
views:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.9
|
data/kaminari.gemspec
CHANGED
data/lib/kaminari/helpers.rb
CHANGED
@@ -3,10 +3,11 @@ require File.join(File.dirname(__FILE__), 'tags')
|
|
3
3
|
module Kaminari
|
4
4
|
module Helpers
|
5
5
|
class PaginationRenderer
|
6
|
-
attr_reader :options
|
6
|
+
attr_reader :options, :params
|
7
7
|
|
8
8
|
def initialize(template, options) #:nodoc:
|
9
9
|
@template, @options = template, options
|
10
|
+
@params = options[:params] ? template.params.merge(options.delete :params) : template.params
|
10
11
|
@left, @window, @right = (options[:left] || options[:outer_window] || 1), (options[:window] || options[:inner_window] || 4), (options[:right] || options[:outer_window] || 1)
|
11
12
|
end
|
12
13
|
|
@@ -104,6 +105,7 @@ module Kaminari
|
|
104
105
|
# * <tt>:outer_window</tt> - The "outer window" size (1 by default).
|
105
106
|
# * <tt>:left</tt> - The "left outer window" size (1 by default).
|
106
107
|
# * <tt>:right</tt> - The "right outer window" size (1 by default).
|
108
|
+
# * <tt>:params</tt> - url_for parameters for the links (:controller, :action, etc.)
|
107
109
|
# * <tt>:remote</tt> - Ajax? (false by default)
|
108
110
|
# * <tt>:ANY_OTHER_VALUES</tt> - Any other hash key & values would be directly passed into each tag as :locals value.
|
109
111
|
def paginate(scope, options = {}, &block)
|
data/lib/kaminari/tags.rb
CHANGED
@@ -60,11 +60,24 @@ module Kaminari
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
# A page
|
64
|
+
module Page
|
65
|
+
include Renderable
|
66
|
+
# target page number
|
67
|
+
def page
|
68
|
+
raise 'Override page with the actual page value to be a Page.'
|
69
|
+
end
|
70
|
+
def to_s(locals = {}) #:nodoc:
|
71
|
+
super locals.merge(:page => page)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
63
75
|
# Tag that contains a link
|
64
76
|
module Link
|
65
77
|
include Renderable
|
78
|
+
include Page
|
66
79
|
def url
|
67
|
-
|
80
|
+
page_url_for page
|
68
81
|
end
|
69
82
|
def to_s(locals = {}) #:nodoc:
|
70
83
|
super locals.merge(:url => url)
|
@@ -76,39 +89,43 @@ module Kaminari
|
|
76
89
|
include Renderable
|
77
90
|
end
|
78
91
|
|
79
|
-
#
|
80
|
-
module
|
81
|
-
|
82
|
-
raise 'Override page with the actual page value to be a Page.'
|
83
|
-
end
|
84
|
-
def to_s(locals = {}) #:nodoc:
|
85
|
-
super locals.merge(:page => page)
|
86
|
-
end
|
92
|
+
# The "previous" page of the current page
|
93
|
+
module Prev
|
94
|
+
include Renderable
|
87
95
|
end
|
88
96
|
|
89
97
|
# "Previous" without link
|
90
98
|
class PrevSpan < Tag
|
91
99
|
include NonLink
|
100
|
+
include Prev
|
92
101
|
end
|
93
102
|
|
94
103
|
# "Previous" with link
|
95
104
|
class PrevLink < Tag
|
96
105
|
include Link
|
97
|
-
|
98
|
-
|
106
|
+
include Prev
|
107
|
+
def page #:nodoc:
|
108
|
+
@options[:current_page] - 1
|
99
109
|
end
|
100
110
|
end
|
101
111
|
|
112
|
+
# The "next" page of the current page
|
113
|
+
module Next
|
114
|
+
include Renderable
|
115
|
+
end
|
116
|
+
|
102
117
|
# "Next" without link
|
103
118
|
class NextSpan < Tag
|
104
119
|
include NonLink
|
120
|
+
include Next
|
105
121
|
end
|
106
122
|
|
107
123
|
# "Next" with link
|
108
124
|
class NextLink < Tag
|
109
125
|
include Link
|
110
|
-
|
111
|
-
|
126
|
+
include Next
|
127
|
+
def page #:nodoc:
|
128
|
+
@options[:current_page] + 1
|
112
129
|
end
|
113
130
|
end
|
114
131
|
|
@@ -119,9 +136,6 @@ module Kaminari
|
|
119
136
|
def page #:nodoc:
|
120
137
|
@options[:page]
|
121
138
|
end
|
122
|
-
def url #:nodoc:
|
123
|
-
page_url_for page
|
124
|
-
end
|
125
139
|
end
|
126
140
|
|
127
141
|
# Non-link tag showing the current page number
|
@@ -2,7 +2,7 @@ require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
|
2
2
|
include Kaminari::Helpers
|
3
3
|
|
4
4
|
describe 'Kaminari::Helpers::PaginationRenderer' do
|
5
|
-
let :
|
5
|
+
let :template do
|
6
6
|
stub(r = Object.new) do
|
7
7
|
render.with_any_args
|
8
8
|
params { {} }
|
@@ -10,9 +10,15 @@ describe 'Kaminari::Helpers::PaginationRenderer' do
|
|
10
10
|
end
|
11
11
|
r
|
12
12
|
end
|
13
|
+
|
14
|
+
describe '#params' do
|
15
|
+
subject { PaginationRenderer.new(template, :params => {:controller => 'foo', :action => 'bar'}) }
|
16
|
+
its(:params) { should == {:controller => 'foo', :action => 'bar'} }
|
17
|
+
end
|
18
|
+
|
13
19
|
describe '#tagify_links' do
|
14
20
|
def tags_with(options)
|
15
|
-
PaginationRenderer.new(
|
21
|
+
PaginationRenderer.new(template, options).tagify_links
|
16
22
|
end
|
17
23
|
|
18
24
|
context '1 page in total' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaminari
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 41
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 9
|
10
|
+
version: 0.9.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Akira Matsuda
|