Sha256: 616533a90b2eb3007c95e4e4ab7c544b6d52031beb8545d6c381f153c1b3859b
Contents?: true
Size: 1.78 KB
Versions: 1
Compression:
Stored size: 1.78 KB
Contents
require "bulma_pagination/version" module BulmaPagination # Contains functionality shared by all renderer classes. module BulmaRenderer def to_html pages = pagination page_prev = pages.delete(:previous_page) page_next = pages.delete(:next_page) list_items = pages.map do |item| item.is_a?(Integer) ? page_number(item) : send(item) end.join(@options[:link_separator]) content = tag("ul", list_items, class: "pagination-list") content.prepend(next_page) if page_next content.prepend(previous_page) if page_prev tag("nav", content, class: "pagination #{@options[:class]}") end def container_attributes super.except(*[:link_options]) end protected def page_number(page) link_options = @options[:link_options] || {} if page == current_page tag :li, tag(:span, page), class: ('pagination-link is-current') else tag :li, link(page, page, link_options.merge(rel: rel_value(page), class: 'pagination-link')) end end def previous_or_next_page(page, text, classname) link_options = @options[:link_options] || {} if page tag :li, link(text, page, link_options), class: classname else tag :li, tag(:span, text), class: classname, disabled: true end end def gap tag :li, '<span class="pagination-ellipsis">…</span>' end def previous_page num = @collection.current_page > 1 && @collection.current_page - 1 previous_or_next_page(num, @options[:previous_label], "pagination-previous") end def next_page num = @collection.current_page < @collection.total_pages && @collection.current_page + 1 previous_or_next_page(num, @options[:next_label], "pagination-next") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
will_paginate-bulma-1.0.0 | lib/bulma_pagination/bulma_renderer.rb |