module Paginate class Renderer attr_accessor :options attr_accessor :current_page def initialize(options) @current_page = [options[:page].to_i, 1].max options.reverse_merge!(Paginate::Config.to_hash) @options = options.merge(:page => current_page) end def processor @processor ||= Paginate::Base.new(options) end def url_for(page) url = options[:url] || options[:fullpath] if url.kind_of?(Proc) url[page] else re = Regexp.new("([&?])#{Regexp.escape(options[:param_name].to_s)}=[0-9]+") url.gsub!(re, "\\1") url.gsub!(/\?$/, "") url.gsub!(/\?&/, "?") url = URI.parse(url).to_s connector = (url =~ /\?/) ? "&" : "?" url + connector + page.to_s.to_query(options[:param_name]) end end def render html = String.new previous_label = I18n.t("paginate.previous") previous_url = url_for(options[:page] - 1) next_label = I18n.t("paginate.next") next_url = url_for(options[:page] + 1) page_label = I18n.t("paginate.page", options) css = %w[ paginate ] css << "disabled" unless processor.previous_page? || processor.next_page? html << %[