Sha256: 6c8067eae50f74e4f8853082d415cf5df520330e5f4f5c5d9ff695c9e791c944

Contents?: true

Size: 1.7 KB

Versions: 4

Compression:

Stored size: 1.7 KB

Contents

require 'will_paginate/view_helpers/action_view'

module HelpCenter
  # This code serves two purposes
  # 1. It patches will_paginate to work with scoped and mounted Rails engines
  #    by adding in the url_builder option
  # 2. It adds Bootstrap 4 styling to will_paginate

  class BootstrapLinkRenderer < WillPaginate::ActionView::LinkRenderer

    # This method adds the `url_builder` option so we can pass in the
    # mounted Rails engine's scope for will_paginate
    def url(page)
      @base_url_params ||= begin
                             url_params = merge_get_params(default_url_params)
                             merge_optional_params(url_params)
                           end

      url_params = @base_url_params.dup
      add_current_page_param(url_params, page)

      # Add optional url_builder support
      (@options[:url_builder] || @template).url_for(url_params)
    end

    protected
    def html_container(html)
      tag :nav, tag(:ul, html, class: ul_class)
    end

    def page_number(page)
      item_class = if(page == current_page)
        'active page-item'
      else
        'page-item'
      end

      tag :li, link(page, page, :rel => rel_value(page), :class => 'page-link'), :class => item_class
    end

    def gap
      tag :li, link('&hellip;'.html_safe, '#', :class => 'page-link'), :class => 'page-item disabled'
    end

    def previous_or_next_page(page, text, classname)
      tag :li, link(text, page || '#', :class => 'page-link'), :class => [(classname[0..3] if  @options[:page_links]), (classname if @options[:page_links]), ('disabled' unless page), 'page-item'].join(' ')
    end

    def ul_class
       ["pagination", container_attributes[:class]].compact.join(" ")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
help_center-0.0.4 lib/help_center/will_paginate.rb
help_center-0.0.3 lib/help_center/will_paginate.rb
help_center-0.0.2 lib/help_center/will_paginate.rb
help_center-0.0.1 lib/help_center/will_paginate.rb