Class: TableMe::TablePagination
- Inherits:
-
Object
- Object
- TableMe::TablePagination
- Defined in:
- lib/table_me/table_pagination.rb
Overview
This handles the pagination elements of the table
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(table_options) ⇒ TablePagination
constructor
A new instance of TablePagination.
- #next_page_url ⇒ Object
-
#pagination_controls ⇒ Object
Adds controls at the bottom of the table for previous and next and a 5 number range TODO Refactor so controllers are hidden when pages on unavailable.
-
#pagination_info ⇒ Object
Information at the top of the table displaying the table name and position page/item wise out of a total.
-
#pagination_number_list ⇒ Object
List of number links for the number range between next and previous.
- #prev_page_url ⇒ Object
Constructor Details
#initialize(table_options) ⇒ TablePagination
Returns a new instance of TablePagination.
9 10 11 |
# File 'lib/table_me/table_pagination.rb', line 9 def initialize self. = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/table_me/table_pagination.rb', line 7 def @options end |
Instance Method Details
#next_page_url ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/table_me/table_pagination.rb', line 35 def next_page_url page = if current_page == total_pages total_pages else current_page + 1 end link_for_page page end |
#pagination_controls ⇒ Object
Adds controls at the bottom of the table for previous and next and a 5 number range TODO Refactor so controllers are hidden when pages on unavailable. IE, if your on page 1 you shouldn’t be able to see a previous button, or if your on the last page you shouldn’t be able to see the next button
27 28 29 30 31 32 33 |
# File 'lib/table_me/table_pagination.rb', line 27 def pagination_controls <<-HTML.strip_heredoc <div class='table-me-pagination-controls'> <a href="#{prev_page_url}" class='previous'>« Prev</a> #{pagination_number_list} <a href="#{next_page_url}" class='next'>Next »</a> </div> HTML end |
#pagination_info ⇒ Object
Information at the top of the table displaying the table name and position page/item wise out of a total.
15 16 17 18 19 20 21 |
# File 'lib/table_me/table_pagination.rb', line 15 def pagination_info <<-HTML.strip_heredoc <div class='table-me-pagination-info'> <h3>#{[:name].split('_').join(' ').titleize}</h3> <p><b>#{[:page]}</b> of <b>#{[:page_total]}</b> out of a total <b>#{[:total_count]}</b></p> </div> HTML end |
#pagination_number_list ⇒ Object
List of number links for the number range between next and previous
56 57 58 59 60 61 |
# File 'lib/table_me/table_pagination.rb', line 56 def pagination_number_list (0...).to_a.map do |n| link_number = n + page_number_offset number_span(link_number) end.join(' ') end |
#prev_page_url ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/table_me/table_pagination.rb', line 45 def prev_page_url page = if current_page == 0 0 else current_page - 1 end link_for_page page end |