Class: Webby::Paginator::Page

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/webby/stelan/paginator.rb

Overview

Page object

Retrieves items for a page and provides metadata about the position of the page in the paginator

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Enumerable

#injecting

Constructor Details

- (Page) initialize(pager, number, select)

:nodoc:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/webby/stelan/paginator.rb', line 90

def initialize(pager, number, select) #:nodoc:
  @pager, @number = pager, number
  @offset = (number - 1) * pager.per_page
  @select = select

  @pager.reset
  if number > 1
    if ::Webby.site.create_mode == 'directory'
      @pager.resource['directory'] = File.join(@pager.directory, number.to_s)
    else
      @pager.resource['filename'] = @pager.filename + number.to_s
    end
  end
  @url = @pager.resource.url
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(meth, *args, &block)

:nodoc:



154
155
156
157
158
159
160
# File 'lib/webby/stelan/paginator.rb', line 154

def method_missing(meth, *args, &block) #:nodoc:
  if @pager.respond_to?(meth)
    @pager.__send__(meth, *args, &block)
  else
    super
  end
end

Instance Attribute Details

- (Object) number (readonly)

Returns the value of attribute number



88
89
90
# File 'lib/webby/stelan/paginator.rb', line 88

def number
  @number
end

- (Object) pager (readonly)

Returns the value of attribute pager



88
89
90
# File 'lib/webby/stelan/paginator.rb', line 88

def pager
  @pager
end

- (Object) url (readonly)

Returns the value of attribute url



88
89
90
# File 'lib/webby/stelan/paginator.rb', line 88

def url
  @url
end

Instance Method Details

- (Object) ==(other)

:nodoc:



146
147
148
# File 'lib/webby/stelan/paginator.rb', line 146

def ==(other) #:nodoc:
  @pager == other.pager && self.number == other.number
end

- (Object) each(&block)



150
151
152
# File 'lib/webby/stelan/paginator.rb', line 150

def each(&block)
  items.each(&block)
end

- (Object) first_item_number

The "item number" of the first item on this page



133
134
135
# File 'lib/webby/stelan/paginator.rb', line 133

def first_item_number
  1 + @offset
end

- (Object) items

Retrieve the items for this page

  • Caches



108
109
110
# File 'lib/webby/stelan/paginator.rb', line 108

def items
  @items ||= @select.call
end

- (Object) last_item_number

The "item number" of the last item on this page



138
139
140
141
142
143
144
# File 'lib/webby/stelan/paginator.rb', line 138

def last_item_number
  if next?
    @offset + @pager.per_page
  else
    @pager.count
  end
end

- (Object) next

Get next page (if possible)



128
129
130
# File 'lib/webby/stelan/paginator.rb', line 128

def next
  @pager.page(@number + 1) if next?
end

- (Boolean) next?

Checks to see if there's a page after this one



123
124
125
# File 'lib/webby/stelan/paginator.rb', line 123

def next?
  @number < @pager.number_of_pages
end

- (Object) prev

Get previous page (if possible)



118
119
120
# File 'lib/webby/stelan/paginator.rb', line 118

def prev
  @pager.page(@number - 1) if prev?
end

- (Boolean) prev?

Checks to see if there's a page before this one



113
114
115
# File 'lib/webby/stelan/paginator.rb', line 113

def prev?
  @number > 1
end