Class: Facades::Helpers::Pagination::Paginator

Inherits:
Object
  • Object
show all
Defined in:
lib/facades/helpers/pagination.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject (readonly)

Returns the value of attribute attributes.



25
26
27
# File 'lib/facades/helpers/pagination.rb', line 25

def attributes
  @attributes
end

#current_pageObject (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

Returns the value of attribute links.



26
27
28
# File 'lib/facades/helpers/pagination.rb', line 26

def links
  @links
end

#total_pagesObject (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

Returns:

  • (Boolean)


42
43
44
# File 'lib/facades/helpers/pagination.rb', line 42

def first?
  current_page == 1
end

#last?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/facades/helpers/pagination.rb', line 46

def last?
  (current_page == total_pages)
end


58
59
60
61
62
# File 'lib/facades/helpers/pagination.rb', line 58

def link(page_number, attrs = {}, text = nil)
  text ||= page_number
  options = CGI.parse(@request.query_string).merge('page' => page_number)
  @template.link_to(text.to_s.html_safe, "?#{options.to_query}", attrs)
end

#nextObject



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

#previousObject



54
55
56
# File 'lib/facades/helpers/pagination.rb', line 54

def previous
  links.detect{ |l| l.number == current_page - 1 }          
end