Class: Paginate::Renderer::Base
- Inherits:
-
Object
- Object
- Paginate::Renderer::Base
- Defined in:
- lib/paginate/renderer.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Set the pagination options.
-
#processor ⇒ Object
readonly
Set the object with defines all pagination methods like ‘Paginate::Base#next_page?`.
-
#view_context ⇒ Object
readonly
Set the view context.
Instance Method Summary collapse
-
#initialize(view_context, options) ⇒ Base
constructor
A new instance of Base.
-
#next_url ⇒ Object
Return the URL for next page.
-
#previous_url ⇒ Object
Return the URL for previous page.
-
#url_for(page) ⇒ Object
Compute the URL for a given page.
Constructor Details
Instance Attribute Details
#options ⇒ Object (readonly)
Set the pagination options.
5 6 7 |
# File 'lib/paginate/renderer.rb', line 5 def @options end |
#processor ⇒ Object (readonly)
Set the object with defines all pagination methods like ‘Paginate::Base#next_page?`.
13 14 15 |
# File 'lib/paginate/renderer.rb', line 13 def processor @processor end |
#view_context ⇒ Object (readonly)
Set the view context. You can use this object to call view and url helpers.
9 10 11 |
# File 'lib/paginate/renderer.rb', line 9 def view_context @view_context end |
Instance Method Details
#next_url ⇒ Object
Return the URL for next page.
27 28 29 |
# File 'lib/paginate/renderer.rb', line 27 def next_url url_for(processor.page + 1) end |
#previous_url ⇒ Object
Return the URL for previous page.
22 23 24 |
# File 'lib/paginate/renderer.rb', line 22 def previous_url url_for(processor.page - 1) end |
#url_for(page) ⇒ Object
Compute the URL for a given page. It will keep track of all query string and replace the page parameter with the specified ‘page`.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/paginate/renderer.rb', line 34 def url_for(page) url = [:url] || [:fullpath] if url.respond_to?(:call) url = url.call(page).to_s.dup else url = url.dup re = Regexp.new("([&?])#{Regexp.escape([:param_name].to_s)}=[^&]*") url.gsub!(re, "\\1") url.gsub!(/[\?&]$/, "") url.gsub!(/&+/, "&") url.gsub!(/\?&/, "?") url << (url =~ /\?/ ? "&" : "?") url << page.to_query([:param_name]) end url.gsub!(/&/, "&") url end |