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 page_number(page) link_options = @options[:link_options] || {} aria_label = @template.will_paginate_translate(:page_aria_label, :page => page.to_i) { "Page #{page}" } if page == current_page tag(:span, page, :class => 'page-link current_page current', :"aria-label" => aria_label, :"aria-current" => 'page') else link_options.merge! class: 'page-link', rel: rel_value(page) link(page, page, {:'data-remote' => @options[:remote], :"aria-label" => aria_label}.merge(link_options)) end end def previous_or_next_page(page, text, classname, aria_label = nil) if page link(text, page, :'data-remote' => @options[:remote], :'aria-label' => aria_label, class: "page-link #{classname}") else tag(:span, text, class: "page-link #{classname} disabled", :'aria-label' => aria_label) end end end end