Sha256: b2a7f6f195879a59991a0f55786440e7dea83afa197a5282f988a709faa464b8

Contents?: true

Size: 1.43 KB

Versions: 81

Compression:

Stored size: 1.43 KB

Contents

# This handy simplification is adapted from SphinxSearch (thanks)
# and originally came from Ultrasphinx
# it saves us a lot of including and bodging to make will_paginate's template calls work in the Page model

module TrustyCms
  module Pagination
    class LinkRenderer < WillPaginate::LinkRenderer
      def initialize(url_stem)
        @url_stem = url_stem
      end

      def to_html
        links = @options[:page_links] ? windowed_links : []
        links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:previous_label])
        links.push    page_link_or_span(@collection.next_page,     'disabled next_page', @options[:next_label])
        html = links.join(@options[:separator])
        @options[:container] ? %{<div class="pagination">#{html}</div>} : html
      end

      # this is rather crude compared to the WillPaginate link-builder,
      # but it can get by without much context to draw on
      def page_link(page, text, attributes = {})
        linkclass = %{ class="#{attributes[:class]}"} if attributes[:class]
        linkrel = %{ rel="#{attributes[:rel]}"} if attributes[:rel]
        param_name = WillPaginate::ViewHelpers.pagination_options[:param_name]
        %{<a href="#{@url_stem}?#{param_name}=#{page}"#{linkrel}#{linkclass}>#{text}</a>}
      end

      def page_span(_page, text, attributes = {})
        %{<span class="#{attributes[:class]}">#{text}</span>}
      end
    end
  end
end

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
trusty-cms-5.0.3 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-5.0.2 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-5.0.1 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.3.5 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-5.0.0 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.3.4 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.3.3 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.3.2 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.3.1 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.3 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.2.3 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.2.2 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.2.1 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.2 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.1.9 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.1.8 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.1.7 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.1.6 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.1.5 lib/trusty_cms/pagination/link_renderer.rb
trusty-cms-4.1.4 lib/trusty_cms/pagination/link_renderer.rb