Introduction
Introduction Statistics Contact Development Disclaimer Help
warvox - VoIP based wardialing tool, forked from rapid7/warvox.
Log
Files
Refs
README
---
commit 26a2d4eb45574f2a127837abb4966260b652264b
parent 0899f9ede192b63614dbf366f0d23a8370a0d5f9
Author: HD Moore <[email protected]>
Date: Wed, 23 Feb 2011 20:37:35 +0000
Diffstat:
A web/vendor/plugins/will_paginate/C… | 105 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/L… | 18 ++++++++++++++++++
A web/vendor/plugins/will_paginate/R… | 126 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/R… | 32 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/l… | 23 +++++++++++++++++++++++
A web/vendor/plugins/will_paginate/l… | 33 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/l… | 145 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/l… | 69 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/l… | 50 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/l… | 9 +++++++++
A web/vendor/plugins/will_paginate/l… | 158 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/l… | 52 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/l… | 112 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/l… | 30 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/l… | 24 ++++++++++++++++++++++++
A web/vendor/plugins/will_paginate/l… | 24 ++++++++++++++++++++++++
A web/vendor/plugins/will_paginate/l… | 9 +++++++++
A web/vendor/plugins/will_paginate/l… | 42 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/l… | 135 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/l… | 126 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/l… | 130 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/l… | 83 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/l… | 14 ++++++++++++++
A web/vendor/plugins/will_paginate/s… | 147 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 8 ++++++++
A web/vendor/plugins/will_paginate/s… | 9 +++++++++
A web/vendor/plugins/will_paginate/s… | 22 ++++++++++++++++++++++
A web/vendor/plugins/will_paginate/s… | 377 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 52 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 114 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 62 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 21 +++++++++++++++++++++
A web/vendor/plugins/will_paginate/s… | 53 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 9 +++++++++
A web/vendor/plugins/will_paginate/s… | 76 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 3 +++
A web/vendor/plugins/will_paginate/s… | 13 +++++++++++++
A web/vendor/plugins/will_paginate/s… | 14 ++++++++++++++
A web/vendor/plugins/will_paginate/s… | 13 +++++++++++++
A web/vendor/plugins/will_paginate/s… | 6 ++++++
A web/vendor/plugins/will_paginate/s… | 29 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 7 +++++++
A web/vendor/plugins/will_paginate/s… | 38 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 7 +++++++
A web/vendor/plugins/will_paginate/s… | 30 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 2 ++
A web/vendor/plugins/will_paginate/s… | 35 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 3 +++
A web/vendor/plugins/will_paginate/s… | 2 ++
A web/vendor/plugins/will_paginate/s… | 76 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 60 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 356 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 64 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 84 +++++++++++++++++++++++++++…
A web/vendor/plugins/will_paginate/s… | 103 +++++++++++++++++++++++++++…
55 files changed, 3444 insertions(+), 0 deletions(-)
---
diff --git a/web/vendor/plugins/will_paginate/CHANGELOG.rdoc b/web/vendor/plugi…
@@ -0,0 +1,105 @@
+== "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 h…
+* 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…
+* 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 n…
+
+== 2.3.0, released 2008-04-29
+
+* Changed LinkRenderer to receive collection, options and reference to view te…
+ constructor, but with the #prepare method. This is a step towards supporting…
+ LinkRenderer (or subclass) instances that may be preconfigured in some way
+* LinkRenderer now has #page_link and #page_span methods for easier customizat…
+ subclasses
+* Changed page_entries_info() method to adjust its output according to humaniz…
+ 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 a…
+ 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 on…
+ one page of records at the time
+* Rails 2: Rescue from WillPaginate::InvalidPage error with 404 Not Found by
+ default
diff --git a/web/vendor/plugins/will_paginate/LICENSE b/web/vendor/plugins/will…
@@ -0,0 +1,18 @@
+Copyright (c) 2009 Mislav Marohnić
+
+Permission is hereby granted, free of charge, to any person obtaining a copy o…
+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 …
+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, FITNE…
+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.
diff --git a/web/vendor/plugins/will_paginate/README.rdoc b/web/vendor/plugins/…
@@ -0,0 +1,125 @@
+= The will_paginate Ruby library
+
+Pagination is just limiting the number of records loaded and displayed. Why sh…
+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 specif…
+
+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…
+* {How to report bugs}[http://github.com/mislav/will_paginate/wikis/report-bug…
+* {Watch the will_paginate screencast}[http://railscasts.com/episodes/51] by R…
+
+== I'm not using Rails; can I still use will_paginate?
+
+Absolutely -- although will_paginate started off as a Rails plugin, now it is …
+framework-agnostic</em> library with support for Rails and Merb built-in. The …
+have any dependences and you can safely use it in any Ruby code.
+
+When will_paginate is loaded in an environment where ActiveRecord and ActionVi…
+automatically hooks into these frameworks to provide easy pagination on your m…
+views. The same mechanism works for Merb applications, too. But, if no known f…
+then you have absolute control over what parts of will_paginate do you want to…
+them mixed in.
+
+
+== Installation
+
+The recommended way is that you get the gem hosted on {gems.github.com}[http:/…
+
+ 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 => '~> …
+
+If you're using Rails 2.0 or older, or any other Ruby framework, just add a si…
+that initializes your application. For example, in Rails you would put this at…
+"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 y…
+
+<i>There are extensive {installation
+instructions}[http://github.com/mislav/will_paginate/wikis/installation] on {t…
+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 …
+to tell it which page you want, or it will complain! Read more in WillPaginate…
+
+Render the posts in your view like you would normally do, and when you need to…
+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 calli…
++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</…
+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 th…
+properties. You can use the collection as you would use any other array. WillP…
+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 devel…
+Marohnić. (The library was completely rewritten since then.)
+
+All these people helped making will_paginate what it is now with their code co…
+simply awesome ideas:
+
+Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence Gold…
+Charles Brian Quinn, Desi McAdam, James Coglan, Matijs van Zuijlen, Maria, Bre…
+Willey, Bryan Helmkamp, Jan Berkel, Lourens Naudé, Rick Olson, Russell Norris…
+Eppstein, Brandon Arbini, Denis Barushev, Paul Barry, Ben Pickles, Ken Collins…
+Noordhuis.
+
+
+== Usable pagination in the UI
+
+There are example CSS styles to get you started on the will_paginate project p…
+
+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-g…
+* {Pagination design pattern}[http://developer.yahoo.com/ypatterns/parent.php?…
+
+Want to discuss, request features, ask questions? Join the {Google
+group}[http://groups.google.com/group/will_paginate].
+\ No newline at end of file
diff --git a/web/vendor/plugins/will_paginate/Rakefile b/web/vendor/plugins/wil…
@@ -0,0 +1,32 @@
+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
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate.rb b/web/vendor…
@@ -0,0 +1,23 @@
+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…
+ require "will_paginate/finders/#{adapter}"
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/array.rb b/web/…
@@ -0,0 +1,33 @@
+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})" un…
+
+ WillPaginate::Collection.create options[:page] || 1,
+ options[:per_page] || 30,
+ options[:total_entries] || self.length do …
+ pager.replace self[pager.offset, pager.per_page].to_a
+ end
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/collection.rb b…
@@ -0,0 +1,145 @@
+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 li…
+ # 404 Not Found. The hook is in "will_paginate.rb":
+ #
+ # ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] = :…
+ #
+ # 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}'…
+ end
+ end
+
+ # = The key to pagination
+ # Arrays returned from paginating finds are, in fact, instances of this litt…
+ # class. You may think of WillPaginate::Collection as an ordinary array with
+ # some extra properties. Those properties are used by view helpers to genera…
+ # 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 li…
+ # 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_p…
+
+ 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.…
+ # # 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 pa…
+ # 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…
+ # 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 exam…
+ # 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 le…
+ self.total_entries = offset + length
+ end
+
+ result
+ end
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb b/w…
@@ -0,0 +1,69 @@
+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 s…
+#
+# ['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_…
+ 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_k…
+ 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
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/deprecation.rb …
@@ -0,0 +1,50 @@
+# 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_D…
+ 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
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/finders.rb b/we…
@@ -0,0 +1,9 @@
+require 'will_paginate/core_ext'
+
+module WillPaginate
+ # Database logic for different ORMs
+ #
+ # See WillPaginate::Finders::Base
+ module Finders
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/finders/active_…
@@ -0,0 +1,158 @@
+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_…
+ #
+ # 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 functionalit…
+ def self.enable!
+ ::ActiveRecord::Base.class_eval do
+ extend ActiveRecord
+ end
+
+ # support pagination on associations and scopes
+ [::ActiveRecord::Relation, ::ActiveRecord::Associations::AssociationColl…
+ 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 whe…
+ # :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.downc…
+ 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, :l…
+
+ 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 = fin…
+ # scope_out adds a 'with_finder' method which acts like with_s…
+ # then execute the count with the scoping provided by the with…
+ 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_nam…
+ 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…
+ # 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 …
+ 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 cou…
+ count_options.delete :include
+ end
+
+ count_options
+ end
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/finders/active_…
@@ -0,0 +1,51 @@
+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 support…
+ 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 = {}…
+ if collection.is_a?(Hash) && collection["type"] == "collection"
+ collectables = collection.values.find{ |c| c.is_a?(Hash) || c.is_a?(Ar…
+ collectables = [collectables].compact unless collectables.kind_of?(Arr…
+ instantiated_collection = WillPaginate::Collection.create(collection["…
+ pager.replace instantiate_collection_without_collection(collectables…
+ 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
+\ No newline at end of file
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/finders/base.rb…
@@ -0,0 +1,112 @@
+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> (wh…
+ # * <tt>:total_entries</tt> -- use only if you manually count total entr…
+ # * <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 |pag…
+ 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 us…
+ # for migrations or any other use case where you don't want to load all …
+ # 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). De…
+ # <tt>:order</tt> is <tt>"id"</tt>, override if necessary.
+ #
+ # {Jamis Buck describes this}[http://weblog.jamisbuck.org/2007/4/6/fakin…
+ # 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 === optio…
+ raise ArgumentError, ':page parameter required' unless options.key? …
+
+ if options[:count] and options[:total_entries]
+ raise ArgumentError, ':count and :total_entries are mutually exclu…
+ 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
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/finders/data_ma…
@@ -0,0 +1,30 @@
+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, :l…
+
+ 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)
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/finders/sequel.…
@@ -0,0 +1,23 @@
+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? :t…
+ alias :per_page :page_size unless existing_methods.include_method? :p…
+ alias :previous_page :prev_page unless existing_methods.include_method? :p…
+ alias :total_entries :pagination_record_count unless existing_methods.includ…
+
+ def out_of_bounds?
+ current_page > total_pages
+ end
+
+ # Current offset of the paginated collection
+ def offset
+ (current_page - 1) * per_page
+ end
+end
+\ No newline at end of file
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/railtie.rb b/we…
@@ -0,0 +1,24 @@
+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::Invalid…
+ 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
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/version.rb b/we…
@@ -0,0 +1,9 @@
+module WillPaginate #:nodoc:
+ module VERSION #:nodoc:
+ MAJOR = 3
+ MINOR = 0
+ TINY = 'pre2'
+
+ STRING = [MAJOR, MINOR, TINY].join('.')
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb…
@@ -0,0 +1,42 @@
+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] = 'Previ…
+ #
+ # 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-gr…
+ :param_name => :page,
+ :params => nil,
+ :renderer => 'WillPaginate::ViewHelpers::LinkRenderer',
+ :page_links => true,
+ :container => true
+ }
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/view_helpers/ac…
@@ -0,0 +1,134 @@
+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 add…
+ # 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 blo…
+ # 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 opt…
+ # apply. Don't use the <tt>:id</tt> option; otherwise you'll finish with…
+ # 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 em…
+ "forget to pass the collection object for will_paginate?" if collect…
+ 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
+\ No newline at end of file
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/view_helpers/ba…
@@ -0,0 +1,126 @@
+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 ob…
+ # returned if there is only one page in total; pagination links aren't n…
+ #
+ # ==== Options
+ # * <tt>:class</tt> -- CSS class name for the generated DIV (default: "p…
+ # * <tt>:previous_label</tt> -- default: "« Previous"
+ # * <tt>:next_label</tt> -- default: "Next »"
+ # * <tt>:inner_window</tt> -- how many links are shown around the curren…
+ # * <tt>:outer_window</tt> -- how many links are around the first and th…
+ # * <tt>:separator</tt> -- string separator for page HTML elements (defa…
+ # * <tt>:param_name</tt> -- parameter name for page number in URLs (defa…
+ # * <tt>:params</tt> -- additional parameters when generating pagination…
+ # (eg. <tt>:controller => "foo", :action => nil</tt>)
+ # * <tt>:renderer</tt> -- class name, class or instance of a link render…
+ # <tt>WillPaginate::LinkRenderer</tt>)
+ # * <tt>:page_links</tt> -- when false, only previous/next links are ren…
+ # * <tt>:container</tt> -- toggles rendering of the DIV container for pa…
+ # false only when you are rendering your own pagination markup (defaul…
+ # * <tt>:id</tt> -- HTML ID for the container (default: nil). Pass +true…
+ # automatically generated from the class name of objects in collection…
+ # ArticleComment models would yield an ID of "article_comments_paginat…
+ #
+ # All options beside listed ones are passed as HTML attributes to the co…
+ # 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 :…
+ 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 =>…
+ #
+ # 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} …
+ collection.offset + 1,
+ collection.offset + collection.length,
+ collection.total_entries
+ ]
+ end
+ end
+ end
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/view_helpers/li…
@@ -0,0 +1,130 @@
+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 obj…
+ # 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 link…
+ def container_attributes
+ @container_attributes ||= begin
+ attributes = @options.except *(WillPaginate::ViewHelpers.pagination_…
+ # 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.pluraliz…
+ 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_la…
+ end
+
+ def next_page
+ previous_or_next_page(@collection.next_page, @options[:next_label], 'n…
+ 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 par…
+ # 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
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/view_helpers/li…
@@ -0,0 +1,83 @@
+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 obj…
+ # 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[:o…
+ 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
diff --git a/web/vendor/plugins/will_paginate/lib/will_paginate/view_helpers/me…
@@ -0,0 +1,13 @@
+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…
+ @template.url(:this, params)
+ end
+end
+
+Merb::AbstractController.send(:include, WillPaginate::ViewHelpers::Base)
+\ No newline at end of file
diff --git a/web/vendor/plugins/will_paginate/spec/collection_spec.rb b/web/ven…
@@ -0,0 +1,147 @@
+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_…
+ 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…
+ 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::InvalidPa…
+ 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
diff --git a/web/vendor/plugins/will_paginate/spec/console b/web/vendor/plugins…
@@ -0,0 +1,8 @@
+#!/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"
diff --git a/web/vendor/plugins/will_paginate/spec/console_fixtures.rb b/web/ve…
@@ -0,0 +1,8 @@
+require 'will_paginate/finders/active_record'
+require 'finders/activerecord_test_connector'
+ActiverecordTestConnector.setup
+
+# load all fixtures
+Fixtures.create_fixtures(ActiverecordTestConnector::FIXTURES_PATH, ActiveRecor…
+
+ActiverecordTestConnector.show_sql
+\ No newline at end of file
diff --git a/web/vendor/plugins/will_paginate/spec/database.yml b/web/vendor/pl…
@@ -0,0 +1,22 @@
+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
diff --git a/web/vendor/plugins/will_paginate/spec/finders/active_record_spec.r…
@@ -0,0 +1,377 @@
+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_pag…
+ 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…
+ 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.m…
+ 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" …
+ Developer.expects(:find).returns([1])
+ Developer.expects(:count).with({ :include => :projects, :conditions => 'pr…
+
+ 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 ?…
+ :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…
+ 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…
+ topic.replies.paginate(:page => 1, :order => 'replies.id ASC').should ==…
+ 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_project…
+
+ lambda {
+ result = Developer.paginate :page => 1, :joins => join_sql, :conditions …
+ 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 => { :selec…
+ 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', :or…
+ }.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, :pe…
+ 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, :or…
+ 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
diff --git a/web/vendor/plugins/will_paginate/spec/finders/active_resource_spec…
@@ -0,0 +1,52 @@
+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 =…
+ 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 =…
+ 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
+end
diff --git a/web/vendor/plugins/will_paginate/spec/finders/activerecord_test_co…
@@ -0,0 +1,114 @@
+require 'active_record'
+require 'active_record/version'
+require 'active_record/fixtures'
+require 'active_support/multibyte' # needed for Ruby 1.9.1
+
+$query_count = $query_sql = nil
+
+class ActiverecordTestConnector
+ cattr_accessor :able_to_connect
+ cattr_accessor :connected
+
+ FIXTURES_PATH = File.expand_path('../../fixtures', __FILE__)
+
+ # Set our defaults
+ self.connected = false
+ self.able_to_connect = true
+
+ def self.setup
+ unless self.connected || !self.able_to_connect
+ setup_connection
+ load_schema
+ add_load_path FIXTURES_PATH
+ self.connected = true
+ end
+ rescue Exception => e # errors from ActiveRecord setup
+ $stderr.puts "\nSkipping ActiveRecord tests: #{e}\n\n"
+ self.able_to_connect = false
+ end
+
+ private
+
+ def self.add_load_path(path)
+ dep = defined?(ActiveSupport::Dependencies) ? ActiveSupport::Dependencies …
+ dep.autoload_paths.unshift path
+ end
+
+ def self.setup_connection
+ db = ENV['DB'].blank?? 'sqlite3' : ENV['DB']
+
+ configurations = YAML.load_file(File.expand_path('../../database.yml', __F…
+ raise "no configuration for '#{db}'" unless configurations.key? db
+ configuration = configurations[db]
+
+ ActiveRecord::Base.logger = Logger.new(STDOUT) if $0 == 'irb'
+ puts "using #{configuration['adapter']} adapter"
+
+ ActiveRecord::Base.configurations = { db => configuration }
+ ActiveRecord::Base.establish_connection(db)
+ prepare ActiveRecord::Base.connection
+ end
+
+ def self.load_schema
+ ActiveRecord::Base.silence do
+ ActiveRecord::Migration.verbose = false
+ load File.join(FIXTURES_PATH, 'schema.rb')
+ end
+ end
+
+ def self.prepare(conn)
+ class << conn
+ IGNORED_SQL = /^(?:PRAGMA|SELECT (?:currval|CAST|@@IDENTITY|@@ROWCOUNT)|…
+
+ def execute_with_counting(sql, name = nil, &block)
+ if $query_count and IGNORED_SQL !~ sql
+ $query_count += 1
+ $query_sql << sql
+ end
+ execute_without_counting(sql, name, &block)
+ end
+
+ alias_method_chain :execute, :counting
+ end
+ end
+
+ def self.show_sql
+ ActiveSupport::Notifications.subscribe('active_record.sql') do |*args|
+ puts args.last[:sql]
+ end
+ end
+
+ module FixtureSetup
+ def fixtures(*tables)
+ table_names = tables.map { |t| t.to_s }
+
+ fixtures = Fixtures.create_fixtures ActiverecordTestConnector::FIXTURES_…
+ @@loaded_fixtures = {}
+ @@fixture_cache = {}
+
+ unless fixtures.nil?
+ if fixtures.instance_of?(Fixtures)
+ @@loaded_fixtures[fixtures.table_name] = fixtures
+ else
+ fixtures.each { |f| @@loaded_fixtures[f.table_name] = f }
+ end
+ end
+
+ table_names.each do |table_name|
+ define_method(table_name) do |*fixtures|
+ @@fixture_cache[table_name] ||= {}
+
+ instances = fixtures.map do |fixture|
+ if @@loaded_fixtures[table_name][fixture.to_s]
+ @@fixture_cache[table_name][fixture] ||= @@loaded_fixtures[table…
+ else
+ raise StandardError, "No fixture with name '#{fixture}' found fo…
+ end
+ end
+
+ instances.size == 1 ? instances.first : instances
+ end
+ end
+ end
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/spec/finders/data_mapper_spec.rb …
@@ -0,0 +1,62 @@
+require 'spec_helper'
+require 'will_paginate/finders/data_mapper'
+require File.expand_path('../data_mapper_test_connector', __FILE__)
+
+require 'will_paginate'
+
+describe WillPaginate::Finders::DataMapper do
+
+ it "should make #paginate available to DM resource classes" do
+ Animal.should respond_to(:paginate)
+ end
+
+ it "should paginate" do
+ Animal.expects(:all).with(:limit => 5, :offset => 0).returns([])
+ Animal.paginate(:page => 1, :per_page => 5)
+ end
+
+ it "should NOT to paginate_by_sql" do
+ Animal.should_not respond_to(:paginate_by_sql)
+ end
+
+ it "should support explicit :all argument" do
+ Animal.expects(:all).with(instance_of(Hash)).returns([])
+ Animal.paginate(:all, :page => nil)
+ end
+
+ it "should support conditional pagination" do
+ filtered_result = Animal.paginate(:all, :name => 'Dog', :page => nil)
+ filtered_result.size.should == 1
+ filtered_result.first.should == Animal.first(:name => 'Dog')
+ end
+
+ it "should leave extra parameters intact" do
+ Animal.expects(:all).with(:name => 'Dog', :limit => 4, :offset => 0 ).retu…
+ Animal.expects(:count).with({:name => 'Dog'}).returns(1)
+
+ Animal.paginate :name => 'Dog', :page => 1, :per_page => 4
+ end
+
+ describe "counting" do
+ it "should ignore nil in :count parameter" do
+ lambda { Animal.paginate :page => nil, :count => nil }.should_not raise_…
+ end
+
+ it "should guess the total count" do
+ Animal.expects(:all).returns(Array.new(2))
+ Animal.expects(:count).never
+
+ result = Animal.paginate :page => 2, :per_page => 4
+ result.total_entries.should == 6
+ end
+
+ it "should guess that there are no records" do
+ Animal.expects(:all).returns([])
+ Animal.expects(:count).never
+
+ result = Animal.paginate :page => 1, :per_page => 4
+ result.total_entries.should == 0
+ end
+ end
+
+end
diff --git a/web/vendor/plugins/will_paginate/spec/finders/data_mapper_test_con…
@@ -0,0 +1,20 @@
+require 'dm-core'
+DataMapper.setup :default, 'sqlite3::memory:'
+
+# Define models
+class Animal
+ include DataMapper::Resource
+ property :id, Serial
+ property :name, String
+ property :notes, Text
+
+ def self.setup
+ Animal.create(:name => 'Dog', :notes => "Man's best friend")
+ Animal.create(:name => 'Cat', :notes => "Woman's best friend")
+ Animal.create(:name => 'Lion', :notes => 'King of the Jungle')
+ end
+end
+
+# Load fixtures
+Animal.auto_migrate!
+Animal.setup
+\ No newline at end of file
diff --git a/web/vendor/plugins/will_paginate/spec/finders/sequel_spec.rb b/web…
@@ -0,0 +1,53 @@
+require 'spec_helper'
+require 'will_paginate/finders/sequel'
+require File.expand_path('../sequel_test_connector', __FILE__)
+
+describe Sequel::Dataset::Pagination, 'extension' do
+
+ class Car < Sequel::Model
+ end
+
+ it "should have the #paginate method" do
+ Car.should respond_to(:paginate)
+ end
+
+ it "should NOT have the #paginate_by_sql method" do
+ Car.should_not respond_to(:paginate_by_sql)
+ end
+
+ describe 'pagination' do
+ before(:all) do
+ Car.create(:name => 'Shelby', :notes => "Man's best friend")
+ Car.create(:name => 'Aston Martin', :notes => "Woman's best friend")
+ Car.create(:name => 'Corvette', :notes => 'King of the Jungle')
+ end
+
+ it "should imitate WillPaginate::Collection" do
+ result = Car.paginate(1, 2)
+
+ result.total_entries.should == 3
+ result.total_pages.should == 2
+ result.per_page.should == 2
+ result.current_page.should == 1
+ result.previous_page.should be_nil
+ result.next_page.should == 2
+ end
+
+ it "should perform" do
+ Car.paginate(1, 2).all.should == [Car[1], Car[2]]
+ end
+
+ it "should perform with #select and #order" do
+ result = Car.select("name as foo".lit).order(:name).paginate(1, 2).all
+ result.size.should == 2
+ result.first.values[:foo].should == "Aston Martin"
+ end
+
+ it "should perform with #filter" do
+ results = Car.filter(:name => 'Shelby').paginate(1, 2).all
+ results.size.should == 1
+ results.first.should == Car.find(:name => 'Shelby')
+ end
+ end
+
+end
diff --git a/web/vendor/plugins/will_paginate/spec/finders/sequel_test_connecto…
@@ -0,0 +1,9 @@
+require 'sequel'
+
+db = Sequel.sqlite
+
+db.create_table :cars do
+ primary_key :id, :integer, :auto_increment => true
+ column :name, :text
+ column :notes, :text
+end
diff --git a/web/vendor/plugins/will_paginate/spec/finders_spec.rb b/web/vendor…
@@ -0,0 +1,76 @@
+require 'spec_helper'
+require 'will_paginate/finders/base'
+
+class Model
+ extend WillPaginate::Finders::Base
+end
+
+describe WillPaginate::Finders::Base do
+ it "should define default per_page of 30" do
+ Model.per_page.should == 30
+ end
+
+ it "should allow to set custom per_page" do
+ begin
+ Model.per_page = 25
+ Model.per_page.should == 25
+ ensure
+ Model.per_page = 30
+ end
+ end
+
+ it "should result with WillPaginate::Collection" do
+ Model.expects(:wp_query)
+ Model.paginate(:page => nil).should be_instance_of(WillPaginate::Collectio…
+ end
+
+ it "should delegate pagination to wp_query" do
+ Model.expects(:wp_query).with({}, instance_of(WillPaginate::Collection), […
+ Model.paginate :page => nil
+ end
+
+ it "should complain when no hash parameters given" do
+ lambda {
+ Model.paginate
+ }.should raise_error(ArgumentError, 'parameter hash expected')
+ end
+
+ it "should complain when no :page parameter present" do
+ lambda {
+ Model.paginate :per_page => 6
+ }.should raise_error(ArgumentError, ':page parameter required')
+ end
+
+ it "should complain when both :count and :total_entries are given" do
+ lambda {
+ Model.paginate :page => 1, :count => {}, :total_entries => 1
+ }.should raise_error(ArgumentError, ':count and :total_entries are mutuall…
+ end
+
+ it "should never mangle options" do
+ options = { :page => 1 }
+ options.expects(:delete).never
+ options_before = options.dup
+
+ Model.expects(:wp_query)
+ Model.paginate(options)
+
+ options.should == options_before
+ end
+
+ it "should provide paginated_each functionality" do
+ collection = stub('collection', :size => 5, :empty? => false, :per_page =>…
+ collection.expects(:each).times(2).returns(collection)
+ last_collection = stub('collection', :size => 4, :empty? => false, :per_pa…
+ last_collection.expects(:each).returns(last_collection)
+
+ params = { :order => 'id', :total_entries => 0 }
+
+ Model.expects(:paginate).with(params.merge(:page => 2)).returns(collection)
+ Model.expects(:paginate).with(params.merge(:page => 3)).returns(collection)
+ Model.expects(:paginate).with(params.merge(:page => 4)).returns(last_colle…
+
+ total = Model.paginated_each(:page => '2') { }
+ total.should == 14
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/spec/fixtures/admin.rb b/web/vend…
@@ -0,0 +1,3 @@
+class Admin < User
+ has_many :companies, :finder_sql => 'SELECT * FROM companies'
+end
diff --git a/web/vendor/plugins/will_paginate/spec/fixtures/developer.rb b/web/…
@@ -0,0 +1,13 @@
+class Developer < User
+ has_and_belongs_to_many :projects, :include => :topics, :order => 'projects.…
+
+ def self.with_poor_ones(&block)
+ with_scope :find => { :conditions => ['salary <= ?', 80000], :order => 'sa…
+ yield
+ end
+ end
+
+ scope :poor, :conditions => ['salary <= ?', 80000], :order => 'salary'
+
+ def self.per_page() 10 end
+end
diff --git a/web/vendor/plugins/will_paginate/spec/fixtures/developers_projects…
@@ -0,0 +1,13 @@
+david_action_controller:
+ developer_id: 1
+ project_id: 2
+ joined_on: 2004-10-10
+
+david_active_record:
+ developer_id: 1
+ project_id: 1
+ joined_on: 2004-10-10
+
+jamis_active_record:
+ developer_id: 2
+ project_id: 1
+\ No newline at end of file
diff --git a/web/vendor/plugins/will_paginate/spec/fixtures/project.rb b/web/ve…
@@ -0,0 +1,13 @@
+class Project < ActiveRecord::Base
+ has_and_belongs_to_many :developers, :uniq => true
+
+ has_many :topics
+ # :finder_sql => 'SELECT * FROM topics WHERE (topics.project_id = #{id})',
+ # :counter_sql => 'SELECT COUNT(*) FROM topics WHERE (topics.project_id = …
+
+ has_many :replies, :through => :topics do
+ def only_recent(params = {})
+ scoped.where(['replies.created_at > ?', 15.minutes.ago])
+ end
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/spec/fixtures/projects.yml b/web/…
@@ -0,0 +1,6 @@
+active_record:
+ id: 1
+ name: Active Record
+action_controller:
+ id: 2
+ name: Action Controller
diff --git a/web/vendor/plugins/will_paginate/spec/fixtures/replies.yml b/web/v…
@@ -0,0 +1,29 @@
+witty_retort:
+ id: 1
+ topic_id: 1
+ content: Birdman is better!
+ created_at: <%= 6.hours.ago.to_s(:db) %>
+
+another:
+ id: 2
+ topic_id: 2
+ content: Nuh uh!
+ created_at: <%= 1.hour.ago.to_s(:db) %>
+
+spam:
+ id: 3
+ topic_id: 1
+ content: Nice site!
+ created_at: <%= 1.hour.ago.to_s(:db) %>
+
+decisive:
+ id: 4
+ topic_id: 4
+ content: "I'm getting to the bottom of this"
+ created_at: <%= 30.minutes.ago.to_s(:db) %>
+
+brave:
+ id: 5
+ topic_id: 4
+ content: "AR doesn't scare me a bit"
+ created_at: <%= 10.minutes.ago.to_s(:db) %>
diff --git a/web/vendor/plugins/will_paginate/spec/fixtures/reply.rb b/web/vend…
@@ -0,0 +1,7 @@
+class Reply < ActiveRecord::Base
+ belongs_to :topic, :include => [:replies]
+
+ scope :recent, :conditions => ['replies.created_at > ?', 15.minutes.ago]
+
+ validates_presence_of :content
+end
diff --git a/web/vendor/plugins/will_paginate/spec/fixtures/schema.rb b/web/ven…
@@ -0,0 +1,38 @@
+ActiveRecord::Schema.define do
+
+ create_table "users", :force => true do |t|
+ t.column "name", :text
+ t.column "salary", :integer, :default => 70000
+ t.column "created_at", :datetime
+ t.column "updated_at", :datetime
+ t.column "type", :text
+ end
+
+ create_table "projects", :force => true do |t|
+ t.column "name", :text
+ end
+
+ create_table "developers_projects", :id => false, :force => true do |t|
+ t.column "developer_id", :integer, :null => false
+ t.column "project_id", :integer, :null => false
+ t.column "joined_on", :date
+ t.column "access_level", :integer, :default => 1
+ end
+
+ create_table "topics", :force => true do |t|
+ t.column "project_id", :integer
+ t.column "title", :string
+ t.column "subtitle", :string
+ t.column "content", :text
+ t.column "created_at", :datetime
+ t.column "updated_at", :datetime
+ end
+
+ create_table "replies", :force => true do |t|
+ t.column "content", :text
+ t.column "created_at", :datetime
+ t.column "updated_at", :datetime
+ t.column "topic_id", :integer
+ end
+
+end
diff --git a/web/vendor/plugins/will_paginate/spec/fixtures/topic.rb b/web/vend…
@@ -0,0 +1,7 @@
+class Topic < ActiveRecord::Base
+ has_many :replies, :dependent => :destroy, :order => 'replies.created_at DES…
+ belongs_to :project
+
+ scope :mentions_activerecord, :conditions => ['topics.title LIKE ?', '%Activ…
+ scope :distinct, :select => "DISTINCT #{table_name}.*"
+end
diff --git a/web/vendor/plugins/will_paginate/spec/fixtures/topics.yml b/web/ve…
@@ -0,0 +1,30 @@
+futurama:
+ id: 1
+ title: Isnt futurama awesome?
+ subtitle: It really is, isnt it.
+ content: I like futurama
+ created_at: <%= 1.day.ago.to_s(:db) %>
+ updated_at:
+
+harvey_birdman:
+ id: 2
+ title: Harvey Birdman is the king of all men
+ subtitle: yup
+ content: He really is
+ created_at: <%= 2.hours.ago.to_s(:db) %>
+ updated_at:
+
+rails:
+ id: 3
+ project_id: 1
+ title: Rails is nice
+ subtitle: It makes me happy
+ content: except when I have to hack internals to fix pagination. even then r…
+ created_at: <%= 20.minutes.ago.to_s(:db) %>
+
+ar:
+ id: 4
+ project_id: 1
+ title: ActiveRecord sometimes freaks me out
+ content: "I mean, what's the deal with eager loading?"
+ created_at: <%= 15.minutes.ago.to_s(:db) %>
diff --git a/web/vendor/plugins/will_paginate/spec/fixtures/user.rb b/web/vendo…
@@ -0,0 +1,2 @@
+class User < ActiveRecord::Base
+end
diff --git a/web/vendor/plugins/will_paginate/spec/fixtures/users.yml b/web/ven…
@@ -0,0 +1,35 @@
+david:
+ id: 1
+ name: David
+ salary: 80000
+ type: Developer
+
+jamis:
+ id: 2
+ name: Jamis
+ salary: 150000
+ type: Developer
+
+<% for digit in 3..10 %>
+dev_<%= digit %>:
+ id: <%= digit %>
+ name: fixture_<%= digit %>
+ salary: 100000
+ type: Developer
+<% end %>
+
+poor_jamis:
+ id: 11
+ name: Jamis
+ salary: 9000
+ type: Developer
+
+admin:
+ id: 12
+ name: admin
+ type: Admin
+
+goofy:
+ id: 13
+ name: Goofy
+ type: Admin
diff --git a/web/vendor/plugins/will_paginate/spec/rcov.opts b/web/vendor/plugi…
@@ -0,0 +1,2 @@
+--exclude ^\/,^spec\/,core_ext.rb,deprecation.rb
+--no-validator-links
+\ No newline at end of file
diff --git a/web/vendor/plugins/will_paginate/spec/spec.opts b/web/vendor/plugi…
@@ -0,0 +1,2 @@
+--colour
+--reverse
diff --git a/web/vendor/plugins/will_paginate/spec/spec_helper.rb b/web/vendor/…
@@ -0,0 +1,76 @@
+require 'rubygems'
+require 'bundler'
+require 'spec/autorun'
+
+module MyExtras
+ protected
+
+ def include_phrase(string)
+ PhraseMatcher.new(string)
+ end
+
+ def collection(params = {})
+ if params[:total_pages]
+ params[:per_page] = 1
+ params[:total_entries] = params[:total_pages]
+ end
+ WillPaginate::Collection.new(params[:page] || 1, params[:per_page] || 30, …
+ end
+
+ def have_deprecation
+ DeprecationMatcher.new
+ end
+end
+
+Spec::Runner.configure do |config|
+ # config.include My::Pony, My::Horse, :type => :farm
+ config.include MyExtras
+ # config.predicate_matchers[:swim] = :can_swim?
+
+ config.mock_with :mocha
+end
+
+class PhraseMatcher
+ def initialize(string)
+ @string = string
+ @pattern = /\b#{string}\b/
+ end
+
+ def matches?(actual)
+ @actual = actual.to_s
+ @actual =~ @pattern
+ end
+
+ def failure_message
+ "expected #{@actual.inspect} to contain phrase #{@string.inspect}"
+ end
+
+ def negative_failure_message
+ "expected #{@actual.inspect} not to contain phrase #{@string.inspect}"
+ end
+end
+
+class DeprecationMatcher
+ def initialize
+ @old_behavior = WillPaginate::Deprecation.behavior
+ @messages = []
+ WillPaginate::Deprecation.behavior = lambda { |message, callstack|
+ @messages << message
+ }
+ end
+
+ def matches?(block)
+ block.call
+ [email protected]?
+ ensure
+ WillPaginate::Deprecation.behavior = @old_behavior
+ end
+
+ def failure_message
+ "expected block to raise a deprecation warning"
+ end
+
+ def negative_failure_message
+ "expected block not to raise deprecation warnings, #{@messages.size} raise…
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/spec/tasks.rake b/web/vendor/plug…
@@ -0,0 +1,60 @@
+require 'spec/rake/spectask'
+
+spec_opts = 'spec/spec.opts'
+
+desc 'Run framework-agnostic specs'
+Spec::Rake::SpecTask.new(:spec) do |t|
+ t.libs << 'spec'
+ t.spec_opts = ['--options', spec_opts]
+ t.spec_files = FileList.new('spec/**/*_spec.rb') do |files|
+ files.exclude(/\b(active_record|active_resource|action_view|data_mapper|se…
+ end
+end
+
+namespace :spec do
+ desc 'Run specs for core, ActiveRecord and ActionView'
+ Spec::Rake::SpecTask.new(:rails) do |t|
+ t.libs << 'spec'
+ t.spec_opts = ['--options', spec_opts]
+ t.spec_files = FileList.new('spec/**/*_spec.rb') do |files|
+ files.exclude(/\b(data_mapper|sequel)_/)
+ end
+ end
+
+ desc 'Run specs for DataMapper'
+ Spec::Rake::SpecTask.new(:datamapper) do |t|
+ t.libs << 'spec'
+ t.spec_opts = ['--options', spec_opts]
+ t.spec_files = FileList.new('spec/finders_spec.rb', 'spec/finders/data_map…
+ end
+
+ desc 'Run specs for Sequel'
+ Spec::Rake::SpecTask.new(:sequel) do |t|
+ t.libs << 'spec'
+ t.spec_opts = ['--options', spec_opts]
+ t.spec_files = FileList.new('spec/finders_spec.rb', 'spec/finders/sequel_s…
+ end
+
+ desc 'Analyze spec coverage with RCov'
+ Spec::Rake::SpecTask.new(:rcov) do |t|
+ t.libs << 'spec'
+ t.spec_opts = ['--options', spec_opts]
+ t.rcov = true
+ t.rcov_opts = lambda do
+ IO.readlines('spec/rcov.opts').map { |l| l.chomp.split(" ") }.flatten
+ end
+ end
+
+ desc 'Print Specdoc for all specs'
+ Spec::Rake::SpecTask.new(:doc) do |t|
+ t.libs << 'spec'
+ t.spec_opts = ['--format', 'specdoc', '--dry-run']
+ end
+
+ desc 'Generate HTML report'
+ Spec::Rake::SpecTask.new(:html) do |t|
+ t.libs << 'spec'
+ t.spec_opts = ['--format', 'html:doc/spec_results.html', '--diff']
+ t.fail_on_error = false
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/spec/view_helpers/action_view_spe…
@@ -0,0 +1,356 @@
+require 'spec_helper'
+require 'active_support/rescuable' # needed for Ruby 1.9.1
+require 'action_controller'
+require 'view_helpers/view_example_group'
+require 'will_paginate/view_helpers/action_view'
+require 'will_paginate/collection'
+
+ActionView::Base.send(:include, WillPaginate::ViewHelpers::ActionView)
+
+Routes = ActionDispatch::Routing::RouteSet.new
+
+Routes.draw do
+ match 'dummy/page/:page' => 'dummy#index'
+ match 'dummy/dots/page.:page' => 'dummy#dots'
+ match 'ibocorp(/:page)' => 'ibocorp#index',
+ :constraints => { :page => /\d+/ }, :defaults => { :page => 1 }
+
+ match ':controller(/:action(/:id(.:format)))'
+end
+
+describe WillPaginate::ViewHelpers::ActionView do
+ before(:each) do
+ @assigns = {}
+ @controller = DummyController.new
+ @request = @controller.request
+ @template = '<%= will_paginate collection, options %>'
+ end
+
+ attr_reader :assigns, :controller, :request
+
+ def render(locals)
+ @view = ActionView::Base.new([], @assigns, @controller)
+ @view.request = @request
+ @view.singleton_class.send(:include, @controller._routes.url_helpers)
+ @view.render(:inline => @template, :locals => locals)
+ end
+
+ ## basic pagination ##
+
+ it "should render" do
+ paginate do |pagination|
+ assert_select 'a[href]', 3 do |elements|
+ validate_page_numbers [2,3,2], elements
+ assert_select elements.last, ':last-child', "Next &#8594;"
+ end
+ assert_select 'span', 1
+ assert_select 'span.disabled:first-child', '&#8592; Previous'
+ assert_select 'em', '1'
+ pagination.first.inner_text.should == '&#8592; Previous 1 2 3 Next &#859…
+ end
+ end
+
+ it "should render nothing when there is only 1 page" do
+ paginate(:per_page => 30).should be_empty
+ end
+
+ it "should paginate with options" do
+ paginate({ :page => 2 }, :class => 'will_paginate', :previous_label => 'Pr…
+ assert_select 'a[href]', 4 do |elements|
+ validate_page_numbers [1,1,3,3], elements
+ # test rel attribute values:
+ assert_select elements[1], 'a', '1' do |link|
+ link.first['rel'].should == 'prev start'
+ end
+ assert_select elements.first, 'a', "Prev" do |link|
+ link.first['rel'].should == 'prev start'
+ end
+ assert_select elements.last, 'a', "Next" do |link|
+ link.first['rel'].should == 'next'
+ end
+ end
+ assert_select 'em', '2'
+ end
+ end
+
+ it "should paginate using a custom renderer class" do
+ paginate({}, :renderer => AdditionalLinkAttributesRenderer) do
+ assert_select 'a[default=true]', 3
+ end
+ end
+
+ it "should paginate using a custom renderer instance" do
+ renderer = WillPaginate::ViewHelpers::LinkRenderer.new
+ def renderer.gap() '<span class="my-gap">~~</span>' end
+
+ paginate({ :per_page => 2 }, :inner_window => 0, :outer_window => 0, :rend…
+ assert_select 'span.my-gap', '~~'
+ end
+
+ renderer = AdditionalLinkAttributesRenderer.new(:title => 'rendered')
+ paginate({}, :renderer => renderer) do
+ assert_select 'a[title=rendered]', 3
+ end
+ end
+
+ it "should have classnames on previous/next links" do
+ paginate do |pagination|
+ assert_select 'span.disabled.previous_page:first-child'
+ assert_select 'a.next_page[href]:last-child'
+ end
+ end
+
+ it "should warn about :prev_label being deprecated" do
+ lambda {
+ paginate({ :page => 2 }, :prev_label => 'Deprecated') do
+ assert_select 'a[href]:first-child', 'Deprecated'
+ end
+ }.should have_deprecation
+ end
+
+ it "should match expected markup" do
+ paginate
+ expected = <<-HTML
+ <div class="pagination"><span class="previous_page disabled">&#8592; Pre…
+ <em>1</em>
+ <a href="/foo/bar?page=2" rel="next">2</a>
+ <a href="/foo/bar?page=3">3</a>
+ <a href="/foo/bar?page=2" class="next_page" rel="next">Next &#8594;</a><…
+ HTML
+ expected.strip!.gsub!(/\s{2,}/, ' ')
+ expected_dom = HTML::Document.new(expected).root
+
+ html_document.root.should == expected_dom
+ end
+
+ it "should output escaped URLs" do
+ paginate({:page => 1, :per_page => 1, :total_entries => 2},
+ :page_links => false, :params => { :tag => '<br>' })
+
+ assert_select 'a[href]', 1 do |links|
+ query = links.first['href'].split('?', 2)[1]
+ query.split('&amp;').sort.should == %w(page=2 tag=%3Cbr%3E)
+ end
+ end
+
+ ## advanced options for pagination ##
+
+ it "should be able to render without container" do
+ paginate({}, :container => false)
+ assert_select 'div.pagination', 0, 'main DIV present when it shouldn\'t'
+ assert_select 'a[href]', 3
+ end
+
+ it "should be able to render without page links" do
+ paginate({ :page => 2 }, :page_links => false) do
+ assert_select 'a[href]', 2 do |elements|
+ validate_page_numbers [1,3], elements
+ end
+ end
+ end
+
+ it "should have magic HTML ID for the container" do
+ paginate do |div|
+ div.first['id'].should be_nil
+ end
+
+ # magic ID
+ paginate({}, :id => true) do |div|
+ div.first['id'].should == 'fixnums_pagination'
+ end
+
+ # explicit ID
+ paginate({}, :id => 'custom_id') do |div|
+ div.first['id'].should == 'custom_id'
+ end
+ end
+
+ ## other helpers ##
+
+ it "should render a paginated section" do
+ @template = <<-ERB
+ <%= paginated_section collection, options do %>
+ <%= content_tag :div, '', :id => "developers" %>
+ <% end %>
+ ERB
+
+ paginate
+ assert_select 'div.pagination', 2
+ assert_select 'div.pagination + div#developers', 1
+ end
+
+ ## parameter handling in page links ##
+
+ it "should preserve parameters on GET" do
+ request.params :foo => { :bar => 'baz' }
+ paginate
+ assert_links_match /foo\[bar\]=baz/
+ end
+
+ it "should not preserve parameters on POST" do
+ request.post
+ request.params :foo => 'bar'
+ paginate
+ assert_no_links_match /foo=bar/
+ end
+
+ it "should add additional parameters to links" do
+ paginate({}, :params => { :foo => 'bar' })
+ assert_links_match /foo=bar/
+ end
+
+ it "should add anchor parameter" do
+ paginate({}, :params => { :anchor => 'anchor' })
+ assert_links_match /#anchor$/
+ end
+
+ it "should remove arbitrary parameters" do
+ request.params :foo => 'bar'
+ paginate({}, :params => { :foo => nil })
+ assert_no_links_match /foo=bar/
+ end
+
+ it "should override default route parameters" do
+ paginate({}, :params => { :controller => 'baz', :action => 'list' })
+ assert_links_match %r{\Wbaz/list\W}
+ end
+
+ it "should paginate with custom page parameter" do
+ paginate({ :page => 2 }, :param_name => :developers_page) do
+ assert_select 'a[href]', 4 do |elements|
+ validate_page_numbers [1,1,3,3], elements, :developers_page
+ end
+ end
+ end
+
+ it "should paginate with complex custom page parameter" do
+ request.params :developers => { :page => 2 }
+
+ paginate({ :page => 2 }, :param_name => 'developers[page]') do
+ assert_select 'a[href]', 4 do |links|
+ assert_links_match /\?developers\[page\]=\d+$/, links
+ validate_page_numbers [1,1,3,3], links, 'developers[page]'
+ end
+ end
+ end
+
+ it "should paginate with custom route page parameter" do
+ request.symbolized_path_parameters.update :controller => 'dummy', :action …
+ paginate :per_page => 2 do
+ assert_select 'a[href]', 6 do |links|
+ assert_links_match %r{/page/(\d+)$}, links, [2, 3, 4, 5, 6, 2]
+ end
+ end
+ end
+
+ it "should paginate with custom route with dot separator page parameter" do
+ request.symbolized_path_parameters.update :controller => 'dummy', :action …
+ paginate :per_page => 2 do
+ assert_select 'a[href]', 6 do |links|
+ assert_links_match %r{/page\.(\d+)$}, links, [2, 3, 4, 5, 6, 2]
+ end
+ end
+ end
+
+ it "should paginate with custom route and first page number implicit" do
+ request.symbolized_path_parameters.update :controller => 'ibocorp', :actio…
+ paginate :page => 2, :per_page => 2 do
+ assert_select 'a[href]', 7 do |links|
+ assert_links_match %r{/ibocorp(?:/(\d+))?$}, links, [nil, nil, 3, 4, 5…
+ end
+ end
+ # Routes.recognize_path('/ibocorp/2').should == {:page=>'2', :action=>'ind…
+ # Routes.recognize_path('/ibocorp/foo').should == {:action=>'foo', :contro…
+ end
+
+ ## internal hardcore stuff ##
+
+ it "should be able to guess the collection name" do
+ collection = mock
+ collection.expects(:total_pages).returns(1)
+
+ @template = '<%= will_paginate options %>'
+ controller.controller_name = 'developers'
+ assigns['developers'] = collection
+
+ paginate(nil)
+ end
+
+ it "should fail if the inferred collection is nil" do
+ @template = '<%= will_paginate options %>'
+ controller.controller_name = 'developers'
+
+ lambda {
+ paginate(nil)
+ }.should raise_error(ActionView::TemplateError, /@developers/)
+ end
+end
+
+class AdditionalLinkAttributesRenderer < WillPaginate::ViewHelpers::LinkRender…
+ def initialize(link_attributes = nil)
+ super()
+ @additional_link_attributes = link_attributes || { :default => 'true' }
+ end
+
+ def link(text, target, attributes = {})
+ super(text, target, attributes.merge(@additional_link_attributes))
+ end
+end
+
+class DummyController
+ attr_reader :request
+ attr_accessor :controller_name
+
+ include ActionController::UrlFor
+ include Routes.url_helpers
+
+ def initialize
+ @request = DummyRequest.new
+ end
+
+ def params
+ @request.params
+ end
+end
+
+class IbocorpController < DummyController
+end
+
+class DummyRequest
+ attr_accessor :symbolized_path_parameters
+
+ def initialize
+ @get = true
+ @params = {}
+ @symbolized_path_parameters = { :controller => 'foo', :action => 'bar' }
+ end
+
+ def get?
+ @get
+ end
+
+ def post
+ @get = false
+ end
+
+ def relative_url_root
+ ''
+ end
+
+ def script_name
+ ''
+ end
+
+ def params(more = nil)
+ @params.update(more) if more
+ @params
+ end
+
+ def host_with_port
+ 'example.com'
+ end
+
+ def protocol
+ 'http:'
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/spec/view_helpers/base_spec.rb b/…
@@ -0,0 +1,64 @@
+require 'spec_helper'
+require 'will_paginate/view_helpers/base'
+require 'will_paginate/array'
+
+describe WillPaginate::ViewHelpers::Base do
+
+ include WillPaginate::ViewHelpers::Base
+
+ describe "will_paginate" do
+ it "should render" do
+ collection = WillPaginate::Collection.new(1, 2, 4)
+ renderer = mock 'Renderer'
+ renderer.expects(:prepare).with(collection, instance_of(Hash), self)
+ renderer.expects(:to_html).returns('<PAGES>')
+
+ will_paginate(collection, :renderer => renderer).should == '<PAGES>'
+ end
+
+ it "should return nil for single-page collections" do
+ collection = mock 'Collection', :total_pages => 1
+ will_paginate(collection).should be_nil
+ end
+ end
+
+ describe "page_entries_info" do
+ before :all do
+ @array = ('a'..'z').to_a
+ end
+
+ def info(params, options = {})
+ options[:html] ||= false unless options.key?(:html) and options[:html].n…
+ collection = Hash === params ? @array.paginate(params) : params
+ page_entries_info collection, options
+ end
+
+ it "should display middle results and total count" do
+ info(:page => 2, :per_page => 5).should == "Displaying strings 6 - 10 of…
+ end
+
+ it "should output HTML by default" do
+ info({ :page => 2, :per_page => 5 }, :html => nil).should ==
+ "Displaying strings <b>6&nbsp;-&nbsp;10</b> of <b>26</b> in total"
+ end
+
+ it "should display shortened end results" do
+ info(:page => 7, :per_page => 4).should include_phrase('strings 25 - 26')
+ end
+
+ it "should handle longer class names" do
+ collection = @array.paginate(:page => 2, :per_page => 5)
+ collection.first.stubs(:class).returns(mock('Class', :name => 'ProjectTy…
+ info(collection).should include_phrase('project types')
+ end
+
+ it "should adjust output for single-page collections" do
+ info(('a'..'d').to_a.paginate(:page => 1, :per_page => 5)).should == "Di…
+ info(['a'].paginate(:page => 1, :per_page => 5)).should == "Displaying 1…
+ end
+
+ it "should display 'no entries found' for empty collections" do
+ info([].paginate(:page => 1, :per_page => 5)).should == "No entries foun…
+ end
+ end
+end
diff --git a/web/vendor/plugins/will_paginate/spec/view_helpers/link_renderer_b…
@@ -0,0 +1,84 @@
+require 'spec_helper'
+require 'will_paginate/view_helpers/link_renderer_base'
+require 'will_paginate/collection'
+
+describe WillPaginate::ViewHelpers::LinkRendererBase do
+
+ before do
+ @renderer = WillPaginate::ViewHelpers::LinkRendererBase.new
+ end
+
+ it "should raise error when unprepared" do
+ lambda {
+ @renderer.send :param_name
+ }.should raise_error
+ end
+
+ it "should prepare with collection and options" do
+ prepare({}, :param_name => 'mypage')
+ @renderer.send(:current_page).should == 1
+ @renderer.send(:param_name).should == 'mypage'
+ end
+
+ it "should have total_pages accessor" do
+ prepare :total_pages => 42
+ lambda {
+ @renderer.send(:total_pages).should == 42
+ }.should_not have_deprecation
+ end
+
+ it "should clear old cached values when prepared" do
+ prepare({ :total_pages => 1 }, :param_name => 'foo')
+ @renderer.send(:total_pages).should == 1
+ @renderer.send(:param_name).should == 'foo'
+ # prepare with different object and options:
+ prepare({ :total_pages => 2 }, :param_name => 'bar')
+ @renderer.send(:total_pages).should == 2
+ @renderer.send(:param_name).should == 'bar'
+ end
+
+ it "should have pagination definition" do
+ prepare({ :total_pages => 1 }, :page_links => true)
+ @renderer.pagination.should == [:previous_page, 1, :next_page]
+ end
+
+ describe "visible page numbers" do
+ it "should calculate windowed visible links" do
+ prepare({ :page => 6, :total_pages => 11 }, :inner_window => 1, :outer_w…
+ showing_pages 1, 2, :gap, 5, 6, 7, :gap, 10, 11
+ end
+
+ it "should eliminate small gaps" do
+ prepare({ :page => 6, :total_pages => 11 }, :inner_window => 2, :outer_w…
+ # pages 4 and 8 appear instead of the gap
+ showing_pages 1..11
+ end
+
+ it "should support having no windows at all" do
+ prepare({ :page => 4, :total_pages => 7 }, :inner_window => 0, :outer_wi…
+ showing_pages 1, :gap, 4, :gap, 7
+ end
+
+ it "should adjust upper limit if lower is out of bounds" do
+ prepare({ :page => 1, :total_pages => 10 }, :inner_window => 2, :outer_w…
+ showing_pages 1, 2, 3, 4, 5, :gap, 9, 10
+ end
+
+ it "should adjust lower limit if upper is out of bounds" do
+ prepare({ :page => 10, :total_pages => 10 }, :inner_window => 2, :outer_…
+ showing_pages 1, 2, :gap, 6, 7, 8, 9, 10
+ end
+
+ def showing_pages(*pages)
+ pages = pages.first.to_a if Array === pages.first or Range === pages.fir…
+ @renderer.send(:windowed_page_numbers).should == pages
+ end
+ end
+
+ protected
+
+ def prepare(collection_options, options = {})
+ @renderer.prepare(collection(collection_options), options)
+ end
+
+end
diff --git a/web/vendor/plugins/will_paginate/spec/view_helpers/view_example_gr…
@@ -0,0 +1,103 @@
+require 'action_dispatch/testing/assertions'
+
+class ViewExampleGroup < Spec::Example::ExampleGroup
+
+ include ActionDispatch::Assertions::SelectorAssertions
+
+ def assert(value, message)
+ raise message unless value
+ end
+
+ def paginate(collection = {}, options = {}, &block)
+ if collection.instance_of? Hash
+ page_options = { :page => 1, :total_entries => 11, :per_page => 4 }.merg…
+ collection = [1].paginate(page_options)
+ end
+
+ locals = { :collection => collection, :options => options }
+
+ @render_output = render(locals)
+ @html_document = nil
+
+ if block_given?
+ classname = options[:class] || WillPaginate::ViewHelpers.pagination_opti…
+ assert_select("div.#{classname}", 1, 'no main DIV', &block)
+ end
+
+ @render_output
+ end
+
+ def html_document
+ @html_document ||= HTML::Document.new(@render_output, true, false)
+ end
+
+ def response_from_page_or_rjs
+ html_document.root
+ end
+
+ def validate_page_numbers(expected, links, param_name = :page)
+ param_pattern = /\W#{Regexp.escape(param_name.to_s)}=([^&]*)/
+
+ links.map { |e|
+ e['href'] =~ param_pattern
+ $1 ? $1.to_i : $1
+ }.should == expected
+ end
+
+ def assert_links_match(pattern, links = nil, numbers = nil)
+ links ||= assert_select 'div.pagination a[href]' do |elements|
+ elements
+ end
+
+ pages = [] if numbers
+
+ links.each do |el|
+ el['href'].should =~ pattern
+ if numbers
+ el['href'] =~ pattern
+ pages << ($1.nil?? nil : $1.to_i)
+ end
+ end
+
+ pages.should == numbers if numbers
+ end
+
+ def assert_no_links_match(pattern)
+ assert_select 'div.pagination a[href]' do |elements|
+ elements.each do |el|
+ el['href'] !~ pattern
+ end
+ end
+ end
+
+ def build_message(message, pattern, *args)
+ built_message = pattern.dup
+ for value in args
+ built_message.sub! '?', value.inspect
+ end
+ built_message
+ end
+
+end
+
+Spec::Example::ExampleGroupFactory.register(:view_helpers, ViewExampleGroup)
+
+module HTML
+ Node.class_eval do
+ def inner_text
+ children.map(&:inner_text).join('')
+ end
+ end
+
+ Text.class_eval do
+ def inner_text
+ self.to_s
+ end
+ end
+
+ Tag.class_eval do
+ def inner_text
+ childless?? '' : super
+ end
+ end
+end
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.