Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove bundled will_paginate

  • Loading branch information...
commit 162d7918dba0d344afc2fa4891c7c79b15a8f96d 1 parent 6f3bedf
@lifo lifo authored
Showing with 0 additions and 3,478 deletions.
  1. +0 −5 init.rb
  2. +0 −4 vendor/plugins/will_paginate/.gitignore
  3. +0 −105 vendor/plugins/will_paginate/CHANGELOG.rdoc
  4. +0 −14 vendor/plugins/will_paginate/Gemfile
  5. +0 −18 vendor/plugins/will_paginate/LICENSE
  6. +0 −125 vendor/plugins/will_paginate/README.rdoc
  7. +0 −32 vendor/plugins/will_paginate/Rakefile
  8. +0 −1  vendor/plugins/will_paginate/init.rb
  9. +0 −23 vendor/plugins/will_paginate/lib/will_paginate.rb
  10. +0 −33 vendor/plugins/will_paginate/lib/will_paginate/array.rb
  11. +0 −145 vendor/plugins/will_paginate/lib/will_paginate/collection.rb
  12. +0 −69 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
  13. +0 −50 vendor/plugins/will_paginate/lib/will_paginate/deprecation.rb
  14. +0 −9 vendor/plugins/will_paginate/lib/will_paginate/finders.rb
  15. +0 −158 vendor/plugins/will_paginate/lib/will_paginate/finders/active_record.rb
  16. +0 −51 vendor/plugins/will_paginate/lib/will_paginate/finders/active_resource.rb
  17. +0 −112 vendor/plugins/will_paginate/lib/will_paginate/finders/base.rb
  18. +0 −30 vendor/plugins/will_paginate/lib/will_paginate/finders/data_mapper.rb
  19. +0 −23 vendor/plugins/will_paginate/lib/will_paginate/finders/sequel.rb
  20. +0 −24 vendor/plugins/will_paginate/lib/will_paginate/railtie.rb
  21. +0 −9 vendor/plugins/will_paginate/lib/will_paginate/version.rb
  22. +0 −42 vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb
  23. +0 −134 vendor/plugins/will_paginate/lib/will_paginate/view_helpers/action_view.rb
  24. +0 −126 vendor/plugins/will_paginate/lib/will_paginate/view_helpers/base.rb
  25. +0 −130 vendor/plugins/will_paginate/lib/will_paginate/view_helpers/link_renderer.rb
  26. +0 −83 vendor/plugins/will_paginate/lib/will_paginate/view_helpers/link_renderer_base.rb
  27. +0 −13 vendor/plugins/will_paginate/lib/will_paginate/view_helpers/merb.rb
  28. +0 −147 vendor/plugins/will_paginate/spec/collection_spec.rb
  29. +0 −8 vendor/plugins/will_paginate/spec/console
  30. +0 −8 vendor/plugins/will_paginate/spec/console_fixtures.rb
  31. +0 −22 vendor/plugins/will_paginate/spec/database.yml
  32. +0 −377 vendor/plugins/will_paginate/spec/finders/active_record_spec.rb
  33. +0 −52 vendor/plugins/will_paginate/spec/finders/active_resource_spec.rb
  34. +0 −114 vendor/plugins/will_paginate/spec/finders/activerecord_test_connector.rb
  35. +0 −62 vendor/plugins/will_paginate/spec/finders/data_mapper_spec.rb
  36. +0 −20 vendor/plugins/will_paginate/spec/finders/data_mapper_test_connector.rb
  37. +0 −53 vendor/plugins/will_paginate/spec/finders/sequel_spec.rb
  38. +0 −9 vendor/plugins/will_paginate/spec/finders/sequel_test_connector.rb
  39. +0 −76 vendor/plugins/will_paginate/spec/finders_spec.rb
  40. +0 −3  vendor/plugins/will_paginate/spec/fixtures/admin.rb
  41. +0 −13 vendor/plugins/will_paginate/spec/fixtures/developer.rb
  42. +0 −13 vendor/plugins/will_paginate/spec/fixtures/developers_projects.yml
  43. +0 −13 vendor/plugins/will_paginate/spec/fixtures/project.rb
  44. +0 −6 vendor/plugins/will_paginate/spec/fixtures/projects.yml
  45. +0 −29 vendor/plugins/will_paginate/spec/fixtures/replies.yml
  46. +0 −7 vendor/plugins/will_paginate/spec/fixtures/reply.rb
  47. +0 −38 vendor/plugins/will_paginate/spec/fixtures/schema.rb
  48. +0 −7 vendor/plugins/will_paginate/spec/fixtures/topic.rb
  49. +0 −30 vendor/plugins/will_paginate/spec/fixtures/topics.yml
  50. +0 −2  vendor/plugins/will_paginate/spec/fixtures/user.rb
  51. +0 −35 vendor/plugins/will_paginate/spec/fixtures/users.yml
  52. +0 −2  vendor/plugins/will_paginate/spec/rcov.opts
  53. +0 −2  vendor/plugins/will_paginate/spec/spec.opts
  54. +0 −74 vendor/plugins/will_paginate/spec/spec_helper.rb
  55. +0 −60 vendor/plugins/will_paginate/spec/tasks.rake
  56. +0 −356 vendor/plugins/will_paginate/spec/view_helpers/action_view_spec.rb
  57. +0 −64 vendor/plugins/will_paginate/spec/view_helpers/base_spec.rb
  58. +0 −84 vendor/plugins/will_paginate/spec/view_helpers/link_renderer_base_spec.rb
  59. +0 −103 vendor/plugins/will_paginate/spec/view_helpers/view_example_group.rb
  60. +0 −21 vendor/plugins/will_paginate/will_paginate.gemspec
View
5 init.rb
@@ -1,10 +1,5 @@
Mime::Type.register_alias "text/yaml", :yml
-will_paginate = File.join(File.dirname(__FILE__), 'vendor/plugins/will_paginate')
-$: << File.join(will_paginate, 'lib')
-
-require File.join(will_paginate, 'init')
-
$KCODE = 'UTF8'
begin
require 'ya2yaml'
View
4 vendor/plugins/will_paginate/.gitignore
@@ -1,4 +0,0 @@
-.bundle
-doc
-*.gem
-coverage
View
105 vendor/plugins/will_paginate/CHANGELOG.rdoc
@@ -1,105 +0,0 @@
-== "agnostic" branch
-
-* added Sequel support
-* added an initialization hook for Merb
-* refactored URL generation
-* BACKWARDS INCOMPATIBLE: refactored LinkRenderer; also markup changes
- <span class="current">1</span> is now <em>1</em>
- a.prev_page -> a.previous_page (for consistency)
-* "prev_label" -> "previous_label"
-* ported view tests to specs
-* setup Autotest
-* added per_page=(limit) attribute writer to set default per_page
-* Remove :include option from count_all query when possible (Rails 2.1)
-* added WP::ViewHelpers::ActionView and LinkRenderer
-* specs for ViewHelpers::Base and LinkRendererBase
-* created LinkRendererBase that implements windowed visible page numbers logic
-* created WP::ViewHelpers::Base abstract module that implements generic view helpers
-* ported finder tests to specs
-* added WP::Finders::DataMapper
-* added WP::Finders::ActiveRecord mixin for ActiveRecord::Base
-* created WP::Finders::Base abstract module that implements generic pagination logic
-* removed dependency to ActiveSupport
-
-== 2.3.1, released 2008-05-04
-
-* Fixed page numbers not showing with custom routes and implicit first page
-* Try to use Hanna for documentation (falls back to default RDoc template if not)
-
-== 2.3.0, released 2008-04-29
-
-* Changed LinkRenderer to receive collection, options and reference to view template NOT in
- constructor, but with the #prepare method. This is a step towards supporting passing of
- LinkRenderer (or subclass) instances that may be preconfigured in some way
-* LinkRenderer now has #page_link and #page_span methods for easier customization of output in
- subclasses
-* Changed page_entries_info() method to adjust its output according to humanized class name of
- collection items. Override this with :entry_name parameter (singular).
-
- page_entries_info(@posts)
- #-> "Displaying all 12 posts"
- page_entries_info(@posts, :entry_name => 'item')
- #-> "Displaying all 12 items"
-
-== 2.2.3, released 2008-04-26
-
-* will_paginate gem is no longer published on RubyForge, but on
- gems.github.com:
-
- gem sources -a http://gems.github.com/ (you only need to do this once)
- gem install mislav-will_paginate
-
-* extract reusable pagination testing stuff into WillPaginate::View
-* rethink the page URL construction mechanism to be more bulletproof when
- combined with custom routing for page parameter
-* test that anchor parameter can be used in pagination links
-
-== 2.2.2, released 2008-04-21
-
-* Add support for page parameter in custom routes like "/foo/page/2"
-* Change output of "page_entries_info" on single-page collection and erroneous
- output with empty collection as reported by Tim Chater
-
-== 2.2.1, released 2008-04-08
-
-* take less risky path when monkeypatching named_scope; fix that it no longer
- requires ActiveRecord::VERSION
-* use strings in "respond_to?" calls to work around a bug in acts_as_ferret
- stable (ugh)
-* add rake release task
-
-
-== 2.2.0, released 2008-04-07
-
-=== API changes
-* Rename WillPaginate::Collection#page_count to "total_pages" for consistency.
- If you implemented this interface, change your implementation accordingly.
-* Remove old, deprecated style of calling Array#paginate as "paginate(page,
- per_page)". If you want to specify :page, :per_page or :total_entries, use a
- parameter hash.
-* Rename LinkRenderer#url_options to "url_for" and drastically optimize it
-
-=== View changes
-* Added "prev_page" and "next_page" CSS classes on previous/next page buttons
-* Add examples of pagination links styling in "examples/index.html"
-* Change gap in pagination links from "..." to
- "<span class="gap">&hellip;</span>".
-* Add "paginated_section", a block helper that renders pagination both above and
- below content in the block
-* Add rel="prev|next|start" to page links
-
-=== Other
-
-* Add ability to opt-in for Rails 2.1 feature "named_scope" by calling
- WillPaginate.enable_named_scope (tested in Rails 1.2.6 and 2.0.2)
-* Support complex page parameters like "developers[page]"
-* Move Array#paginate definition to will_paginate/array.rb. You can now easily
- use pagination on arrays outside of Rails:
-
- gem 'will_paginate'
- require 'will_paginate/array'
-
-* Add "paginated_each" method for iterating through every record by loading only
- one page of records at the time
-* Rails 2: Rescue from WillPaginate::InvalidPage error with 404 Not Found by
- default
View
14 vendor/plugins/will_paginate/Gemfile
@@ -1,14 +0,0 @@
-git 'git://github.com/rails/rails.git'
-source :gemcutter
-
-gem 'activerecord', '~> 3.0.0.beta3'
-gem 'activeresource', '~> 3.0.0.beta3'
-gem 'actionpack', '~> 3.0.0.beta3'
-gem 'sequel', '~> 3.8.0'
-gem 'rspec', '~> 1.3.0'
-gem 'mocha', '~> 0.9.8'
-gem 'sqlite3-ruby', '~> 1.2.5'
-gem 'dm-core', '~> 0.10.2'
-gem 'do_sqlite3', '~> 0.10.1.1'
-gem 'mysql', '~> 2.8.1'
-gem 'pg', '~> 0.8.0'
View
18 vendor/plugins/will_paginate/LICENSE
@@ -1,18 +0,0 @@
-Copyright (c) 2009 Mislav Marohnić
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
125 vendor/plugins/will_paginate/README.rdoc
@@ -1,125 +0,0 @@
-= The will_paginate Ruby library
-
-Pagination is just limiting the number of records loaded and displayed. Why should you let it get in
-your way while developing?
-
-This is how you paginate on an ActiveRecord model:
-
- Post.paginate :page => 1, :order => 'created_at DESC'
-
-Most of the time it's as simple as replacing "find" with "paginate" and specifying the page you want.
-
-Some resources to get you started:
-
-* The {will_paginate project page}[http://mislav.github.com/will_paginate/];
-* Your mind reels with questions? Join our {Google group}[http://groups.google.com/group/will_paginate];
-* {How to report bugs}[http://github.com/mislav/will_paginate/wikis/report-bugs];
-* {Watch the will_paginate screencast}[http://railscasts.com/episodes/51] by Ryan Bates.
-
-== I'm not using Rails; can I still use will_paginate?
-
-Absolutely -- although will_paginate started off as a Rails plugin, now it is a <em>completely
-framework-agnostic</em> library with support for Rails and Merb built-in. The core library doesn't
-have any dependences and you can safely use it in any Ruby code.
-
-When will_paginate is loaded in an environment where ActiveRecord and ActionView are present, it
-automatically hooks into these frameworks to provide easy pagination on your models and in your
-views. The same mechanism works for Merb applications, too. But, if no known framework is present
-then you have absolute control over what parts of will_paginate do you want to load and where you want
-them mixed in.
-
-
-== Installation
-
-The recommended way is that you get the gem hosted on {gems.github.com}[http://gems.github.com/]:
-
- gem install mislav-will_paginate
-
-In <b>Rails 2.1</b>, add a gem dependency:
-
- # for Rails 2.1 and newer
- config.gem 'mislav-will_paginate', :lib => 'will_paginate', :version => '~> 3.0'
-
-If you're using Rails 2.0 or older, or any other Ruby framework, just add a simple require to a file
-that initializes your application. For example, in Rails you would put this at the end of
-"config/environment.rb".
-
- gem 'mislav-will_paginate', '~> 3.0'
- require 'will_paginate'
-
-That's it. Remember to install the gem on <strong>all</strong> machines that you are deploying to.
-
-<i>There are extensive {installation
-instructions}[http://github.com/mislav/will_paginate/wikis/installation] on {the
-wiki}[http://github.com/mislav/will_paginate/wikis].</i>
-
-
-== Example usage
-
-Typical usage involves a paginating find in the controller:
-
- @posts = Post.paginate :page => params[:page], :order => 'updated_at DESC'
-
-It's true: +paginate+ works just like +find+ -- it just doesn't fetch all the records. Don't forget
-to tell it which page you want, or it will complain! Read more in WillPaginate::Finders.
-
-Render the posts in your view like you would normally do, and when you need to render pagination,
-just stick this in:
-
- <%= will_paginate @posts %>
-
-You're done. Read more in WillPaginate::ViewHelpers::Base.
-
-How does it know how much items to fetch per page? It asks your model by calling its
-+per_page+ class method. You can define it like this:
-
- class Post < ActiveRecord::Base
- self.per_page = 50
- end
-
-... or don't worry about it at all. WillPaginate defines it to be <strong>30</strong> by default. You can
-always specify the count explicitly when calling +paginate+:
-
- Post.paginate :page => params[:page], :per_page => 50
-
-The +paginate+ finder wraps the original finder and returns your result set that now has some new
-properties. You can use the collection as you would use any other array. WillPaginate view helpers
-also need that collection object to be able to render pagination:
-
- <ol>
- <% for post in @posts -%>
- <li>Render `post` in some nice way.</li>
- <% end -%>
- </ol>
-
- <p>Now let's render us some pagination!</p>
- <%= will_paginate @posts %>
-
-
-== Authors and credits
-
-The original author of will_paginate was PJ Hyett, who later handed over development to Mislav
-Marohnić. (The library was completely rewritten since then.)
-
-All these people helped making will_paginate what it is now with their code contributions or just
-simply awesome ideas:
-
-Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence Golda, Matt Aimonetti,
-Charles Brian Quinn, Desi McAdam, James Coglan, Matijs van Zuijlen, Maria, Brendan Ribera, Todd
-Willey, Bryan Helmkamp, Jan Berkel, Lourens Naudé, Rick Olson, Russell Norris, Piotr Usewicz, Chris
-Eppstein, Brandon Arbini, Denis Barushev, Paul Barry, Ben Pickles, Ken Collins, Lida Tang and Pieter
-Noordhuis.
-
-
-== Usable pagination in the UI
-
-There are example CSS styles to get you started on the will_paginate project page.
-
-More reading about pagination as design pattern:
-
-* {Pagination 101}[http://kurafire.net/log/archive/2007/06/22/pagination-101];
-* {Pagination gallery}[http://www.smashingmagazine.com/2007/11/16/pagination-gallery-examples-and-good-practices/] featured on Smashing Magazine;
-* {Pagination design pattern}[http://developer.yahoo.com/ypatterns/parent.php?pattern=pagination] on Yahoo Design Pattern Library.
-
-Want to discuss, request features, ask questions? Join the {Google
-group}[http://groups.google.com/group/will_paginate].
View
32 vendor/plugins/will_paginate/Rakefile
@@ -1,32 +0,0 @@
-require 'rake/rdoctask'
-
-load 'spec/tasks.rake'
-
-desc 'Default: run specs.'
-task :default => :spec
-
-desc 'Generate RDoc documentation for the will_paginate plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'CHANGELOG.rdoc').
- include('lib/**/*.rb').
- exclude('lib/will_paginate/finders/active_record/named_scope*').
- exclude('lib/will_paginate/finders/sequel.rb').
- exclude('lib/will_paginate/view_helpers/merb.rb').
- exclude('lib/will_paginate/deprecation.rb').
- exclude('lib/will_paginate/core_ext.rb').
- exclude('lib/will_paginate/version.rb')
-
- rdoc.main = "README.rdoc" # page to start on
- rdoc.title = "will_paginate documentation"
-
- rdoc.rdoc_dir = 'doc' # rdoc output folder
- rdoc.options << '--inline-source' << '--charset=UTF-8'
- rdoc.options << '--webcvs=http://github.com/mislav/will_paginate/tree/master/'
-end
-
-task :website do
- Dir.chdir('website') do
- %x(haml index.haml index.html)
- %x(sass pagination.sass pagination.css)
- end
-end
View
1  vendor/plugins/will_paginate/init.rb
@@ -1 +0,0 @@
-require 'will_paginate'
View
23 vendor/plugins/will_paginate/lib/will_paginate.rb
@@ -1,23 +0,0 @@
-require 'will_paginate/deprecation'
-
-# = You *will* paginate!
-#
-# First read about WillPaginate::Finders::Base, then see
-# WillPaginate::ViewHelpers. The magical array you're handling in-between is
-# WillPaginate::Collection.
-#
-# Happy paginating!
-module WillPaginate
-end
-
-if defined?(::Rails::Railtie)
- require 'will_paginate/railtie'
-end
-
-if defined?(::Merb::Plugins)
- require 'will_paginate/view_helpers/merb'
- # auto-load the right ORM adapter
- if adapter = { :datamapper => 'data_mapper', :activerecord => 'active_record', :sequel => 'sequel' }[Merb.orm]
- require "will_paginate/finders/#{adapter}"
- end
-end
View
33 vendor/plugins/will_paginate/lib/will_paginate/array.rb
@@ -1,33 +0,0 @@
-require 'will_paginate/collection'
-
-class Array
- # Paginates a static array (extracting a subset of it). The result is a
- # WillPaginate::Collection instance, which is an array with a few more
- # properties about its paginated state.
- #
- # Parameters:
- # * <tt>:page</tt> - current page, defaults to 1
- # * <tt>:per_page</tt> - limit of items per page, defaults to 30
- # * <tt>:total_entries</tt> - total number of items in the array, defaults to
- # <tt>array.length</tt> (obviously)
- #
- # Example:
- # arr = ['a', 'b', 'c', 'd', 'e']
- # paged = arr.paginate(:per_page => 2) #-> ['a', 'b']
- # paged.total_entries #-> 5
- # arr.paginate(:page => 2, :per_page => 2) #-> ['c', 'd']
- # arr.paginate(:page => 3, :per_page => 2) #-> ['e']
- #
- # This method was originally {suggested by Desi
- # McAdam}[http://www.desimcadam.com/archives/8] and later proved to be the
- # most useful method of will_paginate library.
- def paginate(options = {})
- raise ArgumentError, "parameter hash expected (got #{options.inspect})" unless Hash === options
-
- WillPaginate::Collection.create options[:page] || 1,
- options[:per_page] || 30,
- options[:total_entries] || self.length do |pager|
- pager.replace self[pager.offset, pager.per_page].to_a
- end
- end
-end
View
145 vendor/plugins/will_paginate/lib/will_paginate/collection.rb
@@ -1,145 +0,0 @@
-module WillPaginate
- # = Invalid page number error
- # This is an ArgumentError raised in case a page was requested that is either
- # zero or negative number. You should decide how do deal with such errors in
- # the controller.
- #
- # If you're using Rails 2, then this error will automatically get handled like
- # 404 Not Found. The hook is in "will_paginate.rb":
- #
- # ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] = :not_found
- #
- # If you don't like this, use your preffered method of rescuing exceptions in
- # public from your controllers to handle this differently. The +rescue_from+
- # method is a nice addition to Rails 2.
- #
- # This error is *not* raised when a page further than the last page is
- # requested. Use <tt>WillPaginate::Collection#out_of_bounds?</tt> method to
- # check for those cases and manually deal with them as you see fit.
- class InvalidPage < ArgumentError
- def initialize(page, page_num) #:nodoc:
- super "#{page.inspect} given as value, which translates to '#{page_num}' as page number"
- end
- end
-
- # = The key to pagination
- # Arrays returned from paginating finds are, in fact, instances of this little
- # class. You may think of WillPaginate::Collection as an ordinary array with
- # some extra properties. Those properties are used by view helpers to generate
- # correct page links.
- #
- # WillPaginate::Collection also assists in rolling out your own pagination
- # solutions: see +create+.
- #
- # If you are writing a library that provides a collection which you would like
- # to conform to this API, you don't have to copy these methods over; simply
- # make your plugin/gem dependant on the "will_paginate" gem:
- #
- # gem 'will_paginate'
- # require 'will_paginate/collection'
- #
- # # now use WillPaginate::Collection directly or subclass it
- class Collection < Array
- attr_reader :current_page, :per_page, :total_entries, :total_pages
-
- # Arguments to the constructor are the current page number, per-page limit
- # and the total number of entries. The last argument is optional because it
- # is best to do lazy counting; in other words, count *conditionally* after
- # populating the collection using the +replace+ method.
- def initialize(page, per_page, total = nil)
- @current_page = page.to_i
- raise InvalidPage.new(page, @current_page) if @current_page < 1
- @per_page = per_page.to_i
- raise ArgumentError, "`per_page` setting cannot be less than 1 (#{@per_page} given)" if @per_page < 1
-
- self.total_entries = total if total
- end
-
- # Just like +new+, but yields the object after instantiation and returns it
- # afterwards. This is very useful for manual pagination:
- #
- # @entries = WillPaginate::Collection.create(1, 10) do |pager|
- # result = Post.find(:all, :limit => pager.per_page, :offset => pager.offset)
- # # inject the result array into the paginated collection:
- # pager.replace(result)
- #
- # unless pager.total_entries
- # # the pager didn't manage to guess the total count, do it manually
- # pager.total_entries = Post.count
- # end
- # end
- #
- # The possibilities with this are endless. For another example, here is how
- # WillPaginate used to define pagination for Array instances:
- #
- # Array.class_eval do
- # def paginate(page = 1, per_page = 15)
- # WillPaginate::Collection.create(page, per_page, size) do |pager|
- # pager.replace self[pager.offset, pager.per_page].to_a
- # end
- # end
- # end
- #
- # The Array#paginate API has since then changed, but this still serves as a
- # fine example of WillPaginate::Collection usage.
- def self.create(page, per_page, total = nil, &block)
- pager = new(page, per_page, total)
- yield pager
- pager
- end
-
- # Helper method that is true when someone tries to fetch a page with a
- # larger number than the last page. Can be used in combination with flashes
- # and redirecting.
- def out_of_bounds?
- current_page > total_pages
- end
-
- # Current offset of the paginated collection. If we're on the first page,
- # it is always 0. If we're on the 2nd page and there are 30 entries per page,
- # the offset is 30. This property is useful if you want to render ordinals
- # besides your records: simply start with offset + 1.
- def offset
- (current_page - 1) * per_page
- end
-
- # current_page - 1 or nil if there is no previous page
- def previous_page
- current_page > 1 ? (current_page - 1) : nil
- end
-
- # current_page + 1 or nil if there is no next page
- def next_page
- current_page < total_pages ? (current_page + 1) : nil
- end
-
- def total_entries=(number)
- @total_entries = number.to_i
- @total_pages = (@total_entries / per_page.to_f).ceil
- end
-
- # This is a magic wrapper for the original Array#replace method. It serves
- # for populating the paginated collection after initialization.
- #
- # Why magic? Because it tries to guess the total number of entries judging
- # by the size of given array. If it is shorter than +per_page+ limit, then we
- # know we're on the last page. This trick is very useful for avoiding
- # unnecessary hits to the database to do the counting after we fetched the
- # data for the current page.
- #
- # However, after using +replace+ you should always test the value of
- # +total_entries+ and set it to a proper value if it's +nil+. See the example
- # in +create+.
- def replace(array)
- result = super
-
- # The collection is shorter then page limit? Rejoice, because
- # then we know that we are on the last page!
- if total_entries.nil? and length < per_page and (current_page == 1 or length > 0)
- self.total_entries = offset + length
- end
-
- result
- end
- end
-end
View
69 vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
@@ -1,69 +0,0 @@
-require 'set'
-require 'will_paginate/array'
-
-# helper to check for method existance in ruby 1.8- and 1.9-compatible way
-# because `methods`, `instance_methods` and others return strings in 1.8 and symbols in 1.9
-#
-# ['foo', 'bar'].include_method?(:foo) # => true
-class Array
- def include_method?(name)
- name = name.to_sym
- !!(find { |item| item.to_sym == name })
- end
-end
-
-## everything below copied from ActiveSupport so we don't depend on it ##
-
-unless Hash.instance_methods.include_method? :except
- Hash.class_eval do
- # Returns a new hash without the given keys.
- def except(*keys)
- rejected = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
- reject { |key,| rejected.include?(key) }
- end
-
- # Replaces the hash without only the given keys.
- def except!(*keys)
- replace(except(*keys))
- end
- end
-end
-
-unless Hash.instance_methods.include_method? :slice
- Hash.class_eval do
- # Returns a new hash with only the given keys.
- def slice(*keys)
- allowed = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
- reject { |key,| !allowed.include?(key) }
- end
-
- # Replaces the hash with only the given keys.
- def slice!(*keys)
- replace(slice(*keys))
- end
- end
-end
-
-unless String.instance_methods.include_method? :constantize
- String.class_eval do
- def constantize
- unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
- raise NameError, "#{self.inspect} is not a valid constant name!"
- end
-
- Object.module_eval("::#{$1}", __FILE__, __LINE__)
- end
- end
-end
-
-unless String.instance_methods.include_method? :underscore
- String.class_eval do
- def underscore
- self.to_s.gsub(/::/, '/').
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
- tr("-", "_").
- downcase
- end
- end
-end
View
50 vendor/plugins/will_paginate/lib/will_paginate/deprecation.rb
@@ -1,50 +0,0 @@
-# borrowed from ActiveSupport::Deprecation
-module WillPaginate
- module Deprecation
- def self.debug() @debug; end
- def self.debug=(value) @debug = value; end
- self.debug = false
-
- # Choose the default warn behavior according to Rails.env.
- # Ignore deprecation warnings in production.
- BEHAVIORS = {
- 'test' => Proc.new { |message, callstack|
- $stderr.puts(message)
- $stderr.puts callstack.join("\n ") if debug
- },
- 'development' => Proc.new { |message, callstack|
- logger = defined?(::RAILS_DEFAULT_LOGGER) ? ::RAILS_DEFAULT_LOGGER : Logger.new($stderr)
- logger.warn message
- logger.debug callstack.join("\n ") if debug
- }
- }
-
- def self.warn(message, callstack = caller)
- if behavior
- message = 'WillPaginate: ' + message.strip.gsub(/\s+/, ' ')
- behavior.call(message, callstack)
- end
- end
-
- def self.default_behavior
- if defined?(::Rails)
- BEHAVIORS[::Rails.env.to_s]
- else
- BEHAVIORS['test']
- end
- end
-
- # Behavior is a block that takes a message argument.
- def self.behavior() @behavior; end
- def self.behavior=(value) @behavior = value; end
- self.behavior = default_behavior
-
- def self.silence
- old_behavior = self.behavior
- self.behavior = nil
- yield
- ensure
- self.behavior = old_behavior
- end
- end
-end
View
9 vendor/plugins/will_paginate/lib/will_paginate/finders.rb
@@ -1,9 +0,0 @@
-require 'will_paginate/core_ext'
-
-module WillPaginate
- # Database logic for different ORMs
- #
- # See WillPaginate::Finders::Base
- module Finders
- end
-end
View
158 vendor/plugins/will_paginate/lib/will_paginate/finders/active_record.rb
@@ -1,158 +0,0 @@
-require 'will_paginate/finders/base'
-require 'active_record'
-
-module WillPaginate::Finders
- # = Paginating finders for ActiveRecord models
- #
- # WillPaginate adds +paginate+, +per_page+ and other methods to
- # ActiveRecord::Base class methods and associations. It also hooks into
- # +method_missing+ to intercept pagination calls to dynamic finders such as
- # +paginate_by_user_id+ and translate them to ordinary finders
- # (+find_all_by_user_id+ in this case).
- #
- # In short, paginating finders are equivalent to ActiveRecord finders; the
- # only difference is that we start with "paginate" instead of "find" and
- # that <tt>:page</tt> is required parameter:
- #
- # @posts = Post.paginate :all, :page => params[:page], :order => 'created_at DESC'
- #
- # In paginating finders, "all" is implicit. There is no sense in paginating
- # a single record, right? So, you can drop the <tt>:all</tt> argument:
- #
- # Post.paginate(...) => Post.find :all
- # Post.paginate_all_by_something => Post.find_all_by_something
- # Post.paginate_by_something => Post.find_all_by_something
- #
- module ActiveRecord
- include WillPaginate::Finders::Base
-
- # In Rails, this is automatically called to mix-in pagination functionality to ActiveRecord.
- def self.enable!
- ::ActiveRecord::Base.class_eval do
- extend ActiveRecord
- end
-
- # support pagination on associations and scopes
- [::ActiveRecord::Relation, ::ActiveRecord::Associations::AssociationCollection].each do |klass|
- klass.send(:include, ActiveRecord)
- end
- end
-
- # Wraps +find_by_sql+ by simply adding LIMIT and OFFSET to your SQL string
- # based on the params otherwise used by paginating finds: +page+ and
- # +per_page+.
- #
- # Example:
- #
- # @developers = Developer.paginate_by_sql ['select * from developers where salary > ?', 80000],
- # :page => params[:page], :per_page => 3
- #
- # A query for counting rows will automatically be generated if you don't
- # supply <tt>:total_entries</tt>. If you experience problems with this
- # generated SQL, you might want to perform the count manually in your
- # application.
- #
- def paginate_by_sql(sql, options)
- WillPaginate::Collection.create(*wp_parse_options(options)) do |pager|
- query = sanitize_sql(sql.dup)
- original_query = query.dup
- # add limit, offset
- query << " LIMIT #{pager.per_page} OFFSET #{pager.offset}"
- # perfom the find
- pager.replace find_by_sql(query)
-
- unless pager.total_entries
- count_query = original_query.sub /\bORDER\s+BY\s+[\w`,\s]+$/mi, ''
- count_query = "SELECT COUNT(*) FROM (#{count_query})"
-
- unless ['oracle', 'oci'].include?(self.connection.adapter_name.downcase)
- count_query << ' AS count_table'
- end
- # perform the count query
- pager.total_entries = count_by_sql(count_query)
- end
- end
- end
-
- protected
-
- def wp_query(options, pager, args, &block) #:nodoc:
- finder = (options.delete(:finder) || 'find').to_s
- find_options = options.except(:count).update(:offset => pager.offset, :limit => pager.per_page)
-
- if finder == 'find'
- if Array === args.first and !pager.total_entries
- pager.total_entries = args.first.size
- end
- args << :all if args.empty?
- end
-
- args << find_options
- pager.replace send(finder, *args, &block)
-
- unless pager.total_entries
- # magic counting
- pager.total_entries = wp_count(options, args, finder)
- end
- end
-
- # Does the not-so-trivial job of finding out the total number of entries
- # in the database. It relies on the ActiveRecord +count+ method.
- def wp_count(options, args, finder) #:nodoc:
- # find out if we are in a model or an association proxy
- klass = (@owner and @reflection) ? @reflection.klass : self
- count_options = wp_parse_count_options(options, klass)
-
- # we may have to scope ...
- counter = Proc.new { count(count_options) }
-
- count = if finder.index('find_') == 0 and klass.respond_to?(scoper = finder.sub('find', 'with'))
- # scope_out adds a 'with_finder' method which acts like with_scope, if it's present
- # then execute the count with the scoping provided by the with_finder
- send(scoper, &counter)
- elsif finder =~ /^find_(all_by|by)_([_a-zA-Z]\w*)$/
- # extract conditions from calls like "paginate_by_foo_and_bar"
- attribute_names = $2.split('_and_')
- conditions = construct_attributes_from_arguments(attribute_names, args)
- with_scope(:find => { :conditions => conditions }, &counter)
- else
- counter.call
- end
-
- count.respond_to?(:length) ? count.length : count
- end
-
- def wp_parse_count_options(options, klass) #:nodoc:
- excludees = [:count, :order, :limit, :offset, :readonly]
-
- # Use :select from scope if it isn't already present.
- # FIXME: this triggers extra queries when going through associations
- # if options[:select].blank? && current_scoped_methods && current_scoped_methods.select_values.present?
- # options[:select] = current_scoped_methods.select_values.join(", ")
- # end
-
- if options[:select] and options[:select] =~ /^\s*DISTINCT\b/i
- # Remove quoting and check for table_name.*-like statement.
- if options[:select].gsub('`', '') =~ /\w+\.\*/
- options[:select] = "DISTINCT #{klass.table_name}.#{klass.primary_key}"
- end
- else
- excludees << :select
- end
-
- # count expects (almost) the same options as find
- count_options = options.except *excludees
-
- # merge the hash found in :count
- # this allows you to specify :select, :order, or anything else just for the count query
- count_options.update options[:count] if options[:count]
-
- # forget about includes if they are irrelevant when counting
- if count_options[:include] and count_options[:conditions].blank? and count_options[:group].blank?
- count_options.delete :include
- end
-
- count_options
- end
- end
-end
View
51 vendor/plugins/will_paginate/lib/will_paginate/finders/active_resource.rb
@@ -1,51 +0,0 @@
-require 'will_paginate/finders/base'
-require 'active_resource'
-
-module WillPaginate::Finders
- # Paginate your ActiveResource models.
- #
- # @posts = Post.paginate :all, :params => {
- # :page => params[:page], :order => 'created_at DESC'
- # }
- #
- module ActiveResource
- include WillPaginate::Finders::Base
-
- protected
-
- def wp_query(options, pager, args, &block) #:nodoc:
- unless args.empty? or args.first == :all
- raise ArgumentError, "finder arguments other than :all are not supported for pagination (#{args.inspect} given)"
- end
- params = (options[:params] ||= {})
- params[:page] = pager.current_page
- params[:per_page] = pager.per_page
-
- pager.replace find_every(options, &block)
- end
-
- # Takes the format that Hash.from_xml produces out of an unknown type
- # (produced by WillPaginate::Collection#to_xml_with_collection_type),
- # parses it into a WillPaginate::Collection,
- # and forwards the result to the former +instantiate_collection+ method.
- # It only does this for hashes that have a :type => "collection".
- def instantiate_collection_with_collection(collection, prefix_options = {}) #:nodoc:
- if collection.is_a?(Hash) && collection["type"] == "collection"
- collectables = collection.values.find{ |c| c.is_a?(Hash) || c.is_a?(Array) }
- collectables = [collectables].compact unless collectables.kind_of?(Array)
- instantiated_collection = WillPaginate::Collection.create(collection["current_page"], collection["per_page"], collection["total_entries"]) do |pager|
- pager.replace instantiate_collection_without_collection(collectables, prefix_options)
- end
- else
- instantiate_collection_without_collection(collection, prefix_options)
- end
- end
- end
-end
-
-ActiveResource::Base.class_eval do
- extend WillPaginate::Finders::ActiveResource
- class << self
- # alias_method_chain :instantiate_collection, :collection
- end
-end
View
112 vendor/plugins/will_paginate/lib/will_paginate/finders/base.rb
@@ -1,112 +0,0 @@
-require 'will_paginate/core_ext'
-
-module WillPaginate
- module Finders
- # = Database-agnostic finder module
- #
- # Out of the box, will_paginate supports hooking in several ORMs to
- # provide paginating finders based on their API. As of this writing, the
- # supported libraries are:
- #
- # * ActiveRecord
- # * DataMapper
- # * Sequel
- #
- # It's easy to write your own adapter for anything that can load data with
- # explicit limit and offset settings. DataMapper adapter is a nice and
- # compact example of writing an adapter to bring the +paginate+ method to
- # DataMapper models.
- #
- # == The importance of SQL's <tt>ORDER BY</tt>
- #
- # In most ORMs, <tt>:order</tt> parameter specifies columns for the
- # <tt>ORDER BY</tt> clause in SQL. It is important to have it, since
- # pagination only makes sense with ordered sets. Without the order clause,
- # databases aren't required to do consistent ordering when performing
- # <tt>SELECT</tt> queries.
- #
- # Ordering by a field for which many records share the same value (e.g.
- # "status") can still result in incorrect ordering with some databases (MS
- # SQL and Postgres for instance). With these databases it's recommend that
- # you order by primary key as well. That is, instead of ordering by
- # "status DESC", use the alternative "status DESC, id DESC" and this will
- # yield consistent results.
- #
- # Therefore, make sure you are doing ordering on a column that makes the
- # most sense in the current context. Make that obvious to the user, also.
- # For perfomance reasons you will also want to add an index to that column.
- module Base
- def per_page
- @per_page ||= 30
- end
-
- def per_page=(limit)
- @per_page = limit.to_i
- end
-
- # This is the main paginating finder.
- #
- # == Special parameters for paginating finders
- # * <tt>:page</tt> -- REQUIRED, but defaults to 1 if false or nil
- # * <tt>:per_page</tt> -- defaults to <tt>CurrentModel.per_page</tt> (which is 30 if not overridden)
- # * <tt>:total_entries</tt> -- use only if you manually count total entries
- # * <tt>:count</tt> -- additional options that are passed on to +count+
- # * <tt>:finder</tt> -- name of the finder method to use (default: "find")
- #
- # All other options (+conditions+, +order+, ...) are forwarded to +find+
- # and +count+ calls.
- def paginate(*args, &block)
- options = args.pop
- page, per_page, total_entries = wp_parse_options(options)
-
- WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
- query_options = options.except :page, :per_page, :total_entries
- wp_query(query_options, pager, args, &block)
- end
- end
-
- # Iterates through all records by loading one page at a time. This is useful
- # for migrations or any other use case where you don't want to load all the
- # records in memory at once.
- #
- # It uses +paginate+ internally; therefore it accepts all of its options.
- # You can specify a starting page with <tt>:page</tt> (default is 1). Default
- # <tt>:order</tt> is <tt>"id"</tt>, override if necessary.
- #
- # {Jamis Buck describes this}[http://weblog.jamisbuck.org/2007/4/6/faking-cursors-in-activerecord]
- # and also uses a more efficient way for MySQL.
- def paginated_each(options = {}, &block)
- options = { :order => 'id', :page => 1 }.merge options
- options[:page] = options[:page].to_i
- options[:total_entries] = 0 # skip the individual count queries
- total = 0
-
- begin
- collection = paginate(options)
- total += collection.each(&block).size
- options[:page] += 1
- end until collection.size < collection.per_page
-
- total
- end
-
- protected
-
- def wp_parse_options(options) #:nodoc:
- raise ArgumentError, 'parameter hash expected' unless Hash === options
- raise ArgumentError, ':page parameter required' unless options.key? :page
-
- if options[:count] and options[:total_entries]
- raise ArgumentError, ':count and :total_entries are mutually exclusive'
- end
-
- page = options[:page] || 1
- per_page = options[:per_page] || self.per_page
- total = options[:total_entries]
-
- return [page, per_page, total]
- end
-
- end
- end
-end
View
30 vendor/plugins/will_paginate/lib/will_paginate/finders/data_mapper.rb
@@ -1,30 +0,0 @@
-require 'will_paginate/finders/base'
-require 'dm-core'
-
-module WillPaginate::Finders
- module DataMapper
- include WillPaginate::Finders::Base
-
- protected
-
- def wp_query(options, pager, args, &block) #:nodoc
- find_options = options.except(:count).update(:offset => pager.offset, :limit => pager.per_page)
-
- pager.replace all(find_options, &block)
-
- unless pager.total_entries
- pager.total_entries = wp_count(options)
- end
- end
-
- def wp_count(options) #:nodoc
- count_options = options.except(:count, :order)
- # merge the hash found in :count
- count_options.update options[:count] if options[:count]
-
- count_options.empty?? count() : count(count_options)
- end
- end
-end
-
-DataMapper::Model.send(:include, WillPaginate::Finders::DataMapper)
View
23 vendor/plugins/will_paginate/lib/will_paginate/finders/sequel.rb
@@ -1,23 +0,0 @@
-require 'will_paginate/core_ext'
-require 'sequel'
-require 'sequel/extensions/pagination'
-
-existing_methods = Sequel::Dataset::Pagination.instance_methods
-
-Sequel::Dataset::Pagination.module_eval do
- # it should quack like a WillPaginate::Collection
-
- alias :total_pages :page_count unless existing_methods.include_method? :total_pages
- alias :per_page :page_size unless existing_methods.include_method? :per_page
- alias :previous_page :prev_page unless existing_methods.include_method? :previous_page
- alias :total_entries :pagination_record_count unless existing_methods.include_method? :total_entries
-
- def out_of_bounds?
- current_page > total_pages
- end
-
- # Current offset of the paginated collection
- def offset
- (current_page - 1) * per_page
- end
-end
View
24 vendor/plugins/will_paginate/lib/will_paginate/railtie.rb
@@ -1,24 +0,0 @@
-require 'will_paginate'
-require 'will_paginate/collection'
-
-module WillPaginate
- class Railtie < Rails::Railtie
- initializer "will_paginate.active_record" do |app|
- if defined? ::ActiveRecord
- require 'will_paginate/finders/active_record'
- WillPaginate::Finders::ActiveRecord.enable!
- end
- end
-
- initializer "will_paginate.action_dispatch" do |app|
- if defined? ::ActionDispatch::ShowExceptions
- ActionDispatch::ShowExceptions.rescue_responses['WillPaginate::InvalidPage'] = :not_found
- end
- end
-
- initializer "will_paginate.action_view" do |app|
- require 'will_paginate/view_helpers/action_view'
- ActionView::Base.send(:include, WillPaginate::ViewHelpers::ActionView)
- end
- end
-end
View
9 vendor/plugins/will_paginate/lib/will_paginate/version.rb
@@ -1,9 +0,0 @@
-module WillPaginate #:nodoc:
- module VERSION #:nodoc:
- MAJOR = 3
- MINOR = 0
- TINY = 'pre'
-
- STRING = [MAJOR, MINOR, TINY].join('.')
- end
-end
View
42 vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb
@@ -1,42 +0,0 @@
-require 'will_paginate/deprecation'
-
-module WillPaginate
- # = Will Paginate view helpers
- #
- # The main view helper is +will_paginate+. It renders the pagination links
- # for the given collection. The helper itself is lightweight and serves only
- # as a wrapper around LinkRenderer instantiation; the renderer then does
- # all the hard work of generating the HTML.
- #
- # Read more in WillPaginate::ViewHelpers::Base
- module ViewHelpers
- # ==== Global options for helpers
- #
- # Options for pagination helpers are optional and get their default values
- # from the WillPaginate::ViewHelpers.pagination_options hash. You can write
- # to this hash to override default options on the global level:
- #
- # WillPaginate::ViewHelpers.pagination_options[:previous_label] = 'Previous page'
- #
- # By putting this into your environment.rb you can easily translate link
- # texts to previous and next pages, as well as override some other defaults
- # to your liking.
- def self.pagination_options() @pagination_options; end
- # Overrides the default +pagination_options+
- def self.pagination_options=(value) @pagination_options = value; end
-
- self.pagination_options = {
- :class => 'pagination',
- :previous_label => '&#8592; Previous',
- :next_label => 'Next &#8594;',
- :inner_window => 4, # links around the current page
- :outer_window => 1, # links around beginning and end
- :separator => ' ', # single space is friendly to spiders and non-graphic browsers
- :param_name => :page,
- :params => nil,
- :renderer => 'WillPaginate::ViewHelpers::LinkRenderer',
- :page_links => true,
- :container => true
- }
- end
-end
View
134 vendor/plugins/will_paginate/lib/will_paginate/view_helpers/action_view.rb
@@ -1,134 +0,0 @@
-require 'will_paginate/view_helpers/base'
-require 'action_view'
-require 'action_pack/version'
-require 'will_paginate/view_helpers/link_renderer'
-
-module WillPaginate
- module ViewHelpers
- # = ActionView helpers
- #
- # This module serves for availability in ActionView templates. It also adds a new
- # view helper: +paginated_section+.
- #
- # == Using the helper without arguments
- # If the helper is called without passing in the collection object, it will
- # try to read from the instance variable inferred by the controller name.
- # For example, calling +will_paginate+ while the current controller is
- # PostsController will result in trying to read from the <tt>@posts</tt>
- # variable. Example:
- #
- # <%= will_paginate :id => true %>
- #
- # ... will result in <tt>@post</tt> collection getting paginated:
- #
- # <div class="pagination" id="posts_pagination"> ... </div>
- #
- module ActionView
- include WillPaginate::ViewHelpers::Base
-
- def will_paginate(collection = nil, options = {}) #:nodoc:
- options, collection = collection, nil if collection.is_a? Hash
- collection ||= infer_collection_from_controller
-
- super(collection, options.symbolize_keys).try(:html_safe)
- end
-
- def page_entries_info(collection = nil, options = {}) #:nodoc:
- options, collection = collection, nil if collection.is_a? Hash
- collection ||= infer_collection_from_controller
-
- super(collection, options.symbolize_keys).try(:html_safe)
- end
-
- # Wrapper for rendering pagination links at both top and bottom of a block
- # of content.
- #
- # <% paginated_section @posts do %>
- # <ol id="posts">
- # <% for post in @posts %>
- # <li> ... </li>
- # <% end %>
- # </ol>
- # <% end %>
- #
- # will result in:
- #
- # <div class="pagination"> ... </div>
- # <ol id="posts">
- # ...
- # </ol>
- # <div class="pagination"> ... </div>
- #
- # Arguments are passed to a <tt>will_paginate</tt> call, so the same options
- # apply. Don't use the <tt>:id</tt> option; otherwise you'll finish with two
- # blocks of pagination links sharing the same ID (which is invalid HTML).
- def paginated_section(*args, &block)
- pagination = will_paginate(*args).to_s
- pagination + capture(&block) + pagination
- end
-
- protected
-
- def infer_collection_from_controller
- collection_name = "@#{controller.controller_name}"
- collection = instance_variable_get(collection_name)
- raise ArgumentError, "The #{collection_name} variable appears to be empty. Did you " +
- "forget to pass the collection object for will_paginate?" if collection.nil?
- collection
- end
- end
- end
-end
-
-# :stopdoc:
-
-WillPaginate::ViewHelpers::LinkRenderer.class_eval do
- protected
-
- def default_url_params
- { :escape => false }
- end
-
- def url(page)
- @base_url_params ||= begin
- url_params = base_url_params
- merge_optional_params(url_params)
- url_params
- end
-
- url_params = @base_url_params.dup
- add_current_page_param(url_params, page)
-
- @template.url_for(url_params)
- end
-
- def base_url_params
- url_params = default_url_params
- # page links should preserve GET parameters
- symbolized_update(url_params, @template.params) if get_request?
- url_params
- end
-
- def merge_optional_params(url_params)
- symbolized_update(url_params, @options[:params]) if @options[:params]
- end
-
- def add_current_page_param(url_params, page)
- unless param_name.index(/[^\w-]/)
- url_params[param_name.to_sym] = page
- else
- page_param = parse_query_parameters("#{param_name}=#{page}")
- symbolized_update(url_params, page_param)
- end
- end
-
- def get_request?
- @template.request.get?
- end
-
- private
-
- def parse_query_parameters(params)
- Rack::Utils.parse_nested_query(params)
- end
-end
View
126 vendor/plugins/will_paginate/lib/will_paginate/view_helpers/base.rb
@@ -1,126 +0,0 @@
-require 'will_paginate/core_ext'
-require 'will_paginate/view_helpers'
-
-module WillPaginate
- module ViewHelpers
- # = The main view helpers module
- #
- # This is the base module which provides the +will_paginate+ view helper.
- module Base
- # Renders Digg/Flickr-style pagination for a WillPaginate::Collection object. Nil is
- # returned if there is only one page in total; pagination links aren't needed in that case.
- #
- # ==== Options
- # * <tt>:class</tt> -- CSS class name for the generated DIV (default: "pagination")
- # * <tt>:previous_label</tt> -- default: "« Previous"
- # * <tt>:next_label</tt> -- default: "Next »"
- # * <tt>:inner_window</tt> -- how many links are shown around the current page (default: 4)
- # * <tt>:outer_window</tt> -- how many links are around the first and the last page (default: 1)
- # * <tt>:separator</tt> -- string separator for page HTML elements (default: single space)
- # * <tt>:param_name</tt> -- parameter name for page number in URLs (default: <tt>:page</tt>)
- # * <tt>:params</tt> -- additional parameters when generating pagination links
- # (eg. <tt>:controller => "foo", :action => nil</tt>)
- # * <tt>:renderer</tt> -- class name, class or instance of a link renderer (default:
- # <tt>WillPaginate::LinkRenderer</tt>)
- # * <tt>:page_links</tt> -- when false, only previous/next links are rendered (default: true)
- # * <tt>:container</tt> -- toggles rendering of the DIV container for pagination links, set to
- # false only when you are rendering your own pagination markup (default: true)
- # * <tt>:id</tt> -- HTML ID for the container (default: nil). Pass +true+ to have the ID
- # automatically generated from the class name of objects in collection: for example, paginating
- # ArticleComment models would yield an ID of "article_comments_pagination".
- #
- # All options beside listed ones are passed as HTML attributes to the container
- # element for pagination links (the DIV). For example:
- #
- # <%= will_paginate @posts, :id => 'wp_posts' %>
- #
- # ... will result in:
- #
- # <div class="pagination" id="wp_posts"> ... </div>
- #
- def will_paginate(collection, options = {})
- # early exit if there is nothing to render
- return nil unless collection.total_pages > 1
-
- options = WillPaginate::ViewHelpers.pagination_options.merge(options)
-
- if options[:prev_label]
- WillPaginate::Deprecation::warn(":prev_label view parameter is now :previous_label; the old name has been deprecated.")
- options[:previous_label] = options.delete(:prev_label)
- end
-
- # get the renderer instance
- renderer = case options[:renderer]
- when String
- options[:renderer].constantize.new
- when Class
- options[:renderer].new
- else
- options[:renderer]
- end
- # render HTML for pagination
- renderer.prepare collection, options, self
- renderer.to_html
- end
-
- # Renders a helpful message with numbers of displayed vs. total entries.
- # You can use this as a blueprint for your own, similar helpers.
- #
- # <%= page_entries_info @posts %>
- # #-> Displaying posts 6 - 10 of 26 in total
- #
- # By default, the message will use the humanized class name of objects
- # in collection: for instance, "project types" for ProjectType models.
- # Override this to your liking with the <tt>:entry_name</tt> parameter:
- #
- # <%= page_entries_info @posts, :entry_name => 'item' %>
- # #-> Displaying items 6 - 10 of 26 in total
- #
- # Entry name is entered in singular and pluralized with
- # <tt>String#pluralize</tt> method from ActiveSupport. If it isn't
- # loaded, specify plural with <tt>:plural_name</tt> parameter:
- #
- # <%= page_entries_info @posts, :entry_name => 'item', :plural_name => 'items' %>
- #
- # By default, this method produces HTML output. You can trigger plain
- # text output by passing <tt>:html => false</tt> in options.
- def page_entries_info(collection, options = {})
- entry_name = options[:entry_name] || (collection.empty?? 'entry' :
- collection.first.class.name.underscore.gsub('_', ' '))
-
- plural_name = if options[:plural_name]
- options[:plural_name]
- elsif entry_name == 'entry'
- plural_name = 'entries'
- elsif entry_name.respond_to? :pluralize
- plural_name = entry_name.pluralize
- else
- entry_name + 's'
- end
-
- unless options[:html] == false
- b = '<b>'
- eb = '</b>'
- sp = '&nbsp;'
- else
- b = eb = ''
- sp = ' '
- end
-
- if collection.total_pages < 2
- case collection.size
- when 0; "No #{plural_name} found"
- when 1; "Displaying #{b}1#{eb} #{entry_name}"
- else; "Displaying #{b}all #{collection.size}#{eb} #{plural_name}"
- end
- else
- %{Displaying #{plural_name} #{b}%d#{sp}-#{sp}%d#{eb} of #{b}%d#{eb} in total} % [
- collection.offset + 1,
- collection.offset + collection.length,
- collection.total_entries
- ]
- end
- end
- end
- end
-end
View
130 vendor/plugins/will_paginate/lib/will_paginate/view_helpers/link_renderer.rb
@@ -1,130 +0,0 @@
-require 'cgi'
-require 'will_paginate/core_ext'
-require 'will_paginate/view_helpers/link_renderer_base'
-
-module WillPaginate
- module ViewHelpers
- # This class does the heavy lifting of actually building the pagination
- # links. It is used by +will_paginate+ helper internally.
- class LinkRenderer < LinkRendererBase
-
- # * +collection+ is a WillPaginate::Collection instance or any other object
- # that conforms to that API
- # * +options+ are forwarded from +will_paginate+ view helper
- # * +template+ is the reference to the template being rendered
- def prepare(collection, options, template)
- super(collection, options)
- @template = template
- @container_attributes = @base_url_params = nil
- end
-
- # Process it! This method returns the complete HTML string which contains
- # pagination links. Feel free to subclass LinkRenderer and change this
- # method as you see fit.
- def to_html
- html = pagination.map do |item|
- item.is_a?(Fixnum) ?
- page_number(item) :
- send(item)
- end.join(@options[:separator])
-
- @options[:container] ? html_container(html) : html
- end
-
- # Returns the subset of +options+ this instance was initialized with that
- # represent HTML attributes for the container element of pagination links.
- def container_attributes
- @container_attributes ||= begin
- attributes = @options.except *(WillPaginate::ViewHelpers.pagination_options.keys - [:class])
- # pagination of Post models will have the ID of "posts_pagination"
- if @options[:container] and @options[:id] === true
- attributes[:id] = @collection.first.class.name.underscore.pluralize + '_pagination'
- end
- attributes
- end
- end
-
- protected
-
- def page_number(page)
- unless page == current_page
- link(page, page, :rel => rel_value(page))
- else
- tag(:em, page)
- end
- end
-
- def gap
- '<span class="gap">&hellip;</span>'
- end
-
- def previous_page
- previous_or_next_page(@collection.previous_page, @options[:previous_label], 'previous_page')
- end
-
- def next_page
- previous_or_next_page(@collection.next_page, @options[:next_label], 'next_page')
- end
-
- def previous_or_next_page(page, text, classname)
- if page
- link(text, page, :class => classname)
- else
- tag(:span, text, :class => classname + ' disabled')
- end
- end
-
- def html_container(html)
- tag(:div, html, container_attributes)
- end
-
- # Returns URL params for +page_link_or_span+, taking the current GET params
- # and <tt>:params</tt> option into account.
- def url(page)
- raise NotImplementedError
- end
-
- private
-
- def link(text, target, attributes = {})
- if target.is_a? Fixnum
- attributes[:rel] = rel_value(target)
- target = url(target)
- end
- attributes[:href] = target
- tag(:a, text, attributes)
- end
-
- def tag(name, value, attributes = {})
- string_attributes = attributes.inject('') do |attrs, pair|
- unless pair.last.nil?
- attrs << %( #{pair.first}="#{CGI::escapeHTML(pair.last.to_s)}")
- end
- attrs
- end
- "<#{name}#{string_attributes}>#{value}</#{name}>"
- end
-
- def rel_value(page)
- case page
- when @collection.previous_page; 'prev' + (page == 1 ? ' start' : '')
- when @collection.next_page; 'next'
- when 1; 'start'
- end
- end
-
- def symbolized_update(target, other)
- other.each do |key, value|
- key = key.to_sym
- existing = target[key]
-
- if value.is_a?(Hash) and (existing.is_a?(Hash) or existing.nil?)
- symbolized_update(existing || (target[key] = {}), value)
- else
- target[key] = value
- end
- end
- end
- end
- end
-end
View
83 vendor/plugins/will_paginate/lib/will_paginate/view_helpers/link_renderer_base.rb
@@ -1,83 +0,0 @@
-require 'will_paginate/view_helpers'
-
-module WillPaginate
- module ViewHelpers
- # This class does the heavy lifting of actually building the pagination
- # links. It is used by +will_paginate+ helper internally.
- class LinkRendererBase
-
- # * +collection+ is a WillPaginate::Collection instance or any other object
- # that conforms to that API
- # * +options+ are forwarded from +will_paginate+ view helper
- def prepare(collection, options)
- @collection = collection
- @options = options
-
- # reset values in case we're re-using this instance
- @total_pages = @param_name = nil
- end
-
- def pagination
- items = @options[:page_links] ? windowed_page_numbers : []
- items.unshift :previous_page
- items.push :next_page
- end
-
- protected
-
- # Calculates visible page numbers using the <tt>:inner_window</tt> and
- # <tt>:outer_window</tt> options.
- def windowed_page_numbers
- inner_window, outer_window = @options[:inner_window].to_i, @options[:outer_window].to_i
- window_from = current_page - inner_window
- window_to = current_page + inner_window
-
- # adjust lower or upper limit if other is out of bounds
- if window_to > total_pages
- window_from -= window_to - total_pages
- window_to = total_pages
- end
- if window_from < 1
- window_to += 1 - window_from
- window_from = 1
- window_to = total_pages if window_to > total_pages
- end
-
- # these are always visible
- middle = window_from..window_to
-
- # left window
- if outer_window + 3 < middle.first # there's a gap
- left = (1..(outer_window + 1)).to_a
- left << :gap
- else # runs into visible pages
- left = 1...middle.first
- end
-
- # right window
- if total_pages - outer_window - 2 > middle.last # again, gap
- right = ((total_pages - outer_window)..total_pages).to_a
- right.unshift :gap
- else # runs into visible pages
- right = (middle.last + 1)..total_pages
- end
-
- left.to_a + middle.to_a + right.to_a
- end
-
- private
-
- def current_page
- @collection.current_page
- end
-
- def total_pages
- @collection.total_pages
- end
-
- def param_name
- @param_name ||= @options[:param_name].to_s
- end
- end
- end
-end
View
13 vendor/plugins/will_paginate/lib/will_paginate/view_helpers/merb.rb
@@ -1,13 +0,0 @@
-require 'will_paginate/view_helpers/base'
-require 'will_paginate/view_helpers/link_renderer'
-
-WillPaginate::ViewHelpers::LinkRenderer.class_eval do
- protected
-
- def url(page)
- params = @template.request.params.except(:action, :controller).merge(param_name => page)
- @template.url(:this, params)
- end
-end
-
-Merb::AbstractController.send(:include, WillPaginate::ViewHelpers::Base)
View
147 vendor/plugins/will_paginate/spec/collection_spec.rb
@@ -1,147 +0,0 @@
-require 'will_paginate/array'
-require 'spec_helper'
-
-describe WillPaginate::Collection do
-
- before :all do
- @simple = ('a'..'e').to_a
- end
-
- it "should be a subset of original collection" do
- @simple.paginate(:page => 1, :per_page => 3).should == %w( a b c )
- end
-
- it "can be shorter than per_page if on last page" do
- @simple.paginate(:page => 2, :per_page => 3).should == %w( d e )
- end
-
- it "should include whole collection if per_page permits" do
- @simple.paginate(:page => 1, :per_page => 5).should == @simple
- end
-
- it "should be empty if out of bounds" do
- @simple.paginate(:page => 2, :per_page => 5).should be_empty
- end
-
- it "should default to 1 as current page and 30 per-page" do
- result = (1..50).to_a.paginate
- result.current_page.should == 1
- result.size.should == 30
- end
-
- describe "old API" do
- it "should fail with numeric params" do
- Proc.new { [].paginate(2) }.should raise_error(ArgumentError)
- Proc.new { [].paginate(2, 10) }.should raise_error(ArgumentError)
- end
-
- it "should fail with both options and numeric param" do
- Proc.new { [].paginate({}, 5) }.should raise_error(ArgumentError)
- end
- end
-
- it "should give total_entries precedence over actual size" do
- %w(a b c).paginate(:total_entries => 5).total_entries.should == 5
- end
-
- it "should be an augmented Array" do
- entries = %w(a b c)
- collection = create(2, 3, 10) do |pager|
- pager.replace(entries).should == entries
- end
-
- collection.should == entries
- for method in %w(total_pages each offset size current_page per_page total_entries)
- collection.should respond_to(method)
- end
- collection.should be_kind_of(Array)
- collection.entries.should be_instance_of(Array)
- # TODO: move to another expectation:
- collection.offset.should == 3
- collection.total_pages.should == 4
- collection.should_not be_out_of_bounds
- end
-
- describe "previous/next pages" do
- it "should have previous_page nil when on first page" do
- collection = create(1, 1, 3)
- collection.previous_page.should be_nil
- collection.next_page.should == 2
- end
-
- it "should have both prev/next pages" do
- collection = create(2, 1, 3)
- collection.previous_page.should == 1
- collection.next_page.should == 3
- end
-
- it "should have next_page nil when on last page" do
- collection = create(3, 1, 3)
- collection.previous_page.should == 2
- collection.next_page.should be_nil
- end
- end
-
- it "should show out of bounds when page number is too high" do
- create(2, 3, 2).should be_out_of_bounds
- end
-
- it "should not show out of bounds when inside collection" do
- create(1, 3, 2).should_not be_out_of_bounds
- end
-
- describe "guessing total count" do
- it "can guess when collection is shorter than limit" do
- collection = create { |p| p.replace array }
- collection.total_entries.should == 8
- end
-
- it "should allow explicit total count to override guessed" do
- collection = create(2, 5, 10) { |p| p.replace array }
- collection.total_entries.should == 10
- end
-
- it "should not be able to guess when collection is same as limit" do
- collection = create { |p| p.replace array(5) }
- collection.total_entries.should be_nil
- end
-
- it "should not be able to guess when collection is empty" do
- collection = create { |p| p.replace array(0) }
- collection.total_entries.should be_nil
- end
-
- it "should be able to guess when collection is empty and this is the first page" do
- collection = create(1) { |p| p.replace array(0) }
- collection.total_entries.should == 0
- end
- end
-
- it "should raise WillPaginate::InvalidPage on invalid input" do
- for bad_input in [0, -1, nil, '', 'Schnitzel']
- Proc.new { create bad_input }.should raise_error(WillPaginate::InvalidPage)
- end
- end
-
- it "should raise Argument error on invalid per_page setting" do
- Proc.new { create(1, -1) }.should raise_error(ArgumentError)
- end
-
- it "should not respond to page_count anymore" do
- Proc.new { create.page_count }.should raise_error(NoMethodError)
- end
-
- private
-
- def create(page = 2, limit = 5, total = nil, &block)
- if block_given?
- WillPaginate::Collection.create(page, limit, total, &block)
- else
- WillPaginate::Collection.new(page, limit, total)
- end
- end
-
- def array(size = 3)
- Array.new(size)
- end
-end
View
8 vendor/plugins/will_paginate/spec/console
@@ -1,8 +0,0 @@
-#!/usr/bin/env ruby
-irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
-libs = []
-
-libs << 'irb/completion'
-libs << 'console_fixtures'
-
-exec "#{irb} -Ilib:spec#{libs.map{ |l| " -r #{l}" }.join} --simple-prompt"
View
8 vendor/plugins/will_paginate/spec/console_fixtures.rb
@@ -1,8 +0,0 @@
-require 'will_paginate/finders/active_record'
-require 'finders/activerecord_test_connector'
-ActiverecordTestConnector.setup
-
-# load all fixtures
-Fixtures.create_fixtures(ActiverecordTestConnector::FIXTURES_PATH, ActiveRecord::Base.connection.tables)
-
-ActiverecordTestConnector.show_sql
View
22 vendor/plugins/will_paginate/spec/database.yml
@@ -1,22 +0,0 @@
-sqlite3:
- database: ":memory:"
- adapter: sqlite3
- timeout: 500
-
-sqlite2:
- database: ":memory:"
- adapter: sqlite2
-
-mysql:
- adapter: mysql
- username: rails
- password: mislav
- encoding: utf8
- database: will_paginate_unittest
-
-postgres:
- adapter: postgresql
- username: mislav
- password: mislav
- database: will_paginate_unittest
- min_messages: warning
View
377 vendor/plugins/will_paginate/spec/finders/active_record_spec.rb
@@ -1,377 +0,0 @@
-require 'spec_helper'
-require 'will_paginate/finders/active_record'
-require File.expand_path('../activerecord_test_connector', __FILE__)
-ActiverecordTestConnector.setup
-
-WillPaginate::Finders::ActiveRecord.enable!
-
-describe WillPaginate::Finders::ActiveRecord do
-
- extend ActiverecordTestConnector::FixtureSetup
-
- fixtures :topics, :replies, :users, :projects, :developers_projects
-
- it "should integrate with ActiveRecord::Base" do
- ActiveRecord::Base.should respond_to(:paginate)
- end
-
- it "should paginate" do
- lambda {
- users = User.paginate(:page => 1, :per_page => 5)
- users.length.should == 5
- }.should run_queries(2)
- end
-
- it "should fail when encountering unknown params" do
- lambda {
- User.paginate :foo => 'bar', :page => 1, :per_page => 4
- }.should raise_error(ArgumentError)
- end
-
- describe "counting" do
- it "should not accept :count parameter" do
- pending
- lambda {
- User.paginate :page => 1, :count => {}
- }.should raise_error(ArgumentError)
- end
-
- it "should guess the total count" do
- lambda {
- topics = Topic.paginate :page => 2, :per_page => 3
- topics.total_entries.should == 4
- }.should run_queries(1)
- end
-
- it "should guess that there are no records" do
- lambda {
- topics = Topic.where(:project_id => 999).paginate :page => 1, :per_page => 3
- topics.total_entries.should == 0
- }.should run_queries(1)
- end
- end
-
- it "should not ignore :select parameter when it says DISTINCT" do
- users = User.select('DISTINCT salary').paginate :page => 2
- users.total_entries.should == 5
- end
-
- it "should count with scoped select when :select => DISTINCT" do
- pending
- Topic.distinct.paginate :page => 2
- end
-
- describe "paginate_by_sql" do
- it "should respond" do
- User.should respond_to(:paginate_by_sql)
- end
-
- it "should paginate" do
- lambda {
- sql = "select content from topics where content like '%futurama%'"
- topics = Topic.paginate_by_sql sql, :page => 1, :per_page => 1
- topics.total_entries.should == 1
- topics.first['title'].should be_nil
- }.should run_queries(2)
- end
-
- it "should respect total_entries setting" do
- lambda {
- sql = "select content from topics"
- topics = Topic.paginate_by_sql sql, :page => 1, :per_page => 1, :total_entries => 999
- topics.total_entries.should == 999
- }.should run_queries(1)
- end
-
- it "should strip the order when counting" do
- lambda {
- sql = "select id, title, content from topics order by title"
- topics = Topic.paginate_by_sql sql, :page => 1, :per_page => 2
- topics.first.should == topics(:ar)
- }.should run_queries(2)
- end
-
- it "shouldn't change the original query string" do
- query = 'select * from topics where 1 = 2'
- original_query = query.dup
- Topic.paginate_by_sql(query, :page => 1)
- query.should == original_query
- end
- end
-
- it "doesn't mangle options" do
- options = { :page => 1 }
- options.expects(:delete).never
- options_before = options.dup
-
- Topic.paginate(options)
- options.should == options_before
- end
-
- it "should get first page of Topics with a single query" do
- lambda {
- result = Topic.paginate :page => nil
- result.current_page.should == 1
- result.total_pages.should == 1
- result.size.should == 4
- }.should run_queries(1)
- end
-
- it "should get second (inexistent) page of Topics, requiring 2 queries" do
- lambda {
- result = Topic.paginate :page => 2
- result.total_pages.should == 1
- result.should be_empty
- }.should run_queries(2)
- end
-
- it "should paginate with :order" do
- result = Topic.paginate :page => 1, :order => 'created_at DESC'
- result.should == topics(:futurama, :harvey_birdman, :rails, :ar).reverse
- result.total_pages.should == 1
- end
-
- it "should paginate with :conditions" do
- result = Topic.paginate :page => 1, :conditions => ["created_at > ?", 30.minutes.ago]
- result.should == topics(:rails, :ar)
- result.total_pages.should == 1
- end
-
- it "should paginate with :include and :conditions" do
- result = Topic.paginate \
- :page => 1,
- :include => :replies,
- :conditions => "replies.content LIKE 'Bird%' ",
- :per_page => 10
-
- expected = Topic.find :all,
- :include => 'replies',
- :conditions => "replies.content LIKE 'Bird%' ",
- :limit => 10
-
- result.should == expected
- result.total_entries.should == 1
- end
-
- it "should paginate with :include and :order" do
- result = nil
- lambda {
- result = Topic.paginate \
- :page => 1,
- :include => :replies,
- :order => 'replies.created_at asc, topics.created_at asc',
- :per_page => 10
- }.should run_queries(2)
-
- expected = Topic.find :all,
- :include => 'replies',
- :order => 'replies.created_at asc, topics.created_at asc',
- :limit => 10
-
- result.should == expected
- result.total_entries.should == 4
- end
-
- it "should remove :include for count" do
- lambda {
- Developer.paginate :page => 1, :per_page => 1, :include => :projects
- $query_sql.last.should_not include(' JOIN ')
- }.should run_queries(4)
- end
-
- it "should keep :include for count when they are referenced in :conditions" do
- Developer.expects(:find).returns([1])
- Developer.expects(:count).with({ :include => :projects, :conditions => 'projects.id > 2' }).returns(0)
-
- Developer.paginate :page => 1, :per_page => 1,
- :include => :projects, :conditions => 'projects.id > 2'
- end
-
- describe "associations" do
- it "should paginate with include" do
- project = projects(:active_record)
-
- result = project.topics.paginate \
- :page => 1,
- :include => :replies,
- :conditions => ["replies.content LIKE ?", 'Nice%'],
- :per_page => 10
-
- expected = Topic.find :all,
- :include => 'replies',
- :conditions => ["project_id = #{project.id} AND replies.content LIKE ?", 'Nice%'],
- :limit => 10
-
- result.should == expected
- end
-
- it "should paginate" do
- dhh = users(:david)
- expected_name_ordered = projects(:action_controller, :active_record)
- expected_id_ordered = projects(:active_record, :action_controller)
-
- lambda {
- # with association-specified order
- result = dhh.projects.paginate(:page => 1)
- result.should == expected_name_ordered
- result.total_entries.should == 2
- }.should run_queries(2)
-
- # with explicit order
- result = dhh.projects.paginate(:page => 1, :order => 'projects.id')
- result.should == expected_id_ordered
- result.total_entries.should == 2
-
- lambda {
- dhh.projects.find(:all, :order => 'projects.id', :limit => 4)
- }.should_not raise_error
-
- result = dhh.projects.paginate(:page => 1, :order => 'projects.id', :per_page => 4)
- result.should == expected_id_ordered
-
- # has_many with implicit order
- topic = Topic.find(1)
- expected = replies(:spam, :witty_retort)
- # FIXME: wow, this is ugly
- topic.replies.paginate(:page => 1).map(&:id).sort.should == expected.map(&:id).sort
- topic.replies.paginate(:page => 1, :order => 'replies.id ASC').should == expected.reverse
- end
-
- it "should paginate through association extension" do
- project = Project.find(:first)
- expected = [replies(:brave)]
-
- lambda {
- result = project.replies.only_recent.paginate(:page => 1)
- result.should == expected
- }.should run_queries(1)
- end
- end
-
- it "should paginate with joins" do
- result = nil
- join_sql = 'LEFT JOIN developers_projects ON users.id = developers_projects.developer_id'
-
- lambda {
- result = Developer.paginate :page => 1, :joins => join_sql, :conditions => 'project_id = 1'
- result.size.should == 2
- developer_names = result.map(&:name)
- developer_names.should include('David')
- developer_names.should include('Jamis')
- }.should run_queries(1)
-
- lambda {
- expected = result.to_a
- result = Developer.paginate :page => 1, :joins => join_sql,
- :conditions => 'project_id = 1', :count => { :select => "users.id" }
- result.should == expected
- result.total_entries.should == 2
- }.should run_queries(1)
- end
-
- it "should paginate with group" do
- result = nil
- lambda {
- result = Developer.paginate :page => 1, :per_page => 10,
- :group => 'salary', :select => 'salary', :order => 'salary'
- }.should run_queries(1)
-
- expected = users(:david, :jamis, :dev_10, :poor_jamis).map(&:salary).sort
- result.map(&:salary).should == expected
- end
-
- it "should not paginate with dynamic finder" do
- lambda {
- Developer.paginate_by_salary(100000, :page => 1, :per_page => 5)
- }.should raise_error(NoMethodError)
- end
-
- it "should paginate with_scope" do
- result = Developer.with_poor_ones { Developer.paginate :page => 1 }
- result.size.should == 2
- result.total_entries.should == 2
- end
-
- describe "scopes" do
- it "should paginate" do
- result = Developer.poor.paginate :page => 1, :per_page => 1
- result.size.should == 1
- result.total_entries.should == 2
- end
-
- it "should paginate on habtm association" do
- project = projects(:active_record)
- lambda {
- result = project.developers.poor.paginate :page => 1, :per_page => 1
- result.size.should == 1
- result.total_entries.should == 1
- }.should run_queries(2)
- end
-
- it "should paginate on hmt association" do
- project = projects(:active_record)
- expected = [replies(:brave)]
-
- lambda {
- result = project.replies.recent.paginate :page => 1, :per_page => 1
- result.should == expected
- result.total_entries.should == 1
- }.should run_queries(2)
- end
-
- it "should paginate on has_many association" do
- project = projects(:active_record)
- expected = [topics(:ar)]
-
- lambda {
- result = project.topics.mentions_activerecord.paginate :page => 1, :per_page => 1
- result.should == expected
- result.total_entries.should == 1
- }.should run_queries(2)
- end
- end
-
- it "should paginate with :readonly option" do
- lambda {
- Developer.paginate :readonly => true, :page => 1
- }.should_not raise_error
- end
-
- it "should paginate an array of IDs" do
- lambda {
- result = Developer.paginate((1..8).to_a, :per_page => 3, :page => 2, :order => 'id')
- result.map(&:id).should == (4..6).to_a
- result.total_entries.should == 8
- }.should run_queries(1)
- end
-
- protected
-
- def run_queries(num)
- QueryCountMatcher.new(num)
- end
-
-end
-
-class QueryCountMatcher
- def initialize(num)
- @expected_count = num
- end
-
- def matches?(block)
- $query_count = 0
- $query_sql = []
- block.call
- @queries = $query_sql
- @count = $query_count
- @count == @expected_count
- end
-
- def failure_message
- "expected #{@expected_count} queries, got #{@count}\n#{@queries.join("\n")}"
- end
-
- def negative_failure_message
- "expected query count not to be #{$expected_count}"
- end
-end
View
52 vendor/plugins/will_paginate/spec/finders/active_resource_spec.rb
@@ -1,52 +0,0 @@
-require 'spec_helper'
-require 'will_paginate/finders/active_resource'
-require 'active_resource/http_mock'
-
-class AresProject < ActiveResource::Base
- self.site = 'http://localhost:4000'
-end
-
-describe WillPaginate::Finders::ActiveResource do
-
- before :all do
- # ActiveResource::HttpMock.respond_to do |mock|
- # mock.get "/ares_projects.xml?page=1&per_page=5", {}, [].to_xml
- # end
- end
-
- it "should integrate with ActiveResource::Base" do
- ActiveResource::Base.should respond_to(:paginate)
- end
-
- it "should error when no parameters for #paginate" do
- lambda { AresProject.paginate }.should raise_error(ArgumentError)
- end
-
- it "should paginate" do
- AresProject.expects(:find_every).with(:params => { :page => 1, :per_page => 5 }).returns([])
- AresProject.paginate(:page => 1, :per_page => 5)
- end
-
- it "should have 30 per_page as default" do
- AresProject.expects(:find_every).with(:params => { :page => 1, :per_page => 30 }).returns([])
- AresProject.paginate(:page => 1)
- end
-
- it "should support #paginate(:all)" do
- lambda { AresProject.paginate(:all) }.should raise_error(ArgumentError)
- end
-
- it "should error #paginate(:other)" do
- lambda { AresProject.paginate(:first) }.should raise_error(ArgumentError)
- end
-
- protected
-
- def create(page = 2, limit = 5, total = nil, &block)
- if block_given?
- WillPaginate::Collection.create(page, limit, total, &block)
- else
- WillPaginate::Collection.new(page, limit, total)
- end
- end