objectreload-pagination 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/pagination/view_helpers.rb +19 -18
  3. metadata +14 -7
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,7 +5,7 @@ module Pagination
5
5
  # pagination links around (top and bottom) given collection. The helper itself is lightweight
6
6
  # and serves only as a wrapper around LinkRenderer instantiation; the
7
7
  # renderer then does all the hard work of generating the HTML.
8
- #
8
+ #
9
9
  # == Global options for helpers
10
10
  #
11
11
  # Options for pagination helpers are optional and get their default values from the
@@ -39,7 +39,7 @@ module Pagination
39
39
  # Renders Digg/Flickr-style pagination for a Pagination::Collection
40
40
  # object. Nil is returned if there is only one page in total; no point in
41
41
  # rendering the pagination in that case...
42
- #
42
+ #
43
43
  # ==== Options
44
44
  # Display options:
45
45
  # * <tt>:previous_label</tt> -- default: "« Previous" (this parameter is called <tt>:prev_label</tt> in versions <b>2.3.2</b> and older!)
@@ -50,7 +50,7 @@ module Pagination
50
50
  # * <tt>:separator</tt> -- string separator for page HTML elements (default: single space)
51
51
  # * <tt>:controls</tt> -- display controls only at the <tt>:top</tt> or <tt>:bottom</tt> of the pagination block (default: <tt>:both</tt>)
52
52
  # * <tt>:per_page</tt> -- number of items displayed per page (default: 10)
53
- #
53
+ #
54
54
  # HTML options:
55
55
  # * <tt>:class</tt> -- CSS class name for the generated DIV (default: "pagination")
56
56
  # * <tt>:container</tt> -- toggles rendering of the DIV container for pagination links, set to
@@ -68,7 +68,7 @@ module Pagination
68
68
  #
69
69
  # All options not recognized by paginate will become HTML attributes on the container
70
70
  # element for pagination links (the DIV). For example:
71
- #
71
+ #
72
72
  # <% paginate @posts, :style => 'font-size: small' do |posts| %>
73
73
  # ...
74
74
  # <% end %>
@@ -79,9 +79,8 @@ module Pagination
79
79
  #
80
80
  def paginate(collection = [], options = {}, &block)
81
81
  options = options.symbolize_keys.reverse_merge Pagination::ViewHelpers.pagination_options
82
-
82
+
83
83
  collection = Pagination::Collection.new(options.merge(:collection => collection, :current_page => params[options[:param_name]]|| 1))
84
- yield collection and return nil unless collection.total_pages > 1
85
84
 
86
85
  # get the renderer instance
87
86
  renderer = case options[:renderer]
@@ -92,12 +91,14 @@ module Pagination
92
91
  else
93
92
  options[:renderer]
94
93
  end
95
-
94
+
96
95
  # render HTML for pagination
97
96
  renderer.prepare collection, options, self
98
97
  pagination = renderer.to_html.to_s
99
98
 
100
99
  if block_given?
100
+ yield collection and return nil unless collection.total_pages > 1
101
+
101
102
  top = [:top, :both].include?(options[:controls]) ? pagination : ""
102
103
  bottom = [:bottom, :both].include?(options[:controls]) ? pagination : ""
103
104
  unless ActionView::Base.respond_to? :erb_variable
@@ -124,11 +125,11 @@ module Pagination
124
125
  #
125
126
  # <span class="gap">&hellip;</span>
126
127
  attr_accessor :gap_marker
127
-
128
+
128
129
  def initialize
129
130
  @gap_marker = '<span class="gap">&hellip;</span>'
130
131
  end
131
-
132
+
132
133
  # * +collection+ is a Pagination::Collection instance or any other object
133
134
  # that conforms to that API
134
135
  # * +options+ are forwarded from +paginate+ view helper
@@ -150,7 +151,7 @@ module Pagination
150
151
  # previous/next buttons
151
152
  links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:previous_label])
152
153
  links.push page_link_or_span(@collection.next_page, 'disabled next_page', @options[:next_label])
153
-
154
+
154
155
  html = links.join(@options[:separator])
155
156
  @options[:container] ? @template.content_tag(:div, html, html_attributes) : html
156
157
  end
@@ -166,7 +167,7 @@ module Pagination
166
167
  end
167
168
  @html_attributes
168
169
  end
169
-
170
+
170
171
  protected
171
172
 
172
173
  # Collects link items for visible page numbers.
@@ -188,7 +189,7 @@ module Pagination
188
189
  inner_window, outer_window = @options[:inner_window].to_i, @options[:outer_window].to_i
189
190
  window_from = current_page - inner_window
190
191
  window_to = current_page + inner_window
191
-
192
+
192
193
  # adjust lower or upper limit if other is out of bounds
193
194
  if window_to > total_pages
194
195
  window_from -= window_to - total_pages
@@ -199,7 +200,7 @@ module Pagination
199
200
  window_from = 1
200
201
  window_to = total_pages if window_to > total_pages
201
202
  end
202
-
203
+
203
204
  visible = (1..total_pages).to_a
204
205
  left_gap = (2 + outer_window)...window_from
205
206
  right_gap = (window_to + 1)...(total_pages - outer_window)
@@ -208,10 +209,10 @@ module Pagination
208
209
 
209
210
  visible
210
211
  end
211
-
212
+
212
213
  def page_link_or_span(page, span_class, text = nil)
213
214
  text ||= page.to_s
214
-
215
+
215
216
  if page and page != current_page
216
217
  classnames = span_class && span_class.index(' ') && span_class.split(' ', 2).last
217
218
  page_link page, text, :rel => rel_value(page), :class => classnames
@@ -237,10 +238,10 @@ module Pagination
237
238
  # page links should preserve GET parameters
238
239
  stringified_merge @url_params, @template.params if @template.request.get?
239
240
  stringified_merge @url_params, @options[:params] if @options[:params]
240
-
241
+
241
242
  if complex = param_name.index(/[^\w-]/)
242
243
  page_param = parse_query_parameters("#{param_name}=#{page}")
243
-
244
+
244
245
  stringified_merge @url_params, page_param
245
246
  else
246
247
  @url_params[param_name] = page_one ? 1 : 2
@@ -248,7 +249,7 @@ module Pagination
248
249
 
249
250
  url = @template.url_for(@url_params)
250
251
  return url if page_one
251
-
252
+
252
253
  if complex
253
254
  @url_string = url.sub(%r!((?:\?|&amp;)#{CGI.escape param_name}=)#{page}!, "\\1\0")
254
255
  return url
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: objectreload-pagination
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 2
9
+ version: 0.1.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - Mateusz Drozdzynski
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-26 00:00:00 +02:00
17
+ date: 2010-03-18 00:00:00 +00:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -56,24 +61,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
61
  requirements:
57
62
  - - ">="
58
63
  - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
59
66
  version: "0"
60
- version:
61
67
  required_rubygems_version: !ruby/object:Gem::Requirement
62
68
  requirements:
63
69
  - - ">="
64
70
  - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
65
73
  version: "0"
66
- version:
67
74
  requirements: []
68
75
 
69
76
  rubyforge_project:
70
- rubygems_version: 1.3.5
77
+ rubygems_version: 1.3.6
71
78
  signing_key:
72
79
  specification_version: 3
73
80
  summary: Simple pagination - without changes in controllers
74
81
  test_files:
75
- - test/lib/view_test_process.rb
76
82
  - test/active_record_extentions_test.rb
77
83
  - test/collection_test.rb
78
- - test/view_helpers_test.rb
84
+ - test/lib/view_test_process.rb
79
85
  - test/test_helper.rb
86
+ - test/view_helpers_test.rb