Module: SpotlightSearch::Helpers

Defined in:
lib/spotlight_search/helpers.rb

Instance Method Summary collapse

Instance Method Details

#cm_paginate(facets) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/spotlight_search/helpers.rb', line 12

def cm_paginate(facets)
  tag.div class: 'text-center' do
    tag.div class: 'nav navbar navbar-inner' do
      tag.ul class: 'pagination' do
        if facets.previous_page != false
          previous_page = tag.li do
            tag.button class: 'btn btn-bordered', data: { behaviour: 'previous-page'} do
              tag.span "Previous"
            end
          end
        end
        current_page =  :li do
          tag.a class: 'btn btn-bordered mx-2', data: {sort_column: facets.sort[:sort_column], sort_direction: facets.sort[:sort_direction], page: facets.current_page, behaviour: 'current-page' } do
            "Showing #{facets.current_page} of #{facets.total_pages} pages"
          end
        end

        if facets.next_page != false
          next_page = tag.li do
            tag.button class: 'btn btn-bordered', data: { behaviour: 'next-page'} do
              tag.span "Next"
            end
          end
        end
        (previous_page || ActiveSupport::SafeBuffer.new) + current_page + (next_page || ActiveSupport::SafeBuffer.new)
      end
    end
  end
end

#sortable(column, title = nil, sort_column = "created_at", sort_direction = "asc") ⇒ Object



4
5
6
7
8
9
10
# File 'lib/spotlight_search/helpers.rb', line 4

def sortable(column, title = nil, sort_column="created_at", sort_direction="asc")
  title ||= column.titleize
  css_class = column == sort_column ? "current #{sort_direction}" : nil
  direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
  # link_to title, '#', {:class => css_class, data: {sort: column, direction: direction}}
  ("a","Title", class: css_class, data: {sort_column: column, sort_direction: direction, behaviour: 'sort', type: 'anchor-filter'})
end