Class: Ramaze::Helper::Paginate::Paginator
- Includes:
- Ramaze::Helper
- Defined in:
- lib/ramaze/helper/paginate.rb
Overview
Provides easy pagination and navigation
Defined Under Namespace
Classes: ArrayPager
Constant Summary
Constants included from Ramaze::Helper
Instance Method Summary collapse
- #count ⇒ Object
- #current_page ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #first_page? ⇒ Boolean
-
#initialize(data = [], page = 1, limit = 10, var = 'pager') ⇒ Paginator
constructor
A new instance of Paginator.
- #last_page ⇒ Object
- #last_page? ⇒ Boolean
- #navigation(limit = 8) ⇒ Object
-
#needed? ⇒ Boolean
Useful to omit pager if it’s of no use.
- #next_page ⇒ Object
-
#page_count ⇒ Object
these methods are actually on the pager, but we def them here for convenience (method_missing in helper is evil and even slower).
- #prev_page ⇒ Object
Constructor Details
#initialize(data = [], page = 1, limit = 10, var = 'pager') ⇒ Paginator
Returns a new instance of Paginator.
69 70 71 72 73 74 |
# File 'lib/ramaze/helper/paginate.rb', line 69 def initialize(data = [], page = 1, limit = 10, var = 'pager') @data, @page, @limit, @var = data, page, limit, var @pager = pager_for(data) @page = @page > page_count ? page_count : @page @pager = pager_for(data) end |
Instance Method Details
#count ⇒ Object
157 |
# File 'lib/ramaze/helper/paginate.rb', line 157 def count; @pager.count; end |
#current_page ⇒ Object
152 |
# File 'lib/ramaze/helper/paginate.rb', line 152 def current_page; @pager.current_page; end |
#each(&block) ⇒ Object
149 |
# File 'lib/ramaze/helper/paginate.rb', line 149 def each(&block) @pager.each(&block) end |
#empty? ⇒ Boolean
156 |
# File 'lib/ramaze/helper/paginate.rb', line 156 def empty?; @pager.empty?; end |
#first_page? ⇒ Boolean
150 |
# File 'lib/ramaze/helper/paginate.rb', line 150 def first_page?; @pager.first_page?; end |
#last_page ⇒ Object
153 |
# File 'lib/ramaze/helper/paginate.rb', line 153 def last_page; @pager.last_page; end |
#last_page? ⇒ Boolean
154 |
# File 'lib/ramaze/helper/paginate.rb', line 154 def last_page?; @pager.last_page?; end |
#navigation(limit = 8) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ramaze/helper/paginate.rb', line 102 def (limit = 8) g = Ramaze::Gestalt.new g.div :class => :pager do if first_page? g.span(:class => 'first grey'){ h('<<') } g.span(:class => 'previous grey'){ h('<') } else link(g, 1, '<<', :class => :first) link(g, prev_page, '<', :class => :previous) end lower = limit ? (current_page - limit) : 1 lower = lower < 1 ? 1 : lower (lower...current_page).each do |n| link(g, n) end link(g, current_page, current_page, :class => :current) if last_page? g.span(:class => 'next grey'){ h('>') } g.span(:class => 'last grey'){ h('>>') } elsif next_page higher = limit ? (next_page + limit) : page_count higher = [higher, page_count].min (next_page..higher).each do |n| link(g, n) end link(g, next_page, '>', :class => :next) link(g, page_count, '>>', :class => :last) end end g.to_s end |
#needed? ⇒ Boolean
Useful to omit pager if it’s of no use.
141 142 143 |
# File 'lib/ramaze/helper/paginate.rb', line 141 def needed? @pager.page_count > 1 end |
#next_page ⇒ Object
155 |
# File 'lib/ramaze/helper/paginate.rb', line 155 def next_page; @pager.next_page; end |
#page_count ⇒ Object
these methods are actually on the pager, but we def them here for convenience (method_missing in helper is evil and even slower)
148 |
# File 'lib/ramaze/helper/paginate.rb', line 148 def page_count; @pager.page_count end |
#prev_page ⇒ Object
151 |
# File 'lib/ramaze/helper/paginate.rb', line 151 def prev_page; @pager.prev_page; end |