paginate_me 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +68 -0
- data/lib/paginate_me/paginate.rb +12 -16
- data/lib/paginate_me/version.rb +1 -1
- data/paginate_me.gemspec +3 -4
- metadata +7 -9
- data/README.textile +0 -49
data/README.markdown
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
<h1>Paginate Me</h1>
|
2
|
+
|
3
|
+
**Adam Rensel's Code**
|
4
|
+
|
5
|
+
<p>Paginate me is a Ruby Gem that adds simple pagination functionality to views.</p>
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
<h2>Usage:</h2>
|
10
|
+
<p>users_controller.rb</p>
|
11
|
+
|
12
|
+
<pre>class UsersController < ApplicationController
|
13
|
+
def index
|
14
|
+
@title = "All Users"
|
15
|
+
|
16
|
+
paginate_me :users
|
17
|
+
end
|
18
|
+
end</pre>
|
19
|
+
|
20
|
+
<p>index.haml</p>
|
21
|
+
|
22
|
+
<pre>= paginate_for :users do |p|
|
23
|
+
= p.link_to_first
|
24
|
+
= p.link_to_next
|
25
|
+
= p.page_out_of_total
|
26
|
+
= p.link_to_previous
|
27
|
+
= p.link_to_last</pre>
|
28
|
+
<p>Results in: </p>
|
29
|
+
<div class="paginate_me users">
|
30
|
+
<a href="/users/page/10" class="first" title="first">First</a>
|
31
|
+
|
32
|
+
<a href="/users/page/10" class="next" title="next">Next</a>
|
33
|
+
|
34
|
+
<span>2 of 10</span>
|
35
|
+
|
36
|
+
<a href="/users/page/10" class="previous" title="previous">Previous</a>
|
37
|
+
|
38
|
+
<a href="/users/page/10" class="last" title="last">Last</a>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<h2>Options for paginate_me(item, options ={})</h2>
|
42
|
+
* :url - The plugin builds it's base path from the item passed in according to standard rails routing resource format. A different base url can be passed in instead. /users/page/:page_number (/users is the base_url)
|
43
|
+
* :per_page - results per page, defaults to 10
|
44
|
+
* :params_var - variable set in routes that will hold the current page number ex: <code>match "/users/page/:page", :to => "users#index"</code> :page is the :params_var
|
45
|
+
|
46
|
+
|
47
|
+
<h2>Options for paginate_for(item, options = {}, &block)</h2>
|
48
|
+
* :class - add classes to div container tag
|
49
|
+
* :slug - slug used for url, defaults to 'page', the controller will use the slug in the 'params' variable by default as well.
|
50
|
+
|
51
|
+
|
52
|
+
<h2>Paginate Links</h2>
|
53
|
+
* link_to_first(options={}) - label for first button, goes to page 1
|
54
|
+
* link_to_next(options={}) - label for next button, increments page by +1
|
55
|
+
* link_to_previous(options={}) - label for previous button subtracts pages by -1
|
56
|
+
* link_to_last(options={}) - goes to the last page available, based on total count
|
57
|
+
<p> **options** </p>
|
58
|
+
* :name - name of link
|
59
|
+
* :class - classes for link pass an array for multiple classes
|
60
|
+
* :title - title for link
|
61
|
+
|
62
|
+
<h2>Information Output</h2>
|
63
|
+
* page_out_of_total - formats pagination info '1 of 10' standard rails 'content_tag' options apply
|
64
|
+
|
65
|
+
<h2>Additional Information</h2>
|
66
|
+
* If multiple pagination is needed on one page, for example at the top and bottom of the list, the block of paginate links only needs to be passed to the first 'paginate_for' The additional 'paginate_for' will use the same block, or new blocks can be passed if a different look is required
|
67
|
+
* Make sure you add the correct routes to your routes.rb. For example if your passing in :users and are using a standard resource routing setup, you will need:<code>match "/users/page/:page", :to => "users#index"</code>
|
68
|
+
|
data/lib/paginate_me/paginate.rb
CHANGED
@@ -4,12 +4,13 @@ module PaginateMe
|
|
4
4
|
model_name = item.to_s
|
5
5
|
model = model_name.singularize.camelize.constantize
|
6
6
|
|
7
|
-
@options =
|
8
|
-
@options[:
|
9
|
-
@options[:
|
7
|
+
@options = options
|
8
|
+
@options[:params_var] ||= :page
|
9
|
+
@options[:base_url] ||= method("#{model_name}_path").call
|
10
|
+
@options[:per_page] ||= 10
|
10
11
|
@options[:page_total] = (model.count / @options[:per_page].to_f).ceil
|
11
|
-
@options[:current_page] = self.params[
|
12
|
-
|
12
|
+
@options[:current_page] = self.params[@options[:params_var]].to_i || 1
|
13
|
+
|
13
14
|
current_page = @options[:current_page]
|
14
15
|
page_total = @options[:page_total]
|
15
16
|
|
@@ -50,43 +51,38 @@ module PaginateMe
|
|
50
51
|
|
51
52
|
def initialize(options)
|
52
53
|
|
53
|
-
@slug = options[:slug]
|
54
|
-
|
54
|
+
@slug = options[:slug] ||= "page"
|
55
55
|
@base_url = options[:base_url]
|
56
56
|
@per_page = options[:per_page]
|
57
57
|
@page_total = options[:page_total]
|
58
58
|
@current_page = options[:current_page]
|
59
59
|
|
60
60
|
@next_page = (@current_page >= @page_total ? @current_page : @current_page + 1).to_s
|
61
|
-
@prev_page = (@current_page <= 1 ? @current_page : @current_page - 1).to_s
|
61
|
+
@prev_page = (@current_page <= 1 ? @current_page : @current_page - 1).to_s
|
62
62
|
end
|
63
63
|
|
64
64
|
def link_to_next(options = {})
|
65
65
|
options[:name] ||= "Next"
|
66
66
|
|
67
|
-
add_to_template paginate_link_to @
|
68
|
-
@current_page < @page_total
|
67
|
+
add_to_template paginate_link_to @next_page, options if @current_page < @page_total
|
69
68
|
end
|
70
69
|
|
71
70
|
def link_to_previous(options = {})
|
72
71
|
options[:name] ||= "Previous"
|
73
72
|
|
74
|
-
add_to_template paginate_link_to @
|
75
|
-
@current_page > 1
|
73
|
+
add_to_template paginate_link_to @prev_page, options if @current_page > 1
|
76
74
|
end
|
77
75
|
|
78
76
|
def link_to_first(options = {})
|
79
77
|
options[:name] ||= "First"
|
80
78
|
|
81
|
-
add_to_template paginate_link_to
|
82
|
-
@current_page < @page_total
|
79
|
+
add_to_template paginate_link_to 1, options if @current_page < @page_total
|
83
80
|
end
|
84
81
|
|
85
82
|
def link_to_last(options = {})
|
86
83
|
options[:name] ||= "Last"
|
87
84
|
|
88
|
-
add_to_template paginate_link_to @page_total, options if
|
89
|
-
@current_page > 1
|
85
|
+
add_to_template paginate_link_to @page_total, options if @current_page > 1
|
90
86
|
end
|
91
87
|
|
92
88
|
def page_out_of_total(options = {})
|
data/lib/paginate_me/version.rb
CHANGED
data/paginate_me.gemspec
CHANGED
@@ -7,10 +7,9 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = PaginateMe::VERSION
|
8
8
|
s.authors = ["Adam Rensel"]
|
9
9
|
s.email = ["adamrensel@gmail.com"]
|
10
|
-
s.homepage = "
|
11
|
-
s.summary = %q{
|
12
|
-
s.description = %q{
|
13
|
-
helper, see the README for more information}
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Something}
|
12
|
+
s.description = %q{Its a thing}
|
14
13
|
|
15
14
|
s.rubyforge_project = "paginate_me"
|
16
15
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paginate_me
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adam Rensel
|
@@ -18,9 +18,7 @@ cert_chain: []
|
|
18
18
|
date: 2011-09-17 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
|
-
description:
|
22
|
-
Pagination gem which works similar to the form_for rails
|
23
|
-
helper, see the README for more information
|
21
|
+
description: Its a thing
|
24
22
|
email:
|
25
23
|
- adamrensel@gmail.com
|
26
24
|
executables: []
|
@@ -32,14 +30,14 @@ extra_rdoc_files: []
|
|
32
30
|
files:
|
33
31
|
- .gitignore
|
34
32
|
- Gemfile
|
35
|
-
- README.
|
33
|
+
- README.markdown
|
36
34
|
- Rakefile
|
37
35
|
- lib/paginate_me.rb
|
38
36
|
- lib/paginate_me/paginate.rb
|
39
37
|
- lib/paginate_me/railtie.rb
|
40
38
|
- lib/paginate_me/version.rb
|
41
39
|
- paginate_me.gemspec
|
42
|
-
homepage:
|
40
|
+
homepage: ""
|
43
41
|
licenses: []
|
44
42
|
|
45
43
|
post_install_message:
|
@@ -71,6 +69,6 @@ rubyforge_project: paginate_me
|
|
71
69
|
rubygems_version: 1.8.10
|
72
70
|
signing_key:
|
73
71
|
specification_version: 3
|
74
|
-
summary:
|
72
|
+
summary: Something
|
75
73
|
test_files: []
|
76
74
|
|
data/README.textile
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
h1. Paginate Me
|
2
|
-
|
3
|
-
*Adam Rensel's Code*
|
4
|
-
|
5
|
-
p. Paginate me is a Ruby Gem that adds simple pagination functionality to views.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
h2. Usage:
|
10
|
-
p. users_controller.rb
|
11
|
-
|
12
|
-
@class UsersController < ApplicationController
|
13
|
-
def index
|
14
|
-
@title = "All Users"
|
15
|
-
|
16
|
-
paginate_me :users
|
17
|
-
end
|
18
|
-
end@
|
19
|
-
|
20
|
-
p. index.haml
|
21
|
-
|
22
|
-
@= paginate_for :users do |p|
|
23
|
-
= p.link_to_first
|
24
|
-
= p.link_to_next
|
25
|
-
= p.page_out_of_total
|
26
|
-
= p.link_to_previous
|
27
|
-
= p.link_to_last@
|
28
|
-
|
29
|
-
h2. Options for paginate_me(item, options ={})
|
30
|
-
* :url - The plugin builds it's base path from the item passed in according to standard rails routing resource format. A different base url can be passed in instead. /users/page/:page_number (/users is the base_url)
|
31
|
-
* :per_page - results per page, defaults to 10
|
32
|
-
|
33
|
-
h2. Options for paginate_for(item, options = {}, &block)
|
34
|
-
* :class - add classes to div container tag
|
35
|
-
* :slug - slug used for url, defaults to 'page'
|
36
|
-
|
37
|
-
h2. Paginate Links
|
38
|
-
* link_to_first(options={}) - label for first button, goes to page 1
|
39
|
-
* link_to_next(options={}) - label for next button, increments page by +1
|
40
|
-
* link_to_previous(options={}) - label for previous button subtracts pages by -1
|
41
|
-
* link_to_last(options={}) - goes to the last page available, based on total count
|
42
|
-
** options
|
43
|
-
*** :name - name of link
|
44
|
-
*** :class - classes for link pass an array for multiple classes
|
45
|
-
*** :title - title for link
|
46
|
-
|
47
|
-
h2. Information Output
|
48
|
-
* page_out_of_total - formats pagination info '1 of 10' standard rails 'content_tag' options apply
|
49
|
-
|