Sha256: a1a3f2315a63f84a6252cbf2b1ac25fed666fd98ac385bd90bffa1abb2ef81d1
Contents?: true
Size: 1.5 KB
Versions: 2
Compression:
Stored size: 1.5 KB
Contents
module Paginate module Renderer class Base # Set the pagination options. attr_reader :options # Set the view context. You can use this object # to call view and url helpers. attr_reader :view_context # Set the object with defines all pagination methods # like `Paginate::Base#next_page?`. attr_reader :processor def initialize(view_context, options) @view_context = view_context @options = options.reverse_merge(Paginate.configuration.to_hash) @processor = Paginate::Base.new(nil, options) end # Return the URL for previous page. def previous_url url_for(processor.page - 1) end # Return the URL for next page. def next_url url_for(processor.page + 1) end # Compute the URL for a given page. # It will keep track of all query string and replace the # page parameter with the specified `page`. def url_for(page) url = options[:url] || options[:fullpath] if url.respond_to?(:call) url = url.call(page).to_s.dup else url = url.dup re = Regexp.new("([&?])#{Regexp.escape(options[:param_name].to_s)}=[^&]*") url.gsub!(re, "\\1") url.gsub!(/[\?&]$/, "") url.gsub!(/&+/, "&") url.gsub!(/\?&/, "?") url << (url =~ /\?/ ? "&" : "?") url << page.to_query(options[:param_name]) end url.gsub!(/&/, "&") url end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
paginate-4.0.1 | lib/paginate/renderer.rb |
paginate-4.0.0 | lib/paginate/renderer.rb |