Module: Decidim::PaginateHelper

Included in:
CellsPaginateHelper
Defined in:
app/helpers/decidim/paginate_helper.rb

Overview

Helper to paginate collections.

Instance Method Summary collapse

Instance Method Details

#decidim_paginate(collection, paginate_params = {}) ⇒ Object

Displays pagination links for the given collection, setting the correct theme. This mostly acts as a proxy for the underlying pagination engine.

collection - a collection of elements that need to be paginated paginate_params - a Hash with options to delegate to the pagination helper.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/helpers/decidim/paginate_helper.rb', line 11

def decidim_paginate(collection, paginate_params = {})
  return if collection.total_pages <= 1

  per_page = (params[:per_page] || paginate_params[:per_page] || Decidim::Paginable::OPTIONS.first).to_i

   :div, class: "flex flex-col-reverse md:flex-row items-center justify-between gap-1 py-8 md:py-16", data: { pagination: "" } do
    template = ""
    template += render(partial: "decidim/shared/results_per_page", locals: { per_page: }, formats: [:html]) if collection.total_pages.positive?
    template += paginate collection, window: 2, outer_window: 1, theme: "decidim", params: paginate_params
    template.html_safe
  end
end