Class: PaginationScope::Pagination
- Inherits:
-
Struct
- Object
- Struct
- PaginationScope::Pagination
- Defined in:
- lib/pagination_scope.rb,
lib/pagination_scope.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#linker ⇒ Object
Returns the value of attribute linker.
-
#model ⇒ Object
Returns the value of attribute model.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #current ⇒ Object
- #first ⇒ Object
- #first? ⇒ Boolean
- #first_item ⇒ Object
- #inspect ⇒ Object
- #last ⇒ Object
- #last? ⇒ Boolean
- #last_item ⇒ Object
- #left ⇒ Object
- #limit ⇒ Object
- #link(i, *args) ⇒ Object
- #next_label ⇒ Object
- #next_link ⇒ Object
- #offset ⇒ Object
- #page_link ⇒ Object
- #page_link_for(i) ⇒ Object
- #pages ⇒ Object
- #prev_label ⇒ Object
- #prev_link ⇒ Object
- #right ⇒ Object
- #span ⇒ Object
- #to_s(*args) ⇒ Object
- #truncate ⇒ Object
- #window ⇒ Object
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context
57 58 59 |
# File 'lib/pagination_scope.rb', line 57 def context @context end |
#linker ⇒ Object
Returns the value of attribute linker
57 58 59 |
# File 'lib/pagination_scope.rb', line 57 def linker @linker end |
#model ⇒ Object
Returns the value of attribute model
57 58 59 |
# File 'lib/pagination_scope.rb', line 57 def model @model end |
#options ⇒ Object
Returns the value of attribute options
57 58 59 |
# File 'lib/pagination_scope.rb', line 57 def @options end |
Instance Method Details
#current ⇒ Object
62 63 64 |
# File 'lib/pagination_scope.rb', line 62 def current page end |
#first ⇒ Object
74 75 76 |
# File 'lib/pagination_scope.rb', line 74 def first 1 end |
#first? ⇒ Boolean
82 83 84 |
# File 'lib/pagination_scope.rb', line 82 def first? page == 1 end |
#first_item ⇒ Object
66 67 68 |
# File 'lib/pagination_scope.rb', line 66 def first_item offset + 1 end |
#inspect ⇒ Object
176 177 178 179 |
# File 'lib/pagination_scope.rb', line 176 def inspect keys = %w( page count offset limit first last first_item last_item ) "#<Pagination %s>" % keys.map{|key| "#{key}: #{send(key)}"}.join(', ') end |
#last ⇒ Object
78 79 80 |
# File 'lib/pagination_scope.rb', line 78 def last num_pages end |
#last? ⇒ Boolean
86 87 88 |
# File 'lib/pagination_scope.rb', line 86 def last? page == num_pages end |
#last_item ⇒ Object
70 71 72 |
# File 'lib/pagination_scope.rb', line 70 def last_item [offset + limit, count].min end |
#left ⇒ Object
102 103 104 |
# File 'lib/pagination_scope.rb', line 102 def left [:left] || 2 end |
#limit ⇒ Object
94 95 96 |
# File 'lib/pagination_scope.rb', line 94 def limit model.[:limit] end |
#link(i, *args) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/pagination_scope.rb', line 152 def link(i, *args) if linker linker.call(i, *args) else link_to i, url_for(:page => i) end end |
#next_label ⇒ Object
114 115 116 |
# File 'lib/pagination_scope.rb', line 114 def next_label [:next] || 'Next »' end |
#next_link ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/pagination_scope.rb', line 140 def next_link if page < num_pages link_to next_label, url_for(:page => page + 1), :class => :older, :rel => "next" else span.call(next_label) end end |
#offset ⇒ Object
90 91 92 |
# File 'lib/pagination_scope.rb', line 90 def offset model.[:offset] end |
#page_link ⇒ Object
148 149 150 |
# File 'lib/pagination_scope.rb', line 148 def page_link pages.map{|i| page_link_for(i)} end |
#page_link_for(i) ⇒ Object
160 161 162 163 164 165 166 167 168 |
# File 'lib/pagination_scope.rb', line 160 def page_link_for(i) if i.nil? span.call(truncate, [:style]) elsif i == page span.call(i, "#{[:style]} current") else span.call(link(i), [:style]) end end |
#pages ⇒ Object
122 123 124 |
# File 'lib/pagination_scope.rb', line 122 def pages @pages ||= model.pages(window, left, right) end |
#prev_label ⇒ Object
110 111 112 |
# File 'lib/pagination_scope.rb', line 110 def prev_label [:prev] || '« Prev' end |
#prev_link ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/pagination_scope.rb', line 132 def prev_link if page > 1 link_to prev_label, url_for(:page => page - 1), :class => :prev, :rel => "prev" else span.call(prev_label) end end |
#right ⇒ Object
106 107 108 |
# File 'lib/pagination_scope.rb', line 106 def right [:right] || 2 end |
#span ⇒ Object
126 127 128 129 130 |
# File 'lib/pagination_scope.rb', line 126 def span proc do |*args| content_tag(:span, args[0].to_s, :class => (args[1]||"disabled")) end end |
#to_s(*args) ⇒ Object
170 171 172 173 174 |
# File 'lib/pagination_scope.rb', line 170 def to_s(*args) args = [:prev, :page, :next] if args.blank? items = args.map{|i| respond_to?("#{i}_link") ? send("#{i}_link") : []}.flatten content_tag(:div, items.join("\n"), :class => "pagination") end |
#truncate ⇒ Object
118 119 120 |
# File 'lib/pagination_scope.rb', line 118 def truncate [:truncate] || '...' end |
#window ⇒ Object
98 99 100 |
# File 'lib/pagination_scope.rb', line 98 def window [:window] || 5 end |