diff --git a/lib/ramaze/helper/paginate.rb b/lib/ramaze/helper/paginate.rb index 54c70b1a..6891d6f3 100644 --- a/lib/ramaze/helper/paginate.rb +++ b/lib/ramaze/helper/paginate.rb @@ -196,6 +196,7 @@ def needed? # these methods are actually on the pager, but we def them here for # convenience (method_missing in helper is evil and even slower) def page_count ; @pager.page_count ; end + def all ; @pager.all ; end def each(&block); @pager.each(&block); end def first_page? ; @pager.first_page? ; end def prev_page ; @pager.prev_page ; end @@ -276,12 +277,14 @@ def last_page? page_count == @page end - def each(&block) + def all from = ((@page - 1) * @limit) to = from + @limit + @array[from...to] || [] + end - a = @array[from...to] || [] - a.each(&block) + def each(&block) + all.each(&block) end include Enumerable diff --git a/spec/ramaze/helper/paginate.rb b/spec/ramaze/helper/paginate.rb index 6ce02d89..10eb5ad9 100644 --- a/spec/ramaze/helper/paginate.rb +++ b/spec/ramaze/helper/paginate.rb @@ -33,6 +33,11 @@ def iteration out.inspect end + def all + pager = paginate(ALPHA) + pager.all.inspect + end + def preserve_params request.params['single'] = 'zero' request.params['multiple'] = %w[ one two three ] @@ -87,6 +92,11 @@ def preserve_params got.body.scan(/\w+/).should == SpecHelperPaginateArray::ALPHA.first(10) end + it 'returns all the items in the pager range' do + got = get('/array/all') + got.body.scan(/\w+/).should == SpecHelperPaginateArray::ALPHA.first(10) + end + it 'sets default css elements on page 1' do doc = Nokogiri::HTML(get('/array/navigation').body) # Paginator outputs spans for disabled elements