alphabetical_paginate 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # AlphabeticalPaginate
2
2
 
3
- A lightweight and highly customizable pagination gem for Ruby on Rails that generates alphabetic pagination categories from collection arrays. It allows you to select the field you want to paginate on.
3
+ A lightweight and highly customizable pagination gem for Ruby on Rails that generates alphabetic pagination categories from Collections or Arrays. It allows you to select the field you want to paginate on.
4
4
 
5
5
  By default, it works with [Bootstrap Pagination](http://twitter.github.io/bootstrap/components.html#pagination) CSS and it is also fully compatible with the [will_paginate](https://github.com/mislav/will_paginate) in case you want to use both.
6
6
 
7
- AlphabeticalPaginate incorporates efficient partial page rerendering techniques and loading animations.
7
+ AlphabeticalPaginate incorporates efficient javascript partial page rerendering techniques and loading animations but also is non-obtrusive and falls back to standard href links.
8
+
9
+ It has two modes - if you're working with MySQL, it allows for low level database regex queries. Otherwise, it uses a buffered search to build an array. You should be able to easily modify the gem to work with other SQL databases (please make a pull-request if you do!).
8
10
 
9
11
  Some code was inspired by [will_paginate](https://github.com/mislav/will_paginate).
10
12
 
@@ -28,26 +30,33 @@ You simply need to call alpha_paginate on the desired table (i.e. `User.all.alph
28
30
 
29
31
  Also, it takes a block in which you can specify the field you wish to paginate by (it can even be in another table). It returns the paginated subset of the collection, sorted by the pagination field. The method returns two values (the paginated array subsection, and an options hash), both of which must be stored as class variables.
30
32
 
33
+ It has a :db_mode parameter which tells the gem to perform low level SQL queries, which are both faster, and take up less memory. This is only supported for MySQL databases at this point.
34
+
31
35
  *An example of its use is as such:*
36
+ #### If you are using MySQL / MySQL2
32
37
  ```ruby
33
38
  #app/controllers/users_controllers.rb
34
39
  class UsersController < ApplicationController
35
40
 
36
41
  def index
37
- @users, @alphaParams = User.all.alpha_paginate(params[:letter]){|user| user.name}
42
+ @users, @alphaParams = User.all.alpha_paginate(params[:letter], {db_mode: true, db_field: "name"})
38
43
  end
39
44
 
40
45
  ...
41
46
  end
42
47
  ```
43
48
 
44
- You may want to sort by the same field that you paginated by (cannot be done in gem due to technical limitaitons).
45
-
49
+ #### If you are not using MySQL
46
50
  ```ruby
51
+ #app/controllers/users_controllers.rb
52
+ class UsersController < ApplicationController
53
+
47
54
  def index
48
55
  @users, @alphaParams = User.all.alpha_paginate(params[:letter]){|user| user.name}
49
- @users.sort_by_name!
50
56
  end
57
+
58
+ ...
59
+ end
51
60
  ```
52
61
 
53
62
  ### View
@@ -95,10 +104,11 @@ Key | Value | Default |Description
95
104
  `:numbers` | `Boolean` | `true` | Whether you want numbers to be included in the pagination at all, either collapsed, or expanded (depending on `:enumerate`).
96
105
  `:others` | `Boolean` | `true` | Whether you want all other characters (non alphanumeric) to be included in the pagination at all.
97
106
  `:pagination_class` | `String` | `"pagination-centered"` | All the classes you would like to add to the rendered pagination selector div (for CSS purposes).
107
+ `:js` | `Boolean` | `"true"` | If you want the javascript with page-rerendering to be enabled.
98
108
 
99
109
  ## Advanced Pagination
100
110
 
101
- You can select a complex field to paginate by. Be careful, as this may be slow in large data sets.
111
+ You can select a complex field to paginate by. Be careful, as this may be slow in large data sets. This only works if db_mode is disabled.
102
112
 
103
113
  For instance, the following example paginates posts by the author's group's name (jumping across two tables).
104
114
  It still returns the Post objects despite whatever field you use to paginate / sort it by (It still auto-sorts by the pagination field).
@@ -117,6 +127,11 @@ class UsersController < ApplicationController
117
127
  end
118
128
  ```
119
129
 
130
+ Also you can paginate by any array generally, it doesn't have to be a collection.
131
+ ```ruby
132
+ @friends, @params = friends.alpha_paginate(params[:letter]){|x| x}
133
+ ```
134
+
120
135
  ## Rails 3.0 and Lower
121
136
 
122
137
  The gem makes use of the Asset Pipeline, introduced in Rails 3.1. It still works with lower versions of Rails, however, you need to copy the assets over manually.
@@ -124,6 +139,13 @@ The gem makes use of the Asset Pipeline, introduced in Rails 3.1. It still works
124
139
  Copy the contents of `vendor/assets/javascripts` of this repo into the `public/javascripts` of your app
125
140
  and also copy the contents of `vendor/assets/images` of this repo into the `public/images` of your app.
126
141
 
142
+ Also, there is one line in vendor/assets/javascripts that needs to be changed for Rails 3.0 support. That is, renaming the image path:
143
+ ```javascript
144
+ var img = "<img src='/assets/aloader.gif' class='loading'/>";
145
+ // RAILS 3.0 USERS -> Please delete the above line and uncomment the bottom line
146
+ //var img = "<img src='/images/aloader.gif' class='loading'/>";
147
+ ```
148
+
127
149
  # Support
128
150
 
129
151
  Please feel free to reach out and contact if you find the gem useful at all! Also, feel free to report / fix any bugs or add features.
@@ -1,3 +1,3 @@
1
1
  module AlphabeticalPaginate
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,9 +1,10 @@
1
1
  module AlphabeticalPaginate
2
2
  module ViewHelpers
3
3
  def alphabetical_paginate params
4
-
5
- output = javascript_include_tag 'alphabetical_paginate'
4
+ output = ""
6
5
  links = ""
6
+
7
+ output += javascript_include_tag 'alphabetical_paginate' if params[:js]
7
8
 
8
9
  if params[:paginate_all]
9
10
  range = ('a'..'z').to_a
@@ -21,7 +22,7 @@ module AlphabeticalPaginate
21
22
  elsif params[:db_mode] or params[:availableLetters].include? l
22
23
  links += '<li><a href="?letter=' + l + '" data-letter="' + l + '">' + l + "</a></li>"
23
24
  else
24
- links += '<li class="disabled"><a href="?letter="' + l + ' data-letter="' + l + '">' + l + "</a></li>"
25
+ links += '<li class="disabled"><a href="?letter=' + l + '" data-letter="' + l + '">' + l + "</a></li>"
25
26
  end
26
27
  end
27
28
  else
@@ -32,7 +33,7 @@ module AlphabeticalPaginate
32
33
 
33
34
  params[:availableLetters].each do |l|
34
35
  if l == params[:currentField]
35
- links += '<li class="active"><a href="?letter=" data-letter="' + l + '">' + l + "</a></li>"
36
+ links += '<li class="active"><a href="?letter=' + l + '" data-letter="' + l + '">' + l + "</a></li>'
36
37
  else
37
38
  links += '<li><a href="?letter=' + l + '" data-letter="' + l + '">' + l + "</a></li>"
38
39
  end
@@ -51,7 +52,8 @@ module AlphabeticalPaginate
51
52
  "</ul>" +
52
53
  "</div>"
53
54
 
54
- output += pagination.html_safe
55
+ output += pagination
56
+ output.html_safe
55
57
  end
56
58
  end
57
59
  end
@@ -1,7 +1,9 @@
1
1
  $(function() {
2
2
  var once = false;
3
3
 
4
- var img = "<img src='/images/aloader.gif' class='loading'/>";
4
+ var img = "<img src='/assets/aloader.gif' class='loading'/>";
5
+ // RAILS 3.0 USERS -> Please delete the above line and uncomment the bottom line
6
+ //var img = "<img src='/images/aloader.gif' class='loading'/>";
5
7
 
6
8
  $(document).on("click", ".pagination#alpha a", function(e) {
7
9
  var url = location.href,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alphabetical_paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-22 00:00:00.000000000 Z
12
+ date: 2013-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler