kaminari-surface 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +5 -0
  4. data/.rdoc_options +16 -0
  5. data/.rspec +1 -0
  6. data/ChangeLog.md +4 -0
  7. data/Gemfile +3 -0
  8. data/LICENSE.txt +20 -0
  9. data/README.md +96 -0
  10. data/Rakefile +25 -0
  11. data/TRACKER.md +17 -0
  12. data/capture.gif +0 -0
  13. data/example/.gitignore +17 -0
  14. data/example/Gemfile +52 -0
  15. data/example/Gemfile.lock +179 -0
  16. data/example/README.rdoc +28 -0
  17. data/example/Rakefile +6 -0
  18. data/example/app/assets/javascripts/application.js +16 -0
  19. data/example/app/assets/stylesheets/application.css +15 -0
  20. data/example/app/controllers/application_controller.rb +5 -0
  21. data/example/app/controllers/products_controller.rb +6 -0
  22. data/example/app/helpers/application_helper.rb +2 -0
  23. data/example/app/models/product.rb +2 -0
  24. data/example/app/views/layouts/application.html.erb +23 -0
  25. data/example/app/views/products/index.haml +18 -0
  26. data/example/bin/bundle +3 -0
  27. data/example/bin/rails +9 -0
  28. data/example/bin/rake +9 -0
  29. data/example/bin/setup +29 -0
  30. data/example/bin/spring +15 -0
  31. data/example/config.ru +4 -0
  32. data/example/config/application.rb +26 -0
  33. data/example/config/boot.rb +3 -0
  34. data/example/config/database.yml +25 -0
  35. data/example/config/environment.rb +5 -0
  36. data/example/config/environments/development.rb +41 -0
  37. data/example/config/environments/production.rb +79 -0
  38. data/example/config/environments/test.rb +42 -0
  39. data/example/config/initializers/assets.rb +11 -0
  40. data/example/config/initializers/backtrace_silencers.rb +7 -0
  41. data/example/config/initializers/cookies_serializer.rb +3 -0
  42. data/example/config/initializers/filter_parameter_logging.rb +4 -0
  43. data/example/config/initializers/inflections.rb +16 -0
  44. data/example/config/initializers/mime_types.rb +4 -0
  45. data/example/config/initializers/session_store.rb +3 -0
  46. data/example/config/initializers/surface.rb +74 -0
  47. data/example/config/initializers/wrap_parameters.rb +14 -0
  48. data/example/config/locales/en.yml +23 -0
  49. data/example/config/routes.rb +58 -0
  50. data/example/config/secrets.yml +22 -0
  51. data/example/db/migrate/20160501023444_create_products.rb +9 -0
  52. data/example/db/schema.rb +22 -0
  53. data/example/db/seeds.rb +7 -0
  54. data/example/lib/tasks/seed.rake +9 -0
  55. data/example/public/404.html +67 -0
  56. data/example/public/422.html +67 -0
  57. data/example/public/500.html +66 -0
  58. data/example/public/favicon.ico +0 -0
  59. data/example/public/robots.txt +5 -0
  60. data/example/test/fixtures/products.yml +7 -0
  61. data/example/test/models/product_test.rb +7 -0
  62. data/example/test/test_helper.rb +10 -0
  63. data/kaminari-surface.gemspec +51 -0
  64. data/lib/kaminari/surface.rb +15 -0
  65. data/lib/kaminari/surface/data_mapper_extension.rb +15 -0
  66. data/lib/kaminari/surface/page_scope_methods.rb +78 -0
  67. data/lib/kaminari/surface/paginatable_array_extension.rb +27 -0
  68. data/lib/kaminari/surface/version.rb +5 -0
  69. data/spec/acceptance/active_record_spec.rb +83 -0
  70. data/spec/acceptance/data_mapper_spec.rb +83 -0
  71. data/spec/acceptance/mongo_mapper_spec.rb +84 -0
  72. data/spec/acceptance/mongoid_spec.rb +84 -0
  73. data/spec/spec_helper.rb +112 -0
  74. data/spec/surface/page_scope_methods_spec.rb +129 -0
  75. data/spec/surface_spec.rb +8 -0
  76. metadata +364 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46fa1f2a2c82930ab50f3ccc4fd9062406c89bd7
4
+ data.tar.gz: 022cbcc90e553d94b7fc78bbcd9d91149b6d50d6
5
+ SHA512:
6
+ metadata.gz: d89a732e78897bc553b652fbaf3e9bdc7a1ef5550744f7b52e744ab75941dd65982ade52f866ab58d91a212e658e636f073601b19b9f7b1c317881c74b3de0b9
7
+ data.tar.gz: 9e505b143b04cb4a8b26860a8c22f35ddfd9174bd3195950d04f047949ce65dd9469cf154ebe386bcc1232952d43fc7b40e834a874af9894f08c5202f201e665
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ README.md
3
+ ChangeLog.md
4
+
5
+ LICENSE.txt
@@ -0,0 +1,5 @@
1
+ /.bundle
2
+ /Gemfile.lock
3
+ /html/
4
+ /pkg/
5
+ /vendor/cache/*.gem
@@ -0,0 +1,16 @@
1
+ --- !ruby/object:RDoc::Options
2
+ encoding: UTF-8
3
+ static_path: []
4
+ rdoc_include:
5
+ - .
6
+ charset: UTF-8
7
+ exclude:
8
+ hyperlink_all: false
9
+ line_numbers: false
10
+ main_page: README.md
11
+ markup: markdown
12
+ show_hash: false
13
+ tab_width: 8
14
+ title: kaminari-surface Documentation
15
+ visibility: :protected
16
+ webcvs:
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
@@ -0,0 +1,4 @@
1
+ ### 0.1.0 / 2016-05-09
2
+
3
+ * Initial release:
4
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016 James Kassemi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,96 @@
1
+ # A Surfacing Pagination Kaminari Extension
2
+
3
+ Making that last result a little closer.
4
+
5
+ ![screencap](https://raw.githubusercontent.com/jkassemi/kaminari-surface/master/capture.gif)
6
+
7
+ ## Overview
8
+
9
+ Developers may implement pagination to protect against overzealous result sizes.
10
+ With responsible pagination settings a query that returns a large number of
11
+ results can be displayed with fewer system resources on both the client and
12
+ the server.
13
+
14
+ The client may be able to configure the `per` option to permit more results per
15
+ page. Usually this value must be increased from an initially conservative
16
+ value, and after the first result set is displayed.
17
+
18
+ For queries that return few results the client must either make a modification
19
+ to the `per` option manually, or must page to a last page containing few
20
+ results. Both of these operations are unnecessary, and we can enhance the
21
+ client experience with an application designed to more intelligently handle
22
+ smaller response sets.
23
+
24
+ Surfacing pagination prevents a second request to the server by sending the
25
+ results that the client would ordinarily need to fetch on a subsequent page
26
+ request if the number of results is under a threshhold. The ideal implementation
27
+ would prevent the client from flipping through pages when there's little need to
28
+ do so.
29
+
30
+ ## Installation
31
+
32
+ ### Rails
33
+
34
+ Place `kaminari-surface` in your Gemfile (if you're sane you'll version it):
35
+
36
+ gem 'kaminari-surface'
37
+
38
+ and bundle:
39
+
40
+ $ bundle
41
+
42
+ ## Usage
43
+
44
+ Configure your query with [Kaminari](https://github.com/amatsuda/kaminari) as
45
+ usual:
46
+
47
+ results = User.page(1).per(50)
48
+ results.size # => 50
49
+ results.total_count # => 100
50
+ results.total_pages # => 2
51
+
52
+ Use the `surface` scope to enable surface pagination on a result set. The last
53
+ page will now include up to 50 more results:
54
+
55
+ results = User.page(1).per(50).surface(50)
56
+
57
+ results.size # => 100
58
+ results.total_count # => 100
59
+ results.total_pages # => 1
60
+
61
+ ## Contributing
62
+
63
+ Fork, address the issue, and submit a pull request. You can reach me through the
64
+ tracker or at jkassemi@gmail.com.
65
+
66
+ ### Running Specs
67
+
68
+ ActiveRecord and DataMapper specs run with an in-memory schema, and don't need
69
+ any additional setup.
70
+
71
+ Get a mongo server up and running on your local system (port 27017) so the
72
+ `mongoid` and `mongo_mapper` specs can run. This can be as simple as `$ brew
73
+ install mongodb`.
74
+
75
+ $ bundle # to install the gems from the gemspec
76
+ $ bundle exec rspec # to feel the green
77
+
78
+ ## Integration Goals
79
+
80
+ This release is a proof of concept and designed as a drop-in implementation
81
+ that does not affect the existing kaminari project.
82
+
83
+ Directly modifying and extending kaminari would be a more maintanable solution.
84
+ Once kinks are worked out here then a PR to the kaminari project makes a heck of
85
+ a lot of sense.
86
+
87
+ ## Caveats
88
+
89
+ There are some cases where the use of surfacing pagination may not be
90
+ recommended. The following issues may pop up:
91
+
92
+ 1. The total number of results can no longer be determined by the client
93
+ using the last page number or total pages number since the result count per
94
+ page may vary.
95
+ 1. If a client workflow routinely involves visiting the last page of results
96
+ then filtering through those last results may take longer.
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'bundler/setup'
7
+ rescue LoadError => e
8
+ abort e.message
9
+ end
10
+
11
+ require 'rake'
12
+
13
+
14
+ require 'rubygems/tasks'
15
+ Gem::Tasks.new
16
+
17
+ require 'rdoc/task'
18
+ RDoc::Task.new
19
+ task :doc => :rdoc
20
+
21
+ require 'rspec/core/rake_task'
22
+ RSpec::Core::RakeTask.new
23
+
24
+ task :test => :spec
25
+ task :default => :spec
@@ -0,0 +1,17 @@
1
+ # Version
2
+
3
+ [x] I should have a basic rails application with kaminari pagination (prototyping)
4
+ [x] I should be able to use a functioning prototype of the surfacing pagination (prototyping)
5
+ [x] `README.md` should better present the solution
6
+ [x] The surfacing pagination should be implemented as a basic ruby gem.
7
+
8
+ # Backlog
9
+
10
+ # Icebox
11
+
12
+ [ ] `README.md` should include a series of examples
13
+ [ ] Documentation should detail how to enable explicitly and disable globally.
14
+ [ ] I should be able to conceptualize around an ajax pagination feature (prototyping)
15
+ [ ] I should be able to use surfacing pagination with ajax (prototyping)
16
+ [ ] A default surfacing pagination value should be provided so surfacing is used
17
+ by default if the gem is installed
Binary file
@@ -0,0 +1,17 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-journal
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*
16
+ !/log/.keep
17
+ /tmp
@@ -0,0 +1,52 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'kaminari'
4
+ gem 'haml'
5
+
6
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
7
+ gem 'rails', '4.2.1'
8
+ # Use sqlite3 as the database for Active Record
9
+ gem 'sqlite3'
10
+ # Use SCSS for stylesheets
11
+ gem 'sass-rails', '~> 5.0'
12
+ # Use Uglifier as compressor for JavaScript assets
13
+ gem 'uglifier', '>= 1.3.0'
14
+ # Use CoffeeScript for .coffee assets and views
15
+ gem 'coffee-rails', '~> 4.1.0'
16
+ # See https://github.com/rails/execjs#readme for more supported runtimes
17
+ # gem 'therubyracer', platforms: :ruby
18
+
19
+ # Use jquery as the JavaScript library
20
+ gem 'jquery-rails'
21
+ # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
22
+ gem 'turbolinks'
23
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
24
+ gem 'jbuilder', '~> 2.0'
25
+ # bundle exec rake doc:rails generates the API under doc/api.
26
+ gem 'sdoc', '~> 0.4.0', group: :doc
27
+
28
+ # Use ActiveModel has_secure_password
29
+ # gem 'bcrypt', '~> 3.1.7'
30
+
31
+ # Use Unicorn as the app server
32
+ # gem 'unicorn'
33
+
34
+ # Use Capistrano for deployment
35
+ # gem 'capistrano-rails', group: :development
36
+
37
+ gem 'bootstrap-kaminari-views'
38
+
39
+ group :development, :test do
40
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
41
+ gem 'byebug'
42
+
43
+ # Access an IRB console on exception pages or by using <%= console %> in views
44
+ gem 'web-console', '~> 2.0'
45
+
46
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
47
+ gem 'spring'
48
+
49
+ gem 'pry'
50
+ gem 'faker'
51
+ end
52
+
@@ -0,0 +1,179 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actionmailer (4.2.1)
5
+ actionpack (= 4.2.1)
6
+ actionview (= 4.2.1)
7
+ activejob (= 4.2.1)
8
+ mail (~> 2.5, >= 2.5.4)
9
+ rails-dom-testing (~> 1.0, >= 1.0.5)
10
+ actionpack (4.2.1)
11
+ actionview (= 4.2.1)
12
+ activesupport (= 4.2.1)
13
+ rack (~> 1.6)
14
+ rack-test (~> 0.6.2)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
17
+ actionview (4.2.1)
18
+ activesupport (= 4.2.1)
19
+ builder (~> 3.1)
20
+ erubis (~> 2.7.0)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
23
+ activejob (4.2.1)
24
+ activesupport (= 4.2.1)
25
+ globalid (>= 0.3.0)
26
+ activemodel (4.2.1)
27
+ activesupport (= 4.2.1)
28
+ builder (~> 3.1)
29
+ activerecord (4.2.1)
30
+ activemodel (= 4.2.1)
31
+ activesupport (= 4.2.1)
32
+ arel (~> 6.0)
33
+ activesupport (4.2.1)
34
+ i18n (~> 0.7)
35
+ json (~> 1.7, >= 1.7.7)
36
+ minitest (~> 5.1)
37
+ thread_safe (~> 0.3, >= 0.3.4)
38
+ tzinfo (~> 1.1)
39
+ arel (6.0.3)
40
+ binding_of_caller (0.7.2)
41
+ debug_inspector (>= 0.0.1)
42
+ bootstrap-kaminari-views (0.0.5)
43
+ kaminari (>= 0.13)
44
+ rails (>= 3.1)
45
+ builder (3.2.2)
46
+ byebug (8.2.5)
47
+ coderay (1.1.0)
48
+ coffee-rails (4.1.1)
49
+ coffee-script (>= 2.2.0)
50
+ railties (>= 4.0.0, < 5.1.x)
51
+ coffee-script (2.4.1)
52
+ coffee-script-source
53
+ execjs
54
+ coffee-script-source (1.10.0)
55
+ concurrent-ruby (1.0.1)
56
+ debug_inspector (0.0.2)
57
+ erubis (2.7.0)
58
+ execjs (2.6.0)
59
+ faker (1.4.3)
60
+ i18n (~> 0.5)
61
+ globalid (0.3.6)
62
+ activesupport (>= 4.1.0)
63
+ haml (4.0.6)
64
+ tilt
65
+ i18n (0.7.0)
66
+ jbuilder (2.4.1)
67
+ activesupport (>= 3.0.0, < 5.1)
68
+ multi_json (~> 1.2)
69
+ jquery-rails (4.1.1)
70
+ rails-dom-testing (>= 1, < 3)
71
+ railties (>= 4.2.0)
72
+ thor (>= 0.14, < 2.0)
73
+ json (1.8.3)
74
+ kaminari (0.16.3)
75
+ actionpack (>= 3.0.0)
76
+ activesupport (>= 3.0.0)
77
+ loofah (2.0.3)
78
+ nokogiri (>= 1.5.9)
79
+ mail (2.6.4)
80
+ mime-types (>= 1.16, < 4)
81
+ method_source (0.8.2)
82
+ mime-types (3.0)
83
+ mime-types-data (~> 3.2015)
84
+ mime-types-data (3.2016.0221)
85
+ mini_portile2 (2.0.0)
86
+ minitest (5.8.4)
87
+ multi_json (1.11.3)
88
+ nokogiri (1.6.7.2)
89
+ mini_portile2 (~> 2.0.0.rc2)
90
+ pry (0.10.1)
91
+ coderay (~> 1.1.0)
92
+ method_source (~> 0.8.1)
93
+ slop (~> 3.4)
94
+ rack (1.6.4)
95
+ rack-test (0.6.3)
96
+ rack (>= 1.0)
97
+ rails (4.2.1)
98
+ actionmailer (= 4.2.1)
99
+ actionpack (= 4.2.1)
100
+ actionview (= 4.2.1)
101
+ activejob (= 4.2.1)
102
+ activemodel (= 4.2.1)
103
+ activerecord (= 4.2.1)
104
+ activesupport (= 4.2.1)
105
+ bundler (>= 1.3.0, < 2.0)
106
+ railties (= 4.2.1)
107
+ sprockets-rails
108
+ rails-deprecated_sanitizer (1.0.3)
109
+ activesupport (>= 4.2.0.alpha)
110
+ rails-dom-testing (1.0.7)
111
+ activesupport (>= 4.2.0.beta, < 5.0)
112
+ nokogiri (~> 1.6.0)
113
+ rails-deprecated_sanitizer (>= 1.0.1)
114
+ rails-html-sanitizer (1.0.3)
115
+ loofah (~> 2.0)
116
+ railties (4.2.1)
117
+ actionpack (= 4.2.1)
118
+ activesupport (= 4.2.1)
119
+ rake (>= 0.8.7)
120
+ thor (>= 0.18.1, < 2.0)
121
+ rake (11.1.2)
122
+ rdoc (4.2.2)
123
+ json (~> 1.4)
124
+ sass (3.4.22)
125
+ sass-rails (5.0.4)
126
+ railties (>= 4.0.0, < 5.0)
127
+ sass (~> 3.1)
128
+ sprockets (>= 2.8, < 4.0)
129
+ sprockets-rails (>= 2.0, < 4.0)
130
+ tilt (>= 1.1, < 3)
131
+ sdoc (0.4.1)
132
+ json (~> 1.7, >= 1.7.7)
133
+ rdoc (~> 4.0)
134
+ slop (3.6.0)
135
+ spring (1.7.1)
136
+ sprockets (3.6.0)
137
+ concurrent-ruby (~> 1.0)
138
+ rack (> 1, < 3)
139
+ sprockets-rails (3.0.4)
140
+ actionpack (>= 4.0)
141
+ activesupport (>= 4.0)
142
+ sprockets (>= 3.0.0)
143
+ sqlite3 (1.3.11)
144
+ thor (0.19.1)
145
+ thread_safe (0.3.5)
146
+ tilt (2.0.2)
147
+ turbolinks (2.5.3)
148
+ coffee-rails
149
+ tzinfo (1.2.2)
150
+ thread_safe (~> 0.1)
151
+ uglifier (3.0.0)
152
+ execjs (>= 0.3.0, < 3)
153
+ web-console (2.3.0)
154
+ activemodel (>= 4.0)
155
+ binding_of_caller (>= 0.7.2)
156
+ railties (>= 4.0)
157
+ sprockets-rails (>= 2.0, < 4.0)
158
+
159
+ PLATFORMS
160
+ ruby
161
+
162
+ DEPENDENCIES
163
+ bootstrap-kaminari-views
164
+ byebug
165
+ coffee-rails (~> 4.1.0)
166
+ faker
167
+ haml
168
+ jbuilder (~> 2.0)
169
+ jquery-rails
170
+ kaminari
171
+ pry
172
+ rails (= 4.2.1)
173
+ sass-rails (~> 5.0)
174
+ sdoc (~> 0.4.0)
175
+ spring
176
+ sqlite3
177
+ turbolinks
178
+ uglifier (>= 1.3.0)
179
+ web-console (~> 2.0)