Class: Wee::Pager
- Defined in:
- lib/wee/components/pager.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#entries_per_page ⇒ Object
Returns the value of attribute entries_per_page.
-
#num_entries ⇒ Object
Returns the value of attribute num_entries.
Instance Method Summary collapse
-
#current_start_index ⇒ Object
Returns the index of the first entry on the current page.
-
#first ⇒ Object
Go to first page.
-
#goto(page) ⇒ Object
Go to page with index
pageNote that page-indices start with zero!. -
#initialize(num_entries = 0) {|_self| ... } ⇒ Pager
constructor
A new instance of Pager.
-
#last ⇒ Object
Go to last page.
-
#last_page_index ⇒ Object
Returns the index of the last page.
-
#next ⇒ Object
Go to next page.
-
#num_pages ⇒ Object
Returns the number of pages.
-
#prev ⇒ Object
Go to previous page.
- #render ⇒ Object
Methods inherited from Component
#add_decoration, #backtrack_state, #backtrack_state_chain, #decoration, #decoration=, #do_render_chain, #each_decoration, #process_callbacks, #process_callbacks_chain, #remove_decoration, #remove_decoration_if
Methods inherited from Presenter
#backtrack_state, #do_render, #get_property, #lookup_property, #process_callbacks, #properties, #properties=, #session, template, uses_property
Constructor Details
#initialize(num_entries = 0) {|_self| ... } ⇒ Pager
Returns a new instance of Pager.
5 6 7 8 9 10 11 |
# File 'lib/wee/components/pager.rb', line 5 def initialize(num_entries=0) super() @num_entries = num_entries @current_page = 0 @entries_per_page = 20 yield self if block_given? end |
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
3 4 5 |
# File 'lib/wee/components/pager.rb', line 3 def current_page @current_page end |
#entries_per_page ⇒ Object
Returns the value of attribute entries_per_page.
2 3 4 |
# File 'lib/wee/components/pager.rb', line 2 def entries_per_page @entries_per_page end |
#num_entries ⇒ Object
Returns the value of attribute num_entries.
2 3 4 |
# File 'lib/wee/components/pager.rb', line 2 def num_entries @num_entries end |
Instance Method Details
#current_start_index ⇒ Object
Returns the index of the first entry on the current page
22 23 24 |
# File 'lib/wee/components/pager.rb', line 22 def current_start_index @current_page * @entries_per_page end |
#first ⇒ Object
Go to first page
34 35 36 |
# File 'lib/wee/components/pager.rb', line 34 def first goto(0) end |
#goto(page) ⇒ Object
Go to page with index page Note that page-indices start with zero!
59 60 61 62 |
# File 'lib/wee/components/pager.rb', line 59 def goto(page) @current_page = page validate end |
#last ⇒ Object
Go to last page
40 41 42 |
# File 'lib/wee/components/pager.rb', line 40 def last goto(last_page_index()) end |
#last_page_index ⇒ Object
Returns the index of the last page
28 29 30 |
# File 'lib/wee/components/pager.rb', line 28 def last_page_index num_pages() - 1 end |
#next ⇒ Object
Go to next page
52 53 54 |
# File 'lib/wee/components/pager.rb', line 52 def next goto(@current_page + 1) end |
#num_pages ⇒ Object
Returns the number of pages
15 16 17 18 |
# File 'lib/wee/components/pager.rb', line 15 def num_pages n, rest = @num_entries.divmod(@entries_per_page) if rest > 0 then n + 1 else n end end |
#prev ⇒ Object
Go to previous page
46 47 48 |
# File 'lib/wee/components/pager.rb', line 46 def prev goto(@current_page - 1) end |
#render ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/wee/components/pager.rb', line 64 def render return if num_pages() <= 0 render_arrow(:first, "<<", "Go to first page"); r.space(2) render_arrow(:prev, "<", "Go to previous page"); r.space(2) render_index; r.space(2) render_arrow(:next, ">", "Go to next page"); r.space(2) render_arrow(:last, ">>", "Go to last page") end |