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

Extended by:
Card::Set::AbstractFormat
Defined in:
tmpsets/set/mod008-pointer/abstract/01_paging.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)


118
119
120
121
122
# File 'tmpsets/set/mod008-pointer/abstract/01_paging.rb', line 118

def fewer_results_than_limit?
  return false unless offset.zero?

  limit > offset + search_with_params.length
end


81
82
83
84
85
86
87
88
# File 'tmpsets/set/mod008-pointer/abstract/01_paging.rb', line 81

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)



71
72
73
74
75
# File 'tmpsets/set/mod008-pointer/abstract/01_paging.rb', line 71

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


77
78
79
# File 'tmpsets/set/mod008-pointer/abstract/01_paging.rb', line 77

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


105
106
107
# File 'tmpsets/set/mod008-pointer/abstract/01_paging.rb', line 105

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


63
64
65
66
67
68
# File 'tmpsets/set/mod008-pointer/abstract/01_paging.rb', line 63

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)


109
110
111
112
113
114
115
# File 'tmpsets/set/mod008-pointer/abstract/01_paging.rb', line 109

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



98
99
100
101
102
103
# File 'tmpsets/set/mod008-pointer/abstract/01_paging.rb', line 98

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

#with_paging(path_args = {}) ⇒ Object



45
46
47
48
49
# File 'tmpsets/set/mod008-pointer/abstract/01_paging.rb', line 45

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



90
91
92
93
94
95
96
# File 'tmpsets/set/mod008-pointer/abstract/01_paging.rb', line 90

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