Module: Dugway::Filters::DefaultPagination

Defined in:
lib/dugway/liquid/filters/default_pagination.rb

Instance Method Summary collapse

Instance Method Details

#default_pagination(paginate, div_id = 'pagination', div_class = 'pagination', prev_label = nil, next_label = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dugway/liquid/filters/default_pagination.rb', line 4

def default_pagination(paginate, div_id = 'pagination', div_class = 'pagination', prev_label = nil, next_label = nil)
  Array.new.tap { |html|
    html << %(<div class="#{ div_class }" id="#{ div_id }">)

    prev_label = prev_label.blank? ? paginate['previous']['title'] : prev_label
    if paginate['previous']['is_link']
      html << %(<a class="previous" href="#{ paginate['previous']['url'] }" aria-label="Go to previous page">#{ prev_label }</a>)
    else
      html << %(<span class="previous disabled">#{ prev_label }</span>)
    end

    paginate['parts'].each do |part|
      if part['is_link']
        html << %(<a href="#{ part['url'] }" aria-label="Go to page #{part['title']}">#{ part['title'] }</a>)
      else
        html << build_non_link_span(part, paginate)
      end
    end

    next_label = next_label.blank? ? paginate['next']['title'] : next_label
    if paginate['next']['is_link']
      html << %(<a class="next" href="#{ paginate['next']['url'] }" aria-label="Go to next page">#{ next_label }</a>)
    else
      html << %(<span class="next disabled">#{ next_label }</span>)
    end

    html << %(</div>)
  }.join(' ')
end