Class: DataMapper::Paginator::Main
- Inherits:
-
Object
- Object
- DataMapper::Paginator::Main
- Defined in:
- lib/dm-paginator/main.rb
Overview
Main class, this object handle pagination attributes.
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#next_page ⇒ Object
readonly
Returns the value of attribute next_page.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#page_count ⇒ Object
readonly
Returns the value of attribute page_count.
-
#previous_page ⇒ Object
readonly
Returns the value of attribute previous_page.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Main
constructor
A new instance of Main.
-
#pages(kind, options = {}) ⇒ Object
Get pages range using a pagination control style.
-
#to_html(kind, erb, options = {}) ⇒ String
Draw pagination controls using a partial (whatever erb file).
Constructor Details
#initialize(options = {}) ⇒ Main
Returns a new instance of Main.
10 11 12 13 14 15 16 17 18 |
# File 'lib/dm-paginator/main.rb', line 10 def initialize = {} @count = [:count].to_i @page = [:page].to_i @limit = [:limit].to_i @offset = [:offset].to_i @page_count = calculate_page_count @next_page = page.to_i + 1 unless page.to_i + 1 >= page_count @previous_page = page.to_i - 1 unless page.to_i - 1 <= 1 end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
7 8 9 |
# File 'lib/dm-paginator/main.rb', line 7 def count @count end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
7 8 9 |
# File 'lib/dm-paginator/main.rb', line 7 def limit @limit end |
#next_page ⇒ Object (readonly)
Returns the value of attribute next_page.
7 8 9 |
# File 'lib/dm-paginator/main.rb', line 7 def next_page @next_page end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
7 8 9 |
# File 'lib/dm-paginator/main.rb', line 7 def offset @offset end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
7 8 9 |
# File 'lib/dm-paginator/main.rb', line 7 def page @page end |
#page_count ⇒ Object (readonly)
Returns the value of attribute page_count.
7 8 9 |
# File 'lib/dm-paginator/main.rb', line 7 def page_count @page_count end |
#previous_page ⇒ Object (readonly)
Returns the value of attribute previous_page.
7 8 9 |
# File 'lib/dm-paginator/main.rb', line 7 def previous_page @previous_page end |
Instance Method Details
#pages(kind, options = {}) ⇒ Object
Get pages range using a pagination control style.
44 45 46 47 |
# File 'lib/dm-paginator/main.rb', line 44 def pages kind, = {} control = DataMapper::Paginator::Control.factory self, kind.to_s, control.pages end |
#to_html(kind, erb, options = {}) ⇒ String
Draw pagination controls using a partial (whatever erb file).
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dm-paginator/main.rb', line 27 def to_html kind, erb, = {} if !File.file?( erb ) raise IOError, "erb files doesn't exists" end template = ERB.new File.read( erb ), 0, "%<>" control = DataMapper::Paginator::Control.factory self, kind.to_s, @pages = control.pages template.result binding end |