Module: Card::Set::Abstract::Paging::PagingViews::HtmlFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
card/tmpsets/set/mod006-card-mod-collection/abstract/paging/paging_views.rb,
card/tmpsets/set/mod005-card-mod-collection/abstract/paging/paging_views.rb

Constant Summary collapse

PAGE_LI_CLASS =
{ ellipses: "disabled", current: "active" }.freeze

Instance Method Summary collapse

Instance Method Details

#fewer_results_than_limit?Boolean

clear we don’t need paging even before running count query

Returns:

  • (Boolean)


82
83
84
85
86
# File 'card/tmpsets/set/mod006-card-mod-collection/abstract/paging/paging_views.rb', line 82

def fewer_results_than_limit?
  return false unless offset.zero?

  limit > offset + search_with_params.length
end


45
46
47
48
49
50
51
52
# File 'card/tmpsets/set/mod006-card-mod-collection/abstract/paging/paging_views.rb', line 45

def page_link text, page, options
  return (:div, text.html_safe, class: "page-link") unless page

  options.merge! class: "card-paging-link slotter page-link",
                 remote: true,
                 path: page_link_path_args(page)
  link_to raw(text), options
end

First page is 0 (not 1)



35
36
37
38
39
# File 'card/tmpsets/set/mod006-card-mod-collection/abstract/paging/paging_views.rb', line 35

def page_link_li text, page, status, options={}
  wrap_with :li, class: page_link_li_class(status) do
    page_link text, page, options
  end
end


41
42
43
# File 'card/tmpsets/set/mod006-card-mod-collection/abstract/paging/paging_views.rb', line 41

def page_link_li_class status
  ["page-item", PAGE_LI_CLASS[status]].compact.join " "
end


69
70
71
# File 'card/tmpsets/set/mod006-card-mod-collection/abstract/paging/paging_views.rb', line 69

def page_link_path_args page
  paging_path_args.merge offset: page * limit
end


28
29
30
31
32
# File 'card/tmpsets/set/mod006-card-mod-collection/abstract/paging/paging_views.rb', line 28

def paging_links
  PagingLinks.new(total_pages, current_page).build do |text, page, status, options|
    page_link_li text, page, status, options
  end
end

#paging_needed?Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
79
# File 'card/tmpsets/set/mod006-card-mod-collection/abstract/paging/paging_views.rb', line 73

def paging_needed?
  return false if limit < 1
  return false if fewer_results_than_limit? # avoid extra count search

  # count search result instead
  limit < count_with_params
end

#paging_path_args(local_args = {}) ⇒ Object



62
63
64
65
66
67
# File 'card/tmpsets/set/mod006-card-mod-collection/abstract/paging/paging_views.rb', line 62

def paging_path_args local_args={}
  @paging_path_args ||= {}
  @paging_path_args.reverse_merge!(limit: limit, offset: offset)
  @paging_path_args.merge! extra_paging_path_args
  @paging_path_args.merge local_args
end

#view: pagingObject



17
18
19
20
21
22
23
24
25
26
# File 'card/tmpsets/set/mod006-card-mod-collection/abstract/paging/paging_views.rb', line 17

view :paging, cache: :never do
  return "" unless paging_needed?
  <<-HTML
    <nav>
      <ul class="pagination paging">
        #{paging_links.join}
      </ul>
    </nav>
  HTML
end

#with_paging(path_args = {}) ⇒ Object



11
12
13
14
15
# File 'card/tmpsets/set/mod006-card-mod-collection/abstract/paging/paging_views.rb', line 11

def with_paging path_args={}
  with_paging_path_args path_args do
    output [yield(@paging_path_args), _render_paging]
  end
end

#with_paging_path_args(args) ⇒ Object



54
55
56
57
58
59
60
# File 'card/tmpsets/set/mod006-card-mod-collection/abstract/paging/paging_views.rb', line 54

def with_paging_path_args args
  tmp = @paging_path_args
  @paging_path_args = paging_path_args args
  yield
ensure
  @paging_path_args = tmp
end