Sha256: 42f4a9cff49e3dd24f86365d78666d7d8d997a41f53c851bb46a8b43b527b4c0

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

# https://github.com/amatsuda/kaminari

module Staticpress::Plugins
  module Pagination
    def pagination_menu(current_number, menu_options = {})
      tag :menu, { :type => :toolbar }.merge(menu_options) do
        numbered_pages = Staticpress::Content::Index.published.map do |page|
          number = page.params[:number]
          pagination_item number, number, number == current_number
        end.join

        first_page = 1
        last_page = Staticpress::Content::Index.published.count

        oldest_page = pagination_item 'Oldest', first_page, current_number == first_page
        older_page = pagination_item 'Older', current_number - 1, current_number <= first_page
        newer_page = pagination_item 'Newer', current_number + 1, current_number >= last_page
        newest_page = pagination_item 'Newest', last_page, current_number == last_page

        oldest_page + older_page + numbered_pages + newer_page + newest_page
      end
    end

    def pagination_item(text, number, is_current)
      tag :li do
        if is_current
          tag :span, :class => 'current-page' do
            text
          end
        else
          tag :a, :href => "/page/#{number}" do
            text
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
staticpress-0.7.1 lib/staticpress/plugins/pagination.rb
staticpress-0.7.0 lib/staticpress/plugins/pagination.rb