Skip to content

Commit

Permalink
move some ActionView hacks back to Renderer class
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda committed Feb 11, 2011
1 parent ad6116b commit 0a80cda
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
23 changes: 17 additions & 6 deletions lib/kaminari/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ def tagify_links #:nodoc:
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:
Expand All @@ -52,6 +49,20 @@ def to_s #:nodoc:
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
Expand Down
12 changes: 1 addition & 11 deletions lib/kaminari/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def to_s(locals = {}) #:nodoc:
# 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}"
Expand All @@ -45,16 +45,6 @@ def find_template(klass = self.class)
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
Expand Down

0 comments on commit 0a80cda

Please sign in to comment.