Sha256: 756a781ba49fe00767cbf26c4943f2d001634162b940175354d75d2e45aa3461

Contents?: true

Size: 874 Bytes

Versions: 2

Compression:

Stored size: 874 Bytes

Contents

module PaginatedTable
  class LinkRenderer < WillPaginate::ActionView::LinkRenderer
    def initialize(page)
      super()
      @paginated_table_page = page
    end

    def sort_link(text, sort_on)
      @template.link_to(text, sort_url(sort_on), :remote => true)
    end

    def tag(name, value, attributes = {})
      if name == :a
        @template.link_to(value.to_s.html_safe, attributes.delete(:href), attributes.merge(:remote => true))
      else
        super
      end
    end

    private

    def sort_url(sort_on)
      new_page = @paginated_table_page.page_for_sort_column(sort_on)
      new_page_params = PageParams.to_params(new_page)
      params = merge_get_params({})
      symbolized_update(params, new_page_params)
      @template.url_for(params)
    end

    def default_url_params
      PageParams.to_params(@paginated_table_page)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
paginated_table-0.0.9 lib/paginated_table/link_renderer.rb
paginated_table-0.0.8 lib/paginated_table/link_renderer.rb