Class: DatePaginate::Helpers::Paginator
- Inherits:
-
Object
- Object
- DatePaginate::Helpers::Paginator
show all
- Includes:
- ActionView::Context
- Defined in:
- lib/date_paginate/helpers/paginator.rb
Constant Summary
collapse
- PARAM_KEY_BLACKLIST =
:authenticity_token, :commit, :utf8, :_method
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(template, options) ⇒ Paginator
Returns a new instance of Paginator.
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/date_paginate/helpers/paginator.rb', line 16
def initialize(template, options)
options[:num_pages] ||= DatePaginate.config.default_num_pages
unless options[:date_paginate_type].in? self.class.paginate_type_list
options[:date_paginate_type] = DatePaginate.config.default_paginate_type
end
@template, @options = template, options
@date_paginate_type = @options.delete(:date_paginate_type)
@num_pages = @options.delete(:num_pages)
@options["recent_#{@date_paginate_type}".to_sym] = send("recent_#{@date_paginate_type}")
@params = template.params.except(*PARAM_KEY_BLACKLIST).merge(@options.delete(:params) || {})
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
delegates view helper methods to @template
53
54
55
|
# File 'lib/date_paginate/helpers/paginator.rb', line 53
def method_missing(name, *args, &block)
@template.respond_to?(name) ? @template.send(name, *args, &block) : super
end
|
Class Method Details
.paginate_type_list ⇒ Object
12
13
14
|
# File 'lib/date_paginate/helpers/paginator.rb', line 12
def self.paginate_type_list
[:days, :weeks, :months]
end
|
Instance Method Details
#partial_path ⇒ Object
45
46
47
48
49
50
|
# File 'lib/date_paginate/helpers/paginator.rb', line 45
def partial_path
[
"date_paginate",
"paginate_#{@date_paginate_type}",
].compact.join("/")
end
|
#to_s(locals = {}) ⇒ Object
58
59
60
61
|
# File 'lib/date_paginate/helpers/paginator.rb', line 58
def to_s(locals = {})
locals = @options.merge(params: @params).merge(locals)
@template.render :partial => partial_path, :locals => locals, :formats => [:html]
end
|