Sha256: e2d8ea28d663c7df800641989e7efc33674f306d72bd38668960b2809743e1ee

Contents?: true

Size: 1.91 KB

Versions: 9

Compression:

Stored size: 1.91 KB

Contents

class PaginationListLinkRenderer < WillPaginate::ActionView::LinkRenderer
  # << < page x of x > >> y per page

  def container_attributes
    super.except(:first_label, :last_label)
  end
  
  def to_html
    html = pagination.map do |item|
      item.is_a?(Fixnum) ?
        page_number(item) :
        send(item)
    end.join(@options[:link_separator])
    
    @options[:container] ? html_container(html) : html
  end

  protected

    def pagination
      #[ :first_page, :previous_page, :current_page_info, :next_page, :last_page, :per_page_navigator, :input_page_navigator ]
      [ :first_page, :previous_page, :current_page_info, :next_page, :last_page, :input_page_navigator ]
    end

    def first_page
      previous_or_next_page(current_page == 1 ? nil : 1, "<<", "first_page")
    end

    def last_page
      previous_or_next_page(current_page == total_pages ? nil : total_pages, ">>", "last_page")
    end
    
    def current_page_info
      '<div class="current_page_part">' + I18n.t("will_paginate.current_page_info", {current_page: current_page, total_pages: total_pages}) + '</div>'     
    end
    
    def input_page_navigator
      '<div class="go_to_page_part"><div>' + I18n.t("will_paginate.go_to_page") + ": </div>" + tag(:input, "", :type => "text", :name => "page", :value => @options[:page].presence || 1) + tag(:a, "Go", :href => "#{url(1)}", :class => 'gotopage btn-mini', "data-remote" => 'true') + '</div>'
    end
    
    def per_page_navigator
      per_page_options = [2, 5, 10, 20, 50, 100]
      '<div class="per_page_part">' + (tag(:select, per_page_options.map{|m| "<option #{(m==@options[:per_page]? 'selected=selected' : '')}>#{m}</option>"}.join, :data_value => @options[:per_page], :name => "per_page").html_safe) + I18n.t("will_paginate.per_page") + '</div>'
    end

    def link(text, target, attributes = {})
      attributes["data-remote"] = @options[:remote].presence || false
      super
    end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rich_table_component-0.0.10 lib/pagination_list_link_renderer.rb
rich_table_component-0.0.9 lib/pagination_list_link_renderer.rb
rich_table_component-0.0.8 lib/pagination_list_link_renderer.rb
rich_table_component-0.0.7 lib/pagination_list_link_renderer.rb
rich_table_component-0.0.6 lib/pagination_list_link_renderer.rb
rich_table_component-0.0.5 lib/pagination_list_link_renderer.rb
rich_table_component-0.0.4 lib/pagination_list_link_renderer.rb
rich_table_component-0.0.3 lib/pagination_list_link_renderer.rb
rich_table_component-0.0.2 lib/pagination_list_link_renderer.rb