lib/rails_paginate/renderers/base.rb in rails_paginate-0.0.4 vs lib/rails_paginate/renderers/base.rb in rails_paginate-0.0.5

- old
+ new

@@ -1,35 +1,34 @@ module RailsPaginate::Renderers # base method class Base attr_reader :view, :collection, :options, :pager + # setup rails_paginate collection def initialize(view, collection, pager, options = {}) raise ArgumentError, "first argument must be a RailsPaginate::Collection" unless collection.is_a? RailsPaginate::Collection raise ArgumentError, "second argument must be a Hash" unless options.is_a? Hash raise ArgumentError, "third argument must be an instance of RailsPaginate::Pagers::Base" unless pager.is_a? RailsPaginate::Pagers::Base @options = options @collection = collection @view = view @pager = pager end + # build url def url_for_page(page) - # todo: fix url_for so did't neet fallback - begin - view.url_for(view.default_url_options.merge({:page => page})) - rescue - "?page=#{page}" - end + view.url_for(view.default_url_options.merge({page_param.to_sym => page})) end + # abstrack renderer def render raise StandardError, "render is not implemented" end protected + # link to page with i18n support def link_to_page(page, key, options = {}) css_class = "#{options[:class]} #{page == current_page ? 'current' : ''}" if key.nil? content_tag :span, "..", :class => "spacer" elsif page.nil? @@ -37,22 +36,30 @@ else link_to t(key, :page => page), url_for_page(page), :class => css_class, :alt => view.strip_tags(t(key, :page => page)) end end + # + def page_param + options[:page_param] || RailsPaginate.page_param + end + # helper def current_page collection.current_page end + # map to view helper def content_tag(*args, &block) view.content_tag(*args, &block) end + # map to view helper def link_to(*args, &block) view.link_to(*args, &block) end + # map to view helper def t(*args) view.t(*args) end end \ No newline at end of file