Class: MerbPaginate::LinkRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/merb_paginate/view_helpers.rb

Overview

Copied mostly from will_paginate, but changed to work with the merb url helpers

Instance Method Summary collapse

Constructor Details

#initialize(collection, options, template) ⇒ LinkRenderer

Returns a new instance of LinkRenderer.



151
152
153
154
155
# File 'lib/merb_paginate/view_helpers.rb', line 151

def initialize(collection, options, template)
  @collection = collection
  @options    = options
  @template   = template
end

Instance Method Details

#html_attributesObject



167
168
169
170
171
172
173
174
175
# File 'lib/merb_paginate/view_helpers.rb', line 167

def html_attributes
  return @html_attributes if @html_attributes
  @html_attributes = @options.except *(MerbPaginate::ViewHelpers.pagination_options.keys - [:class])
  # pagination of Post models will have the ID of "posts_pagination"
  if @options[:container] and @options[:id] === true
    @html_attributes[:id] = @collection.first.class.name.underscore.pluralize + '_pagination'
  end
  @html_attributes
end

#html_attributes_stringObject



177
178
179
180
181
182
183
184
185
# File 'lib/merb_paginate/view_helpers.rb', line 177

def html_attributes_string
  string = ""
  if html_attributes
    html_attributes.each do |key, value|
      string << " #{key}='#{value}'"
    end
  end
  string
end

#to_htmlObject



157
158
159
160
161
162
163
164
165
# File 'lib/merb_paginate/view_helpers.rb', line 157

def to_html
  links = @options[:page_links] ? windowed_links : []
  # previous/next buttons
  links.unshift page_link_or_span(@collection.previous_page, 'disabled', @options[:prev_label])
  links.push    page_link_or_span(@collection.next_page,     'disabled', @options[:next_label])
  
  html = links.join(@options[:separator])
  @options[:container] ? "<div#{html_attributes_string}>#{html}</div>" : html
end