move some ActionView hacks back to Renderer class

This commit is contained in:
Akira Matsuda 2011-02-11 15:30:26 +09:00
parent ad6116b817
commit 0a80cda663
2 changed files with 18 additions and 17 deletions

View File

@ -35,12 +35,9 @@ module Kaminari
tags << (num_pages > current_page ? NextLink.new(self) : NextSpan.new(self))
end
def context #:nodoc:
@template.instance_variable_get('@lookup_context')
end
def resolver #:nodoc:
context.instance_variable_get('@view_paths').first
def partial_exists?(name) #:nodoc:
resolver = context.instance_variable_get('@view_paths').first
resolver.find_all(*args_for_lookup(name)).present?
end
def to_s #:nodoc:
@ -52,6 +49,20 @@ module Kaminari
end
private
def context
@template.instance_variable_get('@lookup_context')
end
def args_for_lookup(name)
if (method = context.method :args_for_lookup).arity == 3
# 3.0
method.call name, 'kaminari', true
else
# 3.1
method.call name, 'kaminari', true, []
end
end
def method_missing(meth, *args, &blk)
@template.send meth, *args, &blk
end

View File

@ -36,7 +36,7 @@ module Kaminari
# 2. a template for its parent class from app/views
# 3. the default one inside the engine
def find_template(klass = self.class)
if @renderer.resolver.find_all(*args_for_lookup(klass)).present?
if @renderer.partial_exists? klass.template_filename
"kaminari/#{klass.template_filename}"
elsif (parent = klass.ancestors[1]) == Tag
"kaminari/#{self.class.template_filename}"
@ -45,16 +45,6 @@ module Kaminari
end
end
def args_for_lookup(klass)
if (method = @renderer.context.method :args_for_lookup).arity == 3
# 3.0
method.call klass.template_filename, 'kaminari', true
else
# 3.1
method.call klass.template_filename, 'kaminari', true, []
end
end
def page_url_for(page)
@renderer.url_for @renderer.params.merge(:page => (page <= 1 ? nil : page))
end