Sha256: 3de66b9d5e45dfae790190e9b727f4533648f4bcd546682d48b1efecbd4e33eb

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

require "foundation_pagination/version"

module FoundationPagination
  # Contains functionality shared by all renderer classes.
  module FoundationRenderer

    def to_html
      list_items = pagination.map do |item|
        case item
          when Fixnum
            page_number(item)
          else
            send(item)
        end
      end.join(@options[:link_separator])

      if @options[:foundation].to_i >= 3
        tag("ul", list_items, class: "pagination")
      else
        html_container(tag("ul", list_items))
      end
    end
    def html_container(html)
      tag(:ul, html, container_attributes) 
    end

    def container_attributes
      super.except(*[:link_options])
    end

    protected

    def page_number(page)
      link_options = @options[:link_options] || {}
      tag :li, link(page, page, link_options.merge(rel: rel_value(page))), :class => ('current' if page == current_page)
    end

    def gap
      tag :li, link('…', '#'), :class => 'unavailable'
    end

#    def previous_page
#      num = @collection.current_page > 1 && @collection.current_page - 1
#      previous_or_next_page(num, @options[:previous_label], "prev")
#    end

#    def next_page
#      num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
#      previous_or_next_page(num, @options[:next_label], "next")
#    end

    def previous_or_next_page(page, text, classname)
      link_options = @options[:link_options] || {}
      tag :li, link(text, page || '#', link_options), :class => [classname[0..3], classname, ('unavailable' unless page)].join(' ')
      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
will_paginate-foundation-0.2 lib/foundation_pagination/foundation_renderer.rb
will_paginate-foundation-0.1 lib/foundation_pagination/foundation_renderer.rb