Skip to content

Commit

Permalink
enh(): paginate_tag
Browse files Browse the repository at this point in the history
  • Loading branch information
chamnap committed Mar 8, 2016
1 parent 84616a2 commit 23abfe2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/liquid-rails/tags/paginate_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def render(context)
@context = context

context.stack do
collection = context[@collection_name]
raise ::Liquid::ArgumentError.new("Cannot paginate array '#{@collection_name}'. Not found.") if collection.nil?
collection = @context[@collection_name].presence || @context.environments[0][@collection_name]
raise ::Liquid::ArgumentError.new("Cannot paginate collection '#{@collection_name}'. Not found.") if collection.nil?

if collection.is_a? Array
paginated_collection = Kaminari.paginate_array(collection.to_a).page(current_page).per(@page_size)
elsif collection.respond_to?(:page) && collection.respond_to?(:per)
elsif collection.respond_to?(:page)
paginated_collection = collection.page(current_page).per(@page_size)
end

Expand Down

0 comments on commit 23abfe2

Please sign in to comment.