require 'will_paginate/view_helpers/action_view' module Symphonia class BootstrapLinkRender < ::WillPaginate::ActionView::LinkRenderer def pagination items = @options[:page_links] ? windowed_page_numbers : [] unless @options[:page_links] == :only items.unshift :previous_page items.push :next_page end items end def to_html html = pagination.map do |item| if @options[:remote] if item == :next_page tag :li,next_page, class: 'page-item' end else tag(:li, (item.is_a?(Integer) ? page_number(item) : send(item)).html_safe, class: 'page-item' + (item == current_page ? ' active' : '')) end end.join(@options[:link_separator]) container_classes = %w(pagination justify-content-center) container_classes << 'pagination-sm' if @options[:small] container_classes << 'pagination-lg' if @options[:large] nav = tag(:ul, html.html_safe, class: container_classes.join(' ')) tag :nav, nav, class: 'd-print-none' end def default_url_params @options[:query] && @options[:query].to_params || {} end def url(page) @base_url_params ||= begin url_params = merge_get_params(default_url_params) url_params[:only_path] = true merge_optional_params(url_params) end @template.url_for(@base_url_params.merge({:page => page})) end def page_number(page) link_options = @options[:link_options] || {} if page == current_page tag(:span, page, class: 'page-link current_page') else link_options.merge! class: 'page-link', rel: rel_value(page) link(page, page, {:'data-remote' => @options[:remote]}.merge(link_options)) end end def previous_or_next_page(page, text, classname) if page link(text, page, :'data-remote' => @options[:remote], class: "page-link #{classname}") else tag(:span, text, class: "page-link #{classname} disabled") end end end end