Sha256: d9b3098a147e8fc93497b35c51da4bf24d0f4a667c134ca49413592cba345b55

Contents?: true

Size: 1.89 KB

Versions: 2

Compression:

Stored size: 1.89 KB

Contents

require 'friendly_id'
require 'will_paginate'
require 'gravatar_image_tag'

require "simple_discussion/version"
require "simple_discussion/engine"
require "simple_discussion/forum_user"

require 'will_paginate/view_helpers/action_view'

module SimpleDiscussion
  # 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

2 entries across 2 versions & 1 rubygems

Version Path
simple_discussion-0.9.1 lib/simple_discussion.rb
simple_discussion-0.9.0 lib/simple_discussion.rb