kaminari_route_prefix 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 127bda09361712de2ab892f54b7c1679d61d3102
4
+ data.tar.gz: 64e0ac99f6f3dc0a0b3e150bea2798339f8a7310
5
+ SHA512:
6
+ metadata.gz: 5c927427e6c274d2b3ceed23a4e150a2c7f86cf1ddd05a2b9094562713544413cb2910ebf3e9db83ee4bb0afa62552c3da993591d934ee1ab83a804ec70d0996
7
+ data.tar.gz: ee96e79b9afdad5cab842306b5abbe80e6c2f815352f5b09de2fd1875132a17d57a3b11bc2f0dcfa4ae2488d8705c74d765a977bcfc597ffcd61615b0aba20a5
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /spec/fake_app/log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kaminari_route_prefix.gemspec
4
+ gemspec
5
+
6
+ gem 'byebug'
7
+ #gem 'kaminari', github: 'amatsuda/kaminari'
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ # Copyright 2016 Chris Beer
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.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # KaminariRoutePrefix
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kaminari_route_prefix`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kaminari_route_prefix'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kaminari_route_prefix
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kaminari_route_prefix.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kaminari_route_prefix"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kaminari_route_prefix/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kaminari_route_prefix"
8
+ spec.version = KaminariRoutePrefix::VERSION
9
+ spec.authors = ["Chris Beer"]
10
+ spec.email = ["cabeer@stanford.edu"]
11
+
12
+ spec.summary = %q{Monkey-patch kaminari to work well with Rails engines}
13
+ spec.description = %q{Upstream pull request: https://github.com/amatsuda/kaminari/pull/636}
14
+ spec.homepage = "https://github.com/cbeer/kaminari_route_prefix"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'kaminari', '>= 0.16', '< 2'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "rspec-rails", "~> 3.0"
27
+ spec.add_development_dependency "railties"
28
+ spec.add_development_dependency "activerecord"
29
+ spec.add_development_dependency "sqlite3"
30
+ spec.add_development_dependency "database_cleaner"
31
+ end
@@ -0,0 +1,21 @@
1
+ require 'kaminari_route_prefix/version'
2
+
3
+ # load Rails/Railtie
4
+ begin
5
+ require 'rails'
6
+ rescue LoadError
7
+ # do nothing
8
+ end
9
+
10
+ require 'kaminari'
11
+ require 'kaminari/version'
12
+
13
+ module KaminariRoutePrefix
14
+ require 'kaminari_route_prefix/engine' if defined? Rails
15
+
16
+ require 'kaminari_route_prefix/helpers/tags'
17
+
18
+ if Kaminari::VERSION < '2.0'
19
+ require 'kaminari_route_prefix/helpers/action_view_extension'
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ module KaminariRoutePrefix #:nodoc:
2
+ class Engine < ::Rails::Engine #:nodoc:
3
+ end
4
+ end
@@ -0,0 +1,134 @@
1
+ require 'kaminari/helpers/action_view_extension'
2
+
3
+ module KaminariRoutePrefix
4
+ module ActionViewExtension
5
+ # A helper that renders the pagination links.
6
+ #
7
+ # <%= paginate @articles %>
8
+ #
9
+ # ==== Options
10
+ # * <tt>:window</tt> - The "inner window" size (4 by default).
11
+ # * <tt>:outer_window</tt> - The "outer window" size (0 by default).
12
+ # * <tt>:left</tt> - The "left outer window" size (0 by default).
13
+ # * <tt>:right</tt> - The "right outer window" size (0 by default).
14
+ # * <tt>:params</tt> - url_for parameters for the links (:controller, :action, etc.)
15
+ # * <tt>:param_name</tt> - parameter name for page number in the links (:page by default)
16
+ # * <tt>:remote</tt> - Ajax? (false by default)
17
+ # * <tt>:ANY_OTHER_VALUES</tt> - Any other hash key & values would be directly passed into each tag as :locals value.
18
+ def paginate(scope, options = {})
19
+ options[:total_pages] ||= options[:num_pages] || scope.total_pages
20
+
21
+ paginator = Kaminari::Helpers::Paginator.new(self, options.reverse_merge(:current_page => scope.current_page, :per_page => scope.limit_value, :remote => false))
22
+ paginator.to_s
23
+ end
24
+
25
+ # A simple "Twitter like" pagination link that creates a link to the previous page.
26
+ #
27
+ # ==== Examples
28
+ # Basic usage:
29
+ #
30
+ # <%= link_to_previous_page @items, 'Previous Page' %>
31
+ #
32
+ # Ajax:
33
+ #
34
+ # <%= link_to_previous_page @items, 'Previous Page', :remote => true %>
35
+ #
36
+ # By default, it renders nothing if there are no more results on the previous page.
37
+ # You can customize this output by passing a block.
38
+ #
39
+ # <%= link_to_previous_page @users, 'Previous Page' do %>
40
+ # <span>At the Beginning</span>
41
+ # <% end %>
42
+ def link_to_previous_page(scope, name, options = {}, &block)
43
+ prev_page = Kaminari::Helpers::PrevPage.new self, options.reverse_merge(:current_page => scope.current_page)
44
+
45
+ link_to_if scope.prev_page.present?, name, prev_page.url, options.except(:params, :param_name).reverse_merge(:rel => 'prev') do
46
+ block.call if block
47
+ end
48
+ end
49
+
50
+ # A simple "Twitter like" pagination link that creates a link to the next page.
51
+ #
52
+ # ==== Examples
53
+ # Basic usage:
54
+ #
55
+ # <%= link_to_next_page @items, 'Next Page' %>
56
+ #
57
+ # Ajax:
58
+ #
59
+ # <%= link_to_next_page @items, 'Next Page', :remote => true %>
60
+ #
61
+ # By default, it renders nothing if there are no more results on the next page.
62
+ # You can customize this output by passing a block.
63
+ #
64
+ # <%= link_to_next_page @users, 'Next Page' do %>
65
+ # <span>No More Pages</span>
66
+ # <% end %>
67
+ def link_to_next_page(scope, name, options = {}, &block)
68
+ next_page = Kaminari::Helpers::NextPage.new self, options.reverse_merge(:current_page => scope.current_page)
69
+
70
+ link_to_if scope.next_page.present?, name, next_page.url, options.except(:params, :param_name).reverse_merge(:rel => 'next') do
71
+ block.call if block
72
+ end
73
+ end
74
+
75
+ # Renders a helpful message with numbers of displayed vs. total entries.
76
+ # Ported from mislav/will_paginate
77
+ #
78
+ # ==== Examples
79
+ # Basic usage:
80
+ #
81
+ # <%= page_entries_info @posts %>
82
+ # #-> Displaying posts 6 - 10 of 26 in total
83
+ #
84
+ # By default, the message will use the humanized class name of objects
85
+ # in collection: for instance, "project types" for ProjectType models.
86
+ # The namespace will be cutted out and only the last name will be used.
87
+ # Override this with the <tt>:entry_name</tt> parameter:
88
+ #
89
+ # <%= page_entries_info @posts, :entry_name => 'item' %>
90
+ # #-> Displaying items 6 - 10 of 26 in total
91
+ def page_entries_info(collection, options = {})
92
+ entry_name = options[:entry_name] || collection.entry_name
93
+ entry_name = entry_name.pluralize unless collection.total_count == 1
94
+
95
+ if collection.total_pages < 2
96
+ t('helpers.page_entries_info.one_page.display_entries', :entry_name => entry_name, :count => collection.total_count)
97
+ else
98
+ first = collection.offset_value + 1
99
+ last = collection.last_page? ? collection.total_count : collection.offset_value + collection.limit_value
100
+ t('helpers.page_entries_info.more_pages.display_entries', :entry_name => entry_name, :first => first, :last => last, :total => collection.total_count)
101
+ end.html_safe
102
+ end
103
+
104
+ # Renders rel="next" and rel="prev" links to be used in the head.
105
+ #
106
+ # ==== Examples
107
+ # Basic usage:
108
+ #
109
+ # In head:
110
+ # <head>
111
+ # <title>My Website</title>
112
+ # <%= yield :head %>
113
+ # </head>
114
+ #
115
+ # Somewhere in body:
116
+ # <% content_for :head do %>
117
+ # <%= rel_next_prev_link_tags @items %>
118
+ # <% end %>
119
+ #
120
+ # #-> <link rel="next" href="/items/page/3" /><link rel="prev" href="/items/page/1" />
121
+ #
122
+ def rel_next_prev_link_tags(scope, options = {})
123
+ next_page = Kaminari::Helpers::NextPage.new self, options.reverse_merge(:current_page => scope.current_page)
124
+ prev_page = Kaminari::Helpers::PrevPage.new self, options.reverse_merge(:current_page => scope.current_page)
125
+
126
+ output = String.new
127
+ output << tag(:link, :rel => "next", :href => next_page.url) if scope.next_page.present?
128
+ output << tag(:link, :rel => "prev", :href => prev_page.url) if scope.prev_page.present?
129
+ output.html_safe
130
+ end
131
+ end
132
+ end
133
+
134
+ Kaminari::ActionViewExtension.prepend KaminariRoutePrefix::ActionViewExtension
@@ -0,0 +1,33 @@
1
+ require 'kaminari/helpers/tags'
2
+
3
+ module KaminariRoutePrefix
4
+ module TagExtensions
5
+ def initialize_route_set(template, options = {})
6
+ @route_set = @options.delete(:route_set)
7
+ end
8
+
9
+ def page_url_for_route_set(page)
10
+ @route_set.url_for @params.merge(@param_name => (page <= 1 ? nil : page), only_path: true)
11
+ end
12
+ end
13
+ end
14
+
15
+ Kaminari::Helpers::Tag.prepend KaminariRoutePrefix::TagExtensions
16
+
17
+ class Kaminari::Helpers::Tag
18
+ alias original_initialize initialize
19
+ alias original_page_url_for page_url_for
20
+
21
+ def initialize(*args)
22
+ original_initialize(*args)
23
+ initialize_route_set(*args)
24
+ end
25
+
26
+ def page_url_for(page)
27
+ if @route_set
28
+ page_url_for_route_set(page)
29
+ else
30
+ original_page_url_for(page)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module KaminariRoutePrefix
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kaminari_route_prefix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Beer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kaminari
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.16'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0.16'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.11'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.11'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec-rails
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: railties
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: activerecord
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: sqlite3
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: database_cleaner
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ description: 'Upstream pull request: https://github.com/amatsuda/kaminari/pull/636'
146
+ email:
147
+ - cabeer@stanford.edu
148
+ executables: []
149
+ extensions: []
150
+ extra_rdoc_files: []
151
+ files:
152
+ - ".gitignore"
153
+ - ".rspec"
154
+ - ".travis.yml"
155
+ - Gemfile
156
+ - LICENSE
157
+ - README.md
158
+ - Rakefile
159
+ - bin/console
160
+ - bin/setup
161
+ - kaminari_route_prefix.gemspec
162
+ - lib/kaminari_route_prefix.rb
163
+ - lib/kaminari_route_prefix/engine.rb
164
+ - lib/kaminari_route_prefix/helpers/action_view_extension.rb
165
+ - lib/kaminari_route_prefix/helpers/tags.rb
166
+ - lib/kaminari_route_prefix/version.rb
167
+ homepage: https://github.com/cbeer/kaminari_route_prefix
168
+ licenses: []
169
+ metadata: {}
170
+ post_install_message:
171
+ rdoc_options: []
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubyforge_project:
186
+ rubygems_version: 2.4.5.1
187
+ signing_key:
188
+ specification_version: 4
189
+ summary: Monkey-patch kaminari to work well with Rails engines
190
+ test_files: []