Sha256: 4cc400f3f3faf248c325ef7b9452cf53c3d06dd02004ce33bc48e808ec01f9d3
Contents?: true
Size: 1.71 KB
Versions: 6
Compression:
Stored size: 1.71 KB
Contents
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('…'.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
6 entries across 6 versions & 1 rubygems