will_paginate 3.0.pre4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of will_paginate might be problematic. Click here for more details.

Files changed (51) hide show
  1. data/README.md +61 -0
  2. data/Rakefile +19 -36
  3. data/lib/will_paginate.rb +16 -14
  4. data/lib/will_paginate/{finders/active_record.rb → active_record.rb} +66 -35
  5. data/lib/will_paginate/array.rb +5 -5
  6. data/lib/will_paginate/collection.rb +12 -36
  7. data/lib/will_paginate/core_ext.rb +0 -28
  8. data/lib/will_paginate/data_mapper.rb +91 -0
  9. data/lib/will_paginate/i18n.rb +22 -0
  10. data/lib/will_paginate/locale/en.yml +33 -0
  11. data/lib/will_paginate/page_number.rb +57 -0
  12. data/lib/will_paginate/per_page.rb +27 -0
  13. data/lib/will_paginate/railtie.rb +13 -4
  14. data/lib/will_paginate/sequel.rb +36 -0
  15. data/lib/will_paginate/version.rb +1 -1
  16. data/lib/will_paginate/view_helpers.rb +136 -22
  17. data/lib/will_paginate/view_helpers/action_view.rb +129 -117
  18. data/lib/will_paginate/view_helpers/link_renderer.rb +10 -11
  19. data/lib/will_paginate/view_helpers/link_renderer_base.rb +2 -8
  20. data/lib/will_paginate/view_helpers/merb.rb +20 -7
  21. data/lib/will_paginate/view_helpers/sinatra.rb +41 -0
  22. data/spec/ci.rb +29 -0
  23. data/spec/collection_spec.rb +7 -23
  24. data/spec/console +9 -1
  25. data/spec/console_fixtures.rb +1 -3
  26. data/spec/database.yml +10 -10
  27. data/spec/finders/active_record_spec.rb +82 -28
  28. data/spec/finders/activerecord_test_connector.rb +9 -1
  29. data/spec/finders/data_mapper_spec.rb +59 -48
  30. data/spec/finders/data_mapper_test_connector.rb +8 -1
  31. data/spec/finders/sequel_spec.rb +9 -3
  32. data/spec/fixtures/project.rb +2 -0
  33. data/spec/page_number_spec.rb +65 -0
  34. data/spec/per_page_spec.rb +41 -0
  35. data/spec/spec_helper.rb +5 -29
  36. data/spec/view_helpers/action_view_spec.rb +48 -32
  37. data/spec/view_helpers/base_spec.rb +59 -7
  38. data/spec/view_helpers/link_renderer_base_spec.rb +7 -12
  39. data/spec/view_helpers/view_example_group.rb +1 -0
  40. metadata +22 -23
  41. data/CHANGELOG.rdoc +0 -105
  42. data/README.rdoc +0 -111
  43. data/lib/will_paginate/deprecation.rb +0 -50
  44. data/lib/will_paginate/finders.rb +0 -9
  45. data/lib/will_paginate/finders/active_resource.rb +0 -51
  46. data/lib/will_paginate/finders/base.rb +0 -112
  47. data/lib/will_paginate/finders/data_mapper.rb +0 -30
  48. data/lib/will_paginate/finders/sequel.rb +0 -23
  49. data/lib/will_paginate/view_helpers/base.rb +0 -126
  50. data/spec/finders/active_resource_spec.rb +0 -52
  51. data/spec/finders_spec.rb +0 -76
@@ -1,5 +1,6 @@
1
1
  require 'active_support'
2
2
  require 'action_dispatch/testing/assertions'
3
+ require 'will_paginate/array'
3
4
 
4
5
  module ViewExampleGroup
5
6
 
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: will_paginate
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 4
5
- version: 3.0.pre4
4
+ prerelease:
5
+ version: 3.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Mislav Marohni\xC4\x87"
@@ -10,52 +10,50 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-02-05 00:00:00 Z
13
+ date: 2011-08-09 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
- description: The will_paginate library provides a simple, yet powerful and extensible API for pagination and rendering of page links in web application templates.
16
+ description: will_paginate provides a simple API for performing paginated queries with Active Record, DataMapper and Sequel, and includes helpers for rendering pagination links in Rails, Sinatra and Merb web apps.
17
17
  email: mislav.marohnic@gmail.com
18
18
  executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README.rdoc
23
+ - README.md
24
24
  - LICENSE
25
- - CHANGELOG.rdoc
26
25
  files:
27
26
  - Rakefile
27
+ - lib/will_paginate/active_record.rb
28
28
  - lib/will_paginate/array.rb
29
29
  - lib/will_paginate/collection.rb
30
30
  - lib/will_paginate/core_ext.rb
31
- - lib/will_paginate/deprecation.rb
32
- - lib/will_paginate/finders/active_record.rb
33
- - lib/will_paginate/finders/active_resource.rb
34
- - lib/will_paginate/finders/base.rb
35
- - lib/will_paginate/finders/data_mapper.rb
36
- - lib/will_paginate/finders/sequel.rb
37
- - lib/will_paginate/finders.rb
31
+ - lib/will_paginate/data_mapper.rb
32
+ - lib/will_paginate/i18n.rb
33
+ - lib/will_paginate/locale/en.yml
34
+ - lib/will_paginate/page_number.rb
35
+ - lib/will_paginate/per_page.rb
38
36
  - lib/will_paginate/railtie.rb
37
+ - lib/will_paginate/sequel.rb
39
38
  - lib/will_paginate/version.rb
40
39
  - lib/will_paginate/view_helpers/action_view.rb
41
- - lib/will_paginate/view_helpers/base.rb
42
40
  - lib/will_paginate/view_helpers/link_renderer.rb
43
41
  - lib/will_paginate/view_helpers/link_renderer_base.rb
44
42
  - lib/will_paginate/view_helpers/merb.rb
43
+ - lib/will_paginate/view_helpers/sinatra.rb
45
44
  - lib/will_paginate/view_helpers.rb
46
45
  - lib/will_paginate.rb
46
+ - spec/ci.rb
47
47
  - spec/collection_spec.rb
48
48
  - spec/console
49
49
  - spec/console_fixtures.rb
50
50
  - spec/database.yml
51
51
  - spec/finders/active_record_spec.rb
52
- - spec/finders/active_resource_spec.rb
53
52
  - spec/finders/activerecord_test_connector.rb
54
53
  - spec/finders/data_mapper_spec.rb
55
54
  - spec/finders/data_mapper_test_connector.rb
56
55
  - spec/finders/sequel_spec.rb
57
56
  - spec/finders/sequel_test_connector.rb
58
- - spec/finders_spec.rb
59
57
  - spec/fixtures/admin.rb
60
58
  - spec/fixtures/developer.rb
61
59
  - spec/fixtures/developers_projects.yml
@@ -68,21 +66,22 @@ files:
68
66
  - spec/fixtures/topics.yml
69
67
  - spec/fixtures/user.rb
70
68
  - spec/fixtures/users.yml
69
+ - spec/page_number_spec.rb
70
+ - spec/per_page_spec.rb
71
71
  - spec/spec_helper.rb
72
72
  - spec/view_helpers/action_view_spec.rb
73
73
  - spec/view_helpers/base_spec.rb
74
74
  - spec/view_helpers/link_renderer_base_spec.rb
75
75
  - spec/view_helpers/view_example_group.rb
76
- - README.rdoc
76
+ - README.md
77
77
  - LICENSE
78
- - CHANGELOG.rdoc
79
- homepage: http://github.com/mislav/will_paginate/wikis
78
+ homepage: https://github.com/mislav/will_paginate/wiki
80
79
  licenses: []
81
80
 
82
81
  post_install_message:
83
82
  rdoc_options:
84
83
  - --main
85
- - README.rdoc
84
+ - README.md
86
85
  - --charset=UTF-8
87
86
  require_paths:
88
87
  - lib
@@ -95,15 +94,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
94
  required_rubygems_version: !ruby/object:Gem::Requirement
96
95
  none: false
97
96
  requirements:
98
- - - ">"
97
+ - - ">="
99
98
  - !ruby/object:Gem::Version
100
- version: 1.3.1
99
+ version: "0"
101
100
  requirements: []
102
101
 
103
102
  rubyforge_project:
104
103
  rubygems_version: 1.8.5
105
104
  signing_key:
106
105
  specification_version: 3
107
- summary: Adaptive pagination plugin for web frameworks and other applications
106
+ summary: Pagination plugin for web frameworks and other apps
108
107
  test_files: []
109
108
 
data/CHANGELOG.rdoc DELETED
@@ -1,105 +0,0 @@
1
- == "agnostic" branch
2
-
3
- * added Sequel support
4
- * added an initialization hook for Merb
5
- * refactored URL generation
6
- * BACKWARDS INCOMPATIBLE: refactored LinkRenderer; also markup changes
7
- <span class="current">1</span> is now <em>1</em>
8
- a.prev_page -> a.previous_page (for consistency)
9
- * "prev_label" -> "previous_label"
10
- * ported view tests to specs
11
- * setup Autotest
12
- * added per_page=(limit) attribute writer to set default per_page
13
- * Remove :include option from count_all query when possible (Rails 2.1)
14
- * added WP::ViewHelpers::ActionView and LinkRenderer
15
- * specs for ViewHelpers::Base and LinkRendererBase
16
- * created LinkRendererBase that implements windowed visible page numbers logic
17
- * created WP::ViewHelpers::Base abstract module that implements generic view helpers
18
- * ported finder tests to specs
19
- * added WP::Finders::DataMapper
20
- * added WP::Finders::ActiveRecord mixin for ActiveRecord::Base
21
- * created WP::Finders::Base abstract module that implements generic pagination logic
22
- * removed dependency to ActiveSupport
23
-
24
- == 2.3.1, released 2008-05-04
25
-
26
- * Fixed page numbers not showing with custom routes and implicit first page
27
- * Try to use Hanna for documentation (falls back to default RDoc template if not)
28
-
29
- == 2.3.0, released 2008-04-29
30
-
31
- * Changed LinkRenderer to receive collection, options and reference to view template NOT in
32
- constructor, but with the #prepare method. This is a step towards supporting passing of
33
- LinkRenderer (or subclass) instances that may be preconfigured in some way
34
- * LinkRenderer now has #page_link and #page_span methods for easier customization of output in
35
- subclasses
36
- * Changed page_entries_info() method to adjust its output according to humanized class name of
37
- collection items. Override this with :entry_name parameter (singular).
38
-
39
- page_entries_info(@posts)
40
- #-> "Displaying all 12 posts"
41
- page_entries_info(@posts, :entry_name => 'item')
42
- #-> "Displaying all 12 items"
43
-
44
- == 2.2.3, released 2008-04-26
45
-
46
- * will_paginate gem is no longer published on RubyForge, but on
47
- gems.github.com:
48
-
49
- gem sources -a http://gems.github.com/ (you only need to do this once)
50
- gem install mislav-will_paginate
51
-
52
- * extract reusable pagination testing stuff into WillPaginate::View
53
- * rethink the page URL construction mechanism to be more bulletproof when
54
- combined with custom routing for page parameter
55
- * test that anchor parameter can be used in pagination links
56
-
57
- == 2.2.2, released 2008-04-21
58
-
59
- * Add support for page parameter in custom routes like "/foo/page/2"
60
- * Change output of "page_entries_info" on single-page collection and erroneous
61
- output with empty collection as reported by Tim Chater
62
-
63
- == 2.2.1, released 2008-04-08
64
-
65
- * take less risky path when monkeypatching named_scope; fix that it no longer
66
- requires ActiveRecord::VERSION
67
- * use strings in "respond_to?" calls to work around a bug in acts_as_ferret
68
- stable (ugh)
69
- * add rake release task
70
-
71
-
72
- == 2.2.0, released 2008-04-07
73
-
74
- === API changes
75
- * Rename WillPaginate::Collection#page_count to "total_pages" for consistency.
76
- If you implemented this interface, change your implementation accordingly.
77
- * Remove old, deprecated style of calling Array#paginate as "paginate(page,
78
- per_page)". If you want to specify :page, :per_page or :total_entries, use a
79
- parameter hash.
80
- * Rename LinkRenderer#url_options to "url_for" and drastically optimize it
81
-
82
- === View changes
83
- * Added "prev_page" and "next_page" CSS classes on previous/next page buttons
84
- * Add examples of pagination links styling in "examples/index.html"
85
- * Change gap in pagination links from "..." to
86
- "<span class="gap">&hellip;</span>".
87
- * Add "paginated_section", a block helper that renders pagination both above and
88
- below content in the block
89
- * Add rel="prev|next|start" to page links
90
-
91
- === Other
92
-
93
- * Add ability to opt-in for Rails 2.1 feature "named_scope" by calling
94
- WillPaginate.enable_named_scope (tested in Rails 1.2.6 and 2.0.2)
95
- * Support complex page parameters like "developers[page]"
96
- * Move Array#paginate definition to will_paginate/array.rb. You can now easily
97
- use pagination on arrays outside of Rails:
98
-
99
- gem 'will_paginate'
100
- require 'will_paginate/array'
101
-
102
- * Add "paginated_each" method for iterating through every record by loading only
103
- one page of records at the time
104
- * Rails 2: Rescue from WillPaginate::InvalidPage error with 404 Not Found by
105
- default
data/README.rdoc DELETED
@@ -1,111 +0,0 @@
1
- = The will_paginate Ruby library
2
-
3
- Pagination is just limiting the number of records loaded and displayed. Why should you let it get in
4
- your way while developing?
5
-
6
- This is how you paginate on an ActiveRecord model:
7
-
8
- Post.paginate :page => 1, :order => 'created_at DESC'
9
-
10
- Most of the time it's as simple as replacing "find" with "paginate" and specifying the page you want.
11
-
12
- Some resources to get you started:
13
-
14
- * The {will_paginate project page}[http://mislav.github.com/will_paginate/];
15
- * Your mind reels with questions? Join our {Google group}[http://groups.google.com/group/will_paginate];
16
- * {How to report bugs}[http://github.com/mislav/will_paginate/wikis/report-bugs];
17
- * {Watch the will_paginate screencast}[http://railscasts.com/episodes/51] by Ryan Bates.
18
-
19
- == I'm not using Rails; can I still use will_paginate?
20
-
21
- Absolutely -- although will_paginate started off as a Rails plugin, now it is a <em>completely
22
- framework-agnostic</em> library with support for Rails and Merb built-in. The core library doesn't
23
- have any dependences and you can safely use it in any Ruby code.
24
-
25
- When will_paginate is loaded in an environment where ActiveRecord and ActionView are present, it
26
- automatically hooks into these frameworks to provide easy pagination on your models and in your
27
- views. The same mechanism works for Merb applications, too. But, if no known framework is present
28
- then you have absolute control over what parts of will_paginate do you want to load and where you want
29
- them mixed in.
30
-
31
-
32
- == Installation
33
-
34
- In your Gemfile (if using Bundler):
35
-
36
- gem 'will_paginate', '~> 3.0.beta'
37
-
38
- <i>There are extensive {installation
39
- instructions}[http://github.com/mislav/will_paginate/wikis/installation] on {the
40
- wiki}[http://github.com/mislav/will_paginate/wikis].</i>
41
-
42
-
43
- == Example usage
44
-
45
- Typical usage involves a paginating find in the controller:
46
-
47
- @posts = Post.paginate :page => params[:page], :order => 'updated_at DESC'
48
-
49
- It's true: +paginate+ works just like +find+ -- it just doesn't fetch all the records. Don't forget
50
- to tell it which page you want, or it will complain! Read more in WillPaginate::Finders.
51
-
52
- Render the posts in your view like you would normally do, and when you need to render pagination,
53
- just stick this in:
54
-
55
- <%= will_paginate @posts %>
56
-
57
- You're done. Read more in WillPaginate::ViewHelpers::Base.
58
-
59
- How does it know how much items to fetch per page? It asks your model by calling its
60
- +per_page+ class method. You can define it like this:
61
-
62
- class Post < ActiveRecord::Base
63
- self.per_page = 50
64
- end
65
-
66
- ... or don't worry about it at all. WillPaginate defines it to be <strong>30</strong> by default. You can
67
- always specify the count explicitly when calling +paginate+:
68
-
69
- Post.paginate :page => params[:page], :per_page => 50
70
-
71
- The +paginate+ finder wraps the original finder and returns your result set that now has some new
72
- properties. You can use the collection as you would use any other array. WillPaginate view helpers
73
- also need that collection object to be able to render pagination:
74
-
75
- <ol>
76
- <% for post in @posts -%>
77
- <li>Render `post` in some nice way.</li>
78
- <% end -%>
79
- </ol>
80
-
81
- <p>Now let's render us some pagination!</p>
82
- <%= will_paginate @posts %>
83
-
84
-
85
- == Authors and credits
86
-
87
- The original author of will_paginate was PJ Hyett, who later handed over development to Mislav
88
- Marohnić. (The library was completely rewritten since then.)
89
-
90
- All these people helped making will_paginate what it is now with their code contributions or just
91
- simply awesome ideas:
92
-
93
- Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence Golda, Matt Aimonetti,
94
- Charles Brian Quinn, Desi McAdam, James Coglan, Matijs van Zuijlen, Maria, Brendan Ribera, Todd
95
- Willey, Bryan Helmkamp, Jan Berkel, Lourens Naudé, Rick Olson, Russell Norris, Piotr Usewicz, Chris
96
- Eppstein, Brandon Arbini, Denis Barushev, Paul Barry, Ben Pickles, Ken Collins, Lida Tang and Pieter
97
- Noordhuis.
98
-
99
-
100
- == Usable pagination in the UI
101
-
102
- There are example CSS styles to get you started on the will_paginate project page.
103
-
104
- More reading about pagination as design pattern:
105
-
106
- * {Pagination 101}[http://kurafire.net/log/archive/2007/06/22/pagination-101];
107
- * {Pagination gallery}[http://www.smashingmagazine.com/2007/11/16/pagination-gallery-examples-and-good-practices/] featured on Smashing Magazine;
108
- * {Pagination design pattern}[http://developer.yahoo.com/ypatterns/parent.php?pattern=pagination] on Yahoo Design Pattern Library.
109
-
110
- Want to discuss, request features, ask questions? Join the {Google
111
- group}[http://groups.google.com/group/will_paginate].
@@ -1,50 +0,0 @@
1
- # borrowed from ActiveSupport::Deprecation
2
- module WillPaginate
3
- module Deprecation
4
- def self.debug() @debug; end
5
- def self.debug=(value) @debug = value; end
6
- self.debug = false
7
-
8
- # Choose the default warn behavior according to Rails.env.
9
- # Ignore deprecation warnings in production.
10
- BEHAVIORS = {
11
- 'test' => Proc.new { |message, callstack|
12
- $stderr.puts(message)
13
- $stderr.puts callstack.join("\n ") if debug
14
- },
15
- 'development' => Proc.new { |message, callstack|
16
- logger = defined?(::RAILS_DEFAULT_LOGGER) ? ::RAILS_DEFAULT_LOGGER : Logger.new($stderr)
17
- logger.warn message
18
- logger.debug callstack.join("\n ") if debug
19
- }
20
- }
21
-
22
- def self.warn(message, callstack = caller)
23
- if behavior
24
- message = 'WillPaginate: ' + message.strip.gsub(/\s+/, ' ')
25
- behavior.call(message, callstack)
26
- end
27
- end
28
-
29
- def self.default_behavior
30
- if defined?(::Rails)
31
- BEHAVIORS[::Rails.env.to_s]
32
- else
33
- BEHAVIORS['test']
34
- end
35
- end
36
-
37
- # Behavior is a block that takes a message argument.
38
- def self.behavior() @behavior; end
39
- def self.behavior=(value) @behavior = value; end
40
- self.behavior = default_behavior
41
-
42
- def self.silence
43
- old_behavior = self.behavior
44
- self.behavior = nil
45
- yield
46
- ensure
47
- self.behavior = old_behavior
48
- end
49
- end
50
- end
@@ -1,9 +0,0 @@
1
- require 'will_paginate/core_ext'
2
-
3
- module WillPaginate
4
- # Database logic for different ORMs
5
- #
6
- # See WillPaginate::Finders::Base
7
- module Finders
8
- end
9
- end
@@ -1,51 +0,0 @@
1
- require 'will_paginate/finders/base'
2
- require 'active_resource'
3
-
4
- module WillPaginate::Finders
5
- # Paginate your ActiveResource models.
6
- #
7
- # @posts = Post.paginate :all, :params => {
8
- # :page => params[:page], :order => 'created_at DESC'
9
- # }
10
- #
11
- module ActiveResource
12
- include WillPaginate::Finders::Base
13
-
14
- protected
15
-
16
- def wp_query(options, pager, args, &block) #:nodoc:
17
- unless args.empty? or args.first == :all
18
- raise ArgumentError, "finder arguments other than :all are not supported for pagination (#{args.inspect} given)"
19
- end
20
- params = (options[:params] ||= {})
21
- params[:page] = pager.current_page
22
- params[:per_page] = pager.per_page
23
-
24
- pager.replace find_every(options, &block)
25
- end
26
-
27
- # Takes the format that Hash.from_xml produces out of an unknown type
28
- # (produced by WillPaginate::Collection#to_xml_with_collection_type),
29
- # parses it into a WillPaginate::Collection,
30
- # and forwards the result to the former +instantiate_collection+ method.
31
- # It only does this for hashes that have a :type => "collection".
32
- def instantiate_collection_with_collection(collection, prefix_options = {}) #:nodoc:
33
- if collection.is_a?(Hash) && collection["type"] == "collection"
34
- collectables = collection.values.find{ |c| c.is_a?(Hash) || c.is_a?(Array) }
35
- collectables = [collectables].compact unless collectables.kind_of?(Array)
36
- instantiated_collection = WillPaginate::Collection.create(collection["current_page"], collection["per_page"], collection["total_entries"]) do |pager|
37
- pager.replace instantiate_collection_without_collection(collectables, prefix_options)
38
- end
39
- else
40
- instantiate_collection_without_collection(collection, prefix_options)
41
- end
42
- end
43
- end
44
- end
45
-
46
- ActiveResource::Base.class_eval do
47
- extend WillPaginate::Finders::ActiveResource
48
- class << self
49
- # alias_method_chain :instantiate_collection, :collection
50
- end
51
- end