paginate_me 0.0.1 → 0.0.2
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.
- data/README.textile +49 -0
- data/lib/paginate_me/paginate.rb +38 -20
- data/lib/paginate_me/version.rb +1 -1
- data/paginate_me.gemspec +4 -3
- metadata +10 -7
data/README.textile
ADDED
@@ -0,0 +1,49 @@
|
|
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
|
+
|
data/lib/paginate_me/paginate.rb
CHANGED
@@ -9,7 +9,7 @@ module PaginateMe
|
|
9
9
|
@options[:per_page] = options[:per_page] || 10
|
10
10
|
@options[:page_total] = (model.count / @options[:per_page].to_f).ceil
|
11
11
|
@options[:current_page] = self.params['page'].to_i || options[:page].to_i || 1
|
12
|
-
|
12
|
+
|
13
13
|
current_page = @options[:current_page]
|
14
14
|
page_total = @options[:page_total]
|
15
15
|
|
@@ -26,15 +26,22 @@ module PaginateMe
|
|
26
26
|
|
27
27
|
module PMView
|
28
28
|
def paginate_for(item,options = {},&block)
|
29
|
+
|
30
|
+
@page_block = block || @page_block
|
31
|
+
raise ArgumentError, "Missing Block" if @page_block.nil?
|
32
|
+
|
29
33
|
model_name = item.to_s
|
30
34
|
|
31
35
|
options = options.merge @options
|
32
36
|
|
37
|
+
paginate_classes = options[:class] || model_name
|
38
|
+
paginate_classes = paginate_classes.join " " if paginate_classes.is_a? Array
|
39
|
+
|
33
40
|
paginate_builder = PaginateMeBuilder.new(options)
|
34
41
|
|
35
|
-
content = capture(paginate_builder
|
42
|
+
content = capture(paginate_builder,&@page_block)
|
36
43
|
|
37
|
-
content_tag(:div,content, :class => "paginate_me #{
|
44
|
+
content_tag(:div,content, :class => "paginate_me #{paginate_classes}")
|
38
45
|
end
|
39
46
|
|
40
47
|
end
|
@@ -43,12 +50,7 @@ module PaginateMe
|
|
43
50
|
|
44
51
|
def initialize(options)
|
45
52
|
|
46
|
-
@
|
47
|
-
|
48
|
-
@next_label = options[:next_label] || "Next"
|
49
|
-
@previous_label = options[:previous_label] || "Previous"
|
50
|
-
|
51
|
-
@last_label = options[:last_label] || "Last"
|
53
|
+
@slug = options[:slug] || "page"
|
52
54
|
|
53
55
|
@base_url = options[:base_url]
|
54
56
|
@per_page = options[:per_page]
|
@@ -59,35 +61,51 @@ module PaginateMe
|
|
59
61
|
@prev_page = (@current_page <= 1 ? @current_page : @current_page - 1).to_s
|
60
62
|
end
|
61
63
|
|
62
|
-
def link_to_next
|
63
|
-
|
64
|
+
def link_to_next(options = {})
|
65
|
+
options[:name] ||= "Next"
|
66
|
+
|
67
|
+
add_to_template paginate_link_to @page_total, options if
|
64
68
|
@current_page < @page_total
|
65
69
|
end
|
66
70
|
|
67
|
-
def link_to_previous
|
68
|
-
|
71
|
+
def link_to_previous(options = {})
|
72
|
+
options[:name] ||= "Previous"
|
73
|
+
|
74
|
+
add_to_template paginate_link_to @page_total, options if
|
69
75
|
@current_page > 1
|
70
76
|
end
|
71
77
|
|
72
|
-
def link_to_first
|
73
|
-
|
78
|
+
def link_to_first(options = {})
|
79
|
+
options[:name] ||= "First"
|
80
|
+
|
81
|
+
add_to_template paginate_link_to @page_total, options if
|
74
82
|
@current_page < @page_total
|
75
83
|
end
|
76
84
|
|
77
|
-
def link_to_last
|
78
|
-
|
85
|
+
def link_to_last(options = {})
|
86
|
+
options[:name] ||= "Last"
|
87
|
+
|
88
|
+
add_to_template paginate_link_to @page_total, options if
|
79
89
|
@current_page > 1
|
80
90
|
end
|
81
91
|
|
82
|
-
def page_out_of_total
|
83
|
-
|
92
|
+
def page_out_of_total(options = {})
|
93
|
+
content = "#{@current_page} of #{@page_total}"
|
94
|
+
add_to_template content_tag(:span,content, options)
|
84
95
|
end
|
85
96
|
|
86
97
|
private
|
98
|
+
def paginate_link_to(page, args)
|
99
|
+
name = args[:name]
|
100
|
+
args[:class] ||= name.downcase
|
101
|
+
args[:title] ||= name.downcase
|
102
|
+
args.delete :name
|
103
|
+
link_to(name, @base_url + "/#{@slug}/#{page}" , args)
|
104
|
+
end
|
105
|
+
|
87
106
|
def add_to_template(string)
|
88
107
|
template = "\n\t" + string
|
89
108
|
template.html_safe
|
90
|
-
string
|
91
109
|
end
|
92
110
|
end
|
93
111
|
end
|
data/lib/paginate_me/version.rb
CHANGED
data/paginate_me.gemspec
CHANGED
@@ -7,9 +7,10 @@ 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{
|
10
|
+
s.homepage = "https://github.com/renz45/paginate_me"
|
11
|
+
s.summary = %q{Pagination gem for rails 3.1}
|
12
|
+
s.description = %q{Pagination gem which works similar to the form_for rails
|
13
|
+
helper, see the README for more information}
|
13
14
|
|
14
15
|
s.rubyforge_project = "paginate_me"
|
15
16
|
|
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: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adam Rensel
|
@@ -15,10 +15,12 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-17 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
|
-
description:
|
21
|
+
description: |-
|
22
|
+
Pagination gem which works similar to the form_for rails
|
23
|
+
helper, see the README for more information
|
22
24
|
email:
|
23
25
|
- adamrensel@gmail.com
|
24
26
|
executables: []
|
@@ -30,13 +32,14 @@ extra_rdoc_files: []
|
|
30
32
|
files:
|
31
33
|
- .gitignore
|
32
34
|
- Gemfile
|
35
|
+
- README.textile
|
33
36
|
- Rakefile
|
34
37
|
- lib/paginate_me.rb
|
35
38
|
- lib/paginate_me/paginate.rb
|
36
39
|
- lib/paginate_me/railtie.rb
|
37
40
|
- lib/paginate_me/version.rb
|
38
41
|
- paginate_me.gemspec
|
39
|
-
homepage:
|
42
|
+
homepage: https://github.com/renz45/paginate_me
|
40
43
|
licenses: []
|
41
44
|
|
42
45
|
post_install_message:
|
@@ -68,6 +71,6 @@ rubyforge_project: paginate_me
|
|
68
71
|
rubygems_version: 1.8.10
|
69
72
|
signing_key:
|
70
73
|
specification_version: 3
|
71
|
-
summary:
|
74
|
+
summary: Pagination gem for rails 3.1
|
72
75
|
test_files: []
|
73
76
|
|