Class: Facades::Helpers::Pagination::Paginator
- Inherits:
-
Object
- Object
- Facades::Helpers::Pagination::Paginator
- Defined in:
- lib/facades/helpers/pagination.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Instance Method Summary collapse
- #first? ⇒ Boolean
-
#initialize(collection, view, request) ⇒ Paginator
constructor
A new instance of Paginator.
- #last? ⇒ Boolean
- #link(page_number, attrs = {}, text = nil) ⇒ Object
- #next ⇒ Object
- #paginate!(window) ⇒ Object
- #previous ⇒ Object
Constructor Details
#initialize(collection, view, request) ⇒ Paginator
Returns a new instance of Paginator.
28 29 30 31 32 33 34 |
# File 'lib/facades/helpers/pagination.rb', line 28 def initialize(collection, view, request) @total_pages = collection.total_pages @current_page = collection.current_page @links = [] @template = view @request = request end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
25 26 27 |
# File 'lib/facades/helpers/pagination.rb', line 25 def attributes @attributes end |
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
23 24 25 |
# File 'lib/facades/helpers/pagination.rb', line 23 def current_page @current_page end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
26 27 28 |
# File 'lib/facades/helpers/pagination.rb', line 26 def links @links end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
24 25 26 |
# File 'lib/facades/helpers/pagination.rb', line 24 def total_pages @total_pages end |
Instance Method Details
#first? ⇒ Boolean
42 43 44 |
# File 'lib/facades/helpers/pagination.rb', line 42 def first? current_page == 1 end |
#last? ⇒ Boolean
46 47 48 |
# File 'lib/facades/helpers/pagination.rb', line 46 def last? (current_page == total_pages) end |
#link(page_number, attrs = {}, text = nil) ⇒ Object
58 59 60 61 62 |
# File 'lib/facades/helpers/pagination.rb', line 58 def link(page_number, attrs = {}, text = nil) text ||= page_number = CGI.parse(@request.query_string).merge('page' => page_number) @template.link_to(text.to_s.html_safe, "?#{.to_query}", attrs) end |
#next ⇒ Object
50 51 52 |
# File 'lib/facades/helpers/pagination.rb', line 50 def next links.detect{ |l| l.number == current_page + 1 } end |
#paginate!(window) ⇒ Object
36 37 38 39 40 |
# File 'lib/facades/helpers/pagination.rb', line 36 def paginate!(window) window.each do |page| @links << PageLink.new(page, (page == current_page)) end end |
#previous ⇒ Object
54 55 56 |
# File 'lib/facades/helpers/pagination.rb', line 54 def previous links.detect{ |l| l.number == current_page - 1 } end |