innetra-flow_pagination 1.1
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/MIT-LICENSE +20 -0
- data/Manifest +7 -0
- data/README.rdoc +167 -0
- data/Rakefile +10 -0
- data/flow_pagination.gemspec +31 -0
- data/init.rb +1 -0
- data/lib/flow_pagination.rb +37 -0
- metadata +65 -0
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009 Innetra Consultancy Services, S.C.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
data/README.rdoc
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
= FlowPagination
|
|
2
|
+
|
|
3
|
+
FlowPagination link renderer plugin for Mislav's
|
|
4
|
+
{WillPaginate}[http://github.com/mislav/will_paginate/tree/master]
|
|
5
|
+
plugin (Twitter like pagination).
|
|
6
|
+
|
|
7
|
+
Instead of showing page links, this plugin/gem change the rendering of
|
|
8
|
+
WillPaginate to display, at the bottom of the page's records, the "More" button.
|
|
9
|
+
And when clicked it will add the next set of records (next page) right below
|
|
10
|
+
the previous ones.
|
|
11
|
+
|
|
12
|
+
== Requirements
|
|
13
|
+
|
|
14
|
+
* Mislav's {WillPaginate}[http://github.com/mislav/will_paginate/tree/master]
|
|
15
|
+
plugin/gem.
|
|
16
|
+
|
|
17
|
+
== Installation
|
|
18
|
+
|
|
19
|
+
I've created a category listing (index action) to give a basic example.
|
|
20
|
+
|
|
21
|
+
Configure +WillPaginate+ and +FlowPagination+ gems (config/environment.rb):
|
|
22
|
+
|
|
23
|
+
Rails::Initializer.run do |config|
|
|
24
|
+
[...]
|
|
25
|
+
config.gem 'mislav-will_paginate', :lib => 'will_paginate',
|
|
26
|
+
:source => 'http://gems.github.com'
|
|
27
|
+
|
|
28
|
+
config.gem 'innetra-flow_pagination', :lib => 'flow_pagination',
|
|
29
|
+
:source => 'http://gems.github.com'
|
|
30
|
+
[...]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
To install these gems type the following rake task:
|
|
34
|
+
|
|
35
|
+
rake gems:install
|
|
36
|
+
|
|
37
|
+
=== Install It as a Plugin
|
|
38
|
+
|
|
39
|
+
script/plugin install git://github.com/mislav/will_paginate.git
|
|
40
|
+
script/plugin install git://github.com/innetra/flow_pagination.git
|
|
41
|
+
|
|
42
|
+
== Usage
|
|
43
|
+
|
|
44
|
+
Let's create category listing page as a sample.
|
|
45
|
+
|
|
46
|
+
=== Categories Controller
|
|
47
|
+
|
|
48
|
+
controllers/categories_controller.rb:
|
|
49
|
+
|
|
50
|
+
class CategoriesController < ApplicationController
|
|
51
|
+
def index
|
|
52
|
+
@categories = Category.paginate :page => params[:page], :order => 'name'
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
=== Categories Index View
|
|
57
|
+
|
|
58
|
+
app/views/cateogories/index.html.haml:
|
|
59
|
+
|
|
60
|
+
= javascript_include_tag :all
|
|
61
|
+
%h1 Categories
|
|
62
|
+
%ul#categories= render @categories
|
|
63
|
+
= will_paginate @categories, :renderer => FlowPagination::FlowPaginationRenderer
|
|
64
|
+
|
|
65
|
+
==== Important Note
|
|
66
|
+
|
|
67
|
+
If you're using Prototype (Rails default javascript library) you have to
|
|
68
|
+
surround the +will_paginate+ method with a form. Cause Prototype requires a
|
|
69
|
+
form to submit.
|
|
70
|
+
|
|
71
|
+
Another option is to override +FlowPagination::LinkRenderer.to_html+ method
|
|
72
|
+
so it uses the +ActionView::Helpers::UrlHelper.link_to+ method instead of
|
|
73
|
+
+ActionView::Helpers::PrototypeHelper.submit_to_remote+,
|
|
74
|
+
|
|
75
|
+
=== Category Partial
|
|
76
|
+
|
|
77
|
+
app/views/categories/_category.html.haml:
|
|
78
|
+
|
|
79
|
+
%li{ :id => "category_#{category.id}" }=category.name
|
|
80
|
+
|
|
81
|
+
=== RJS Template
|
|
82
|
+
|
|
83
|
+
app/views/categories/index.js.rjs:
|
|
84
|
+
|
|
85
|
+
page.insert_html :bottom, :categories, :partial => @categories
|
|
86
|
+
page.replace :flow_pagination, will_paginate(@categories)
|
|
87
|
+
|
|
88
|
+
=== Populate Database
|
|
89
|
+
|
|
90
|
+
To test this solution I've created a rake task to populate the database
|
|
91
|
+
(lib/tasks/populate.rake):
|
|
92
|
+
|
|
93
|
+
namespace :db do
|
|
94
|
+
desc 'Erase and fill database'
|
|
95
|
+
task :populate => :environment do
|
|
96
|
+
|
|
97
|
+
require 'populator'
|
|
98
|
+
require 'faker'
|
|
99
|
+
|
|
100
|
+
Category.delete_all
|
|
101
|
+
|
|
102
|
+
Category.populate 100 do |category|
|
|
103
|
+
category.name = Populator.words(1..3).titleize
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
==== Important
|
|
110
|
+
|
|
111
|
+
You'll need Populator and Faker gems to run this rake task.
|
|
112
|
+
|
|
113
|
+
=== Enjoy
|
|
114
|
+
|
|
115
|
+
Run your application, browse your category listing
|
|
116
|
+
(http://localhost:3000/categories). Go to the end of the page and, if you have
|
|
117
|
+
more than 30 categories (or more than the number specified in the +per_page+
|
|
118
|
+
parameter), you should see the "More" button. Click it and the next records will
|
|
119
|
+
be added next to the previous ones.
|
|
120
|
+
|
|
121
|
+
== Changing the Button's Legend
|
|
122
|
+
|
|
123
|
+
+FlowPagination+ supports internationalization (Rails +i18n+), thus you can
|
|
124
|
+
change the label like this:
|
|
125
|
+
|
|
126
|
+
I18n.backend.store_translations :en, 'flow_pagination.button' => { :default => 'Next Records' }
|
|
127
|
+
|
|
128
|
+
Another way to accomplish the same is to add the following in your locales
|
|
129
|
+
(config/locales/en.application.yml):
|
|
130
|
+
|
|
131
|
+
en:
|
|
132
|
+
flow_pagination:
|
|
133
|
+
button: Next Records
|
|
134
|
+
|
|
135
|
+
== Setting FlowPagination as Default LinkRenderer
|
|
136
|
+
|
|
137
|
+
If you wan't to use +FlowPagination::LinkRenderer+ as default, instead of
|
|
138
|
+
specify the +renderer+ parameter each call to +WillPaginate+ helper, you can
|
|
139
|
+
specify it on Application Helper (app/helpers/application_helper.rb):
|
|
140
|
+
|
|
141
|
+
module ApplicationHelper
|
|
142
|
+
WillPaginate::ViewHelpers.pagination_options[:renderer] =
|
|
143
|
+
FlowPagination::LinkRenderer
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
== License
|
|
147
|
+
|
|
148
|
+
Copyright (c) 2008 Innetra Consultancy Services, S.C.
|
|
149
|
+
|
|
150
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
151
|
+
a copy of this software and associated documentation files (the
|
|
152
|
+
"Software"), to deal in the Software without restriction, including
|
|
153
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
154
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
155
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
156
|
+
the following conditions:
|
|
157
|
+
|
|
158
|
+
The above copyright notice and this permission notice shall be
|
|
159
|
+
included in all copies or substantial portions of the Software.
|
|
160
|
+
|
|
161
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
162
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
163
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
164
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
165
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
166
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
167
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'echoe'
|
|
2
|
+
|
|
3
|
+
Echoe.new('flow_pagination', '1.1') do |e|
|
|
4
|
+
e.description = "FlowPagination link renderer plugin for Mislav's WillPaginate plugin (Twitter like pagination)."
|
|
5
|
+
e.url = "http://github.com/innetra/flow_pagination"
|
|
6
|
+
e.author = "Ivan Torres"
|
|
7
|
+
e.email = "mexpolk@gmail.com"
|
|
8
|
+
e.ignore_pattern = ["tmp/*", "script/*"]
|
|
9
|
+
e.development_dependencies = []
|
|
10
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = %q{flow_pagination}
|
|
5
|
+
s.version = "1.1"
|
|
6
|
+
|
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
8
|
+
s.authors = ["Ivan Torres"]
|
|
9
|
+
s.date = %q{2009-05-17}
|
|
10
|
+
s.description = %q{FlowPagination link renderer plugin for Mislav's WillPaginate plugin (Twitter like pagination).}
|
|
11
|
+
s.email = %q{mexpolk@gmail.com}
|
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/flow_pagination.rb"]
|
|
13
|
+
s.files = ["Manifest", "flow_pagination.gemspec", "README.rdoc", "Rakefile", "init.rb", "lib/flow_pagination.rb", "MIT-LICENSE"]
|
|
14
|
+
s.has_rdoc = true
|
|
15
|
+
s.homepage = %q{http://github.com/innetra/flow_pagination}
|
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Flow_pagination", "--main", "README.rdoc"]
|
|
17
|
+
s.require_paths = ["lib"]
|
|
18
|
+
s.rubyforge_project = %q{flow_pagination}
|
|
19
|
+
s.rubygems_version = %q{1.3.2}
|
|
20
|
+
s.summary = %q{FlowPagination link renderer plugin for Mislav's WillPaginate plugin (Twitter like pagination).}
|
|
21
|
+
|
|
22
|
+
if s.respond_to? :specification_version then
|
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
24
|
+
s.specification_version = 3
|
|
25
|
+
|
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
27
|
+
else
|
|
28
|
+
end
|
|
29
|
+
else
|
|
30
|
+
end
|
|
31
|
+
end
|
data/init.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'flow_pagination'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module FlowPagination
|
|
2
|
+
|
|
3
|
+
# FlowPagination renderer for (Mislav) WillPaginate Plugin
|
|
4
|
+
class LinkRenderer < WillPaginate::LinkRenderer
|
|
5
|
+
|
|
6
|
+
# Render flow navigation
|
|
7
|
+
def to_html
|
|
8
|
+
if self.current_page < self.last_page
|
|
9
|
+
@template.content_tag :div, :id => 'flow_pagination' do
|
|
10
|
+
@template.submit_to_remote 'flow_pagination_button',
|
|
11
|
+
@template.t('flow_pagination.button', :default => 'More'),
|
|
12
|
+
:url => { :action => @template.action_name,
|
|
13
|
+
:page => self.next_page }, :method => :get
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
protected
|
|
19
|
+
|
|
20
|
+
# Get current page number
|
|
21
|
+
def current_page
|
|
22
|
+
@collection.current_page
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Get last page number
|
|
26
|
+
def last_page
|
|
27
|
+
@last_page ||= WillPaginate::ViewHelpers.total_pages_for_collection(@collection)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Get next page number
|
|
31
|
+
def next_page
|
|
32
|
+
@collection.next_page
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: innetra-flow_pagination
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: "1.1"
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ivan Torres
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-05-17 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: FlowPagination link renderer plugin for Mislav's WillPaginate plugin (Twitter like pagination).
|
|
17
|
+
email: mexpolk@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- README.rdoc
|
|
24
|
+
- lib/flow_pagination.rb
|
|
25
|
+
files:
|
|
26
|
+
- Manifest
|
|
27
|
+
- flow_pagination.gemspec
|
|
28
|
+
- README.rdoc
|
|
29
|
+
- Rakefile
|
|
30
|
+
- init.rb
|
|
31
|
+
- lib/flow_pagination.rb
|
|
32
|
+
- MIT-LICENSE
|
|
33
|
+
has_rdoc: true
|
|
34
|
+
homepage: http://github.com/innetra/flow_pagination
|
|
35
|
+
post_install_message:
|
|
36
|
+
rdoc_options:
|
|
37
|
+
- --line-numbers
|
|
38
|
+
- --inline-source
|
|
39
|
+
- --title
|
|
40
|
+
- Flow_pagination
|
|
41
|
+
- --main
|
|
42
|
+
- README.rdoc
|
|
43
|
+
require_paths:
|
|
44
|
+
- lib
|
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: "0"
|
|
50
|
+
version:
|
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: "1.2"
|
|
56
|
+
version:
|
|
57
|
+
requirements: []
|
|
58
|
+
|
|
59
|
+
rubyforge_project: flow_pagination
|
|
60
|
+
rubygems_version: 1.2.0
|
|
61
|
+
signing_key:
|
|
62
|
+
specification_version: 3
|
|
63
|
+
summary: FlowPagination link renderer plugin for Mislav's WillPaginate plugin (Twitter like pagination).
|
|
64
|
+
test_files: []
|
|
65
|
+
|