Module: PaginationRenderLogic::Digg
- Defined in:
- lib/pagination_render_logic/digg.rb
Overview
Provides logic for building digg style pagination First Previous 1 2 3 … 22 23 24 25 26 [27] 28 29 30 31 32 … 48 49 50 Next Last
Instance Attribute Summary collapse
-
#after_first_page ⇒ Object
Returns the value of attribute after_first_page.
-
#arround_current_page ⇒ Object
Returns the value of attribute arround_current_page.
-
#current_page ⇒ Object
Returns the value of attribute current_page.
-
#first_page_section ⇒ Object
Returns the value of attribute first_page_section.
-
#last_page_section ⇒ Object
Returns the value of attribute last_page_section.
-
#middle_section ⇒ Object
Returns the value of attribute middle_section.
-
#total_pages ⇒ Object
Returns the value of attribute total_pages.
Instance Method Summary collapse
- #config(args = {}) ⇒ Object
- #config!(args = {}) ⇒ Object
- #first_page ⇒ Object
- #has_first_page? ⇒ Boolean
- #has_first_page_section? ⇒ Boolean
- #has_last_page? ⇒ Boolean
- #has_last_page_section? ⇒ Boolean
- #has_links? ⇒ Boolean
- #has_next_page? ⇒ Boolean
- #has_previous_page? ⇒ Boolean
- #last_page ⇒ Object
- #next_page ⇒ Object
- #previous_page ⇒ Object
- #setup ⇒ Object
Instance Attribute Details
#after_first_page ⇒ Object
Returns the value of attribute after_first_page.
5 6 7 |
# File 'lib/pagination_render_logic/digg.rb', line 5 def after_first_page @after_first_page end |
#arround_current_page ⇒ Object
Returns the value of attribute arround_current_page.
5 6 7 |
# File 'lib/pagination_render_logic/digg.rb', line 5 def arround_current_page @arround_current_page end |
#current_page ⇒ Object
Returns the value of attribute current_page.
5 6 7 |
# File 'lib/pagination_render_logic/digg.rb', line 5 def current_page @current_page end |
#first_page_section ⇒ Object
Returns the value of attribute first_page_section.
5 6 7 |
# File 'lib/pagination_render_logic/digg.rb', line 5 def first_page_section @first_page_section end |
#last_page_section ⇒ Object
Returns the value of attribute last_page_section.
5 6 7 |
# File 'lib/pagination_render_logic/digg.rb', line 5 def last_page_section @last_page_section end |
#middle_section ⇒ Object
Returns the value of attribute middle_section.
5 6 7 |
# File 'lib/pagination_render_logic/digg.rb', line 5 def middle_section @middle_section end |
#total_pages ⇒ Object
Returns the value of attribute total_pages.
5 6 7 |
# File 'lib/pagination_render_logic/digg.rb', line 5 def total_pages @total_pages end |
Instance Method Details
#config(args = {}) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/pagination_render_logic/digg.rb', line 9 def config(args = {}) @total_pages = args[:total_pages] || 0 @after_first_page = args[:after_first_page] || 3 @arround_current_page = args[:arround_current_page] || 5 @current_page = args[:current_page] || 1 end |
#config!(args = {}) ⇒ Object
16 17 18 19 |
# File 'lib/pagination_render_logic/digg.rb', line 16 def config!(args = {}) config(args) setup end |
#first_page ⇒ Object
54 55 56 |
# File 'lib/pagination_render_logic/digg.rb', line 54 def first_page 1 end |
#has_first_page? ⇒ Boolean
50 51 52 |
# File 'lib/pagination_render_logic/digg.rb', line 50 def has_first_page? @current_page > 1 end |
#has_first_page_section? ⇒ Boolean
70 71 72 |
# File 'lib/pagination_render_logic/digg.rb', line 70 def has_first_page_section? not @first_page_section.empty? end |
#has_last_page? ⇒ Boolean
42 43 44 |
# File 'lib/pagination_render_logic/digg.rb', line 42 def has_last_page? @current_page < @total_pages end |
#has_last_page_section? ⇒ Boolean
74 75 76 |
# File 'lib/pagination_render_logic/digg.rb', line 74 def has_last_page_section? not @last_page_section.empty? end |
#has_links? ⇒ Boolean
66 67 68 |
# File 'lib/pagination_render_logic/digg.rb', line 66 def has_links? @total_pages > 1 end |
#has_next_page? ⇒ Boolean
34 35 36 |
# File 'lib/pagination_render_logic/digg.rb', line 34 def has_next_page? @current_page < @total_pages end |
#has_previous_page? ⇒ Boolean
58 59 60 |
# File 'lib/pagination_render_logic/digg.rb', line 58 def has_previous_page? @current_page > 1 end |
#last_page ⇒ Object
46 47 48 |
# File 'lib/pagination_render_logic/digg.rb', line 46 def last_page @total_pages end |
#next_page ⇒ Object
38 39 40 |
# File 'lib/pagination_render_logic/digg.rb', line 38 def next_page @current_page + 1 end |
#previous_page ⇒ Object
62 63 64 |
# File 'lib/pagination_render_logic/digg.rb', line 62 def previous_page @current_page - 1 end |
#setup ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pagination_render_logic/digg.rb', line 21 def setup @middle_section = ([current_page - arround_current_page, 1].max..[current_page + arround_current_page, total_pages].min).to_a @first_page_section = (1..[after_first_page, total_pages].min).to_a @last_page_section = ([1, total_pages - after_first_page + 1].max..total_pages).to_a if (total_pages / 2) > current_page merge_left merge_right else merge_right merge_left end end |