Sha256: 6795eaa06bab440574c13f1dd84978629f1cf7f6b686ef95c0faaaec4a514fbb
Contents?: true
Size: 1.64 KB
Versions: 1
Compression:
Stored size: 1.64 KB
Contents
module Pagination def paginator_for page, entries_count, per_page, &to_link page.must_be >= 1 return if page == 1 and entries_count < per_page opt = { current_page: page, pages: [], #(go_prev + [current] + go_next), to_link: to_link } opt[:prev] = to_link.call(t(:go_prev), page - 1) if page > 1 opt[:next] = to_link.call(t(:go_next), page + 1) b.paginator opt end # PAGINATOR_HALF_SIZE = 3 # # def paginator_for current, total_entries, per_page, &to_link # return "" if total_entries <= per_page # total = (total_entries / (1.0 * per_page)).ceil # # from = current # if current > 1 # from = current - PAGINATOR_HALF_SIZE # if (right_size = total - current) < PAGINATOR_HALF_SIZE # from -= (PAGINATOR_HALF_SIZE - right_size) # end # from = 1 if from < 0 # end # # to = current # if current < total_entries # to = current + PAGINATOR_HALF_SIZE # if (left_size = current - 1) < PAGINATOR_HALF_SIZE # to += (PAGINATOR_HALF_SIZE - left_size) # end # to = total if to > total # end # # go_prev, go_next = [], [] # (from..to).each do |n| # if n < current # go_prev << to_link.call(n.to_s, n) # elsif n > current # go_next << to_link.call(n.to_s, n) # end # end # # opt = { # current_page: current, # pages: (go_prev + [current] + go_next), # to_link: to_link # } # # opt[:prev] = to_link.call(t(:go_prev), current - 1) if current > 1 # opt[:next] = to_link.call(t(:go_next), current + 1) if current < total # # b.paginator opt # end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rad_kit-0.0.10 | app/helpers/kit/pagination.rb |