moar 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/Rakefile +1 -2
- data/lib/generators/moar/install/install_generator.rb +0 -2
- data/lib/moar/helper.rb +22 -18
- data/lib/moar/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a326ba6916580da9c124db958eda52918d81fde5d13f6516cb613ac317181002
|
4
|
+
data.tar.gz: 878bac6ff03712086eb27dcb84c00a5982e02314899b52245dca0b7229a3eebe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb2aadac7f69bf538a678a70be57a0405e9834ba45b7661a4d1a76f3002e56ba8d1853c5326d93b46adc862d24b8eb0a5616e012275cad22a1338fe99f70a593
|
7
|
+
data.tar.gz: ffee5afebc4dc869440f63bcde6696b40cdf4de21825d7232843aad01afa79d68f9e3f0da9af2156fd28d31b642286b28299c070dc5dcc880a2d7befa28b65e0
|
data/README.md
CHANGED
@@ -25,6 +25,7 @@ With *moar*, this story can be realized using the following code:
|
|
25
25
|
|
26
26
|
```ruby
|
27
27
|
## app/controllers/posts_controller.rb
|
28
|
+
|
28
29
|
class PostsController < ApplicationController
|
29
30
|
# Step 1 (optional): set controller-specific pagination increments
|
30
31
|
moar_increments [10, 20, 30]
|
@@ -36,8 +37,9 @@ class PostsController < ApplicationController
|
|
36
37
|
end
|
37
38
|
```
|
38
39
|
|
39
|
-
```erb
|
40
|
+
```html+erb
|
40
41
|
<!-- app/views/posts/index.html.erb -->
|
42
|
+
|
41
43
|
<h1>Posts</h1>
|
42
44
|
<ul id="list-of-posts">
|
43
45
|
<% @posts.each do |post| %>
|
data/Rakefile
CHANGED
@@ -9,14 +9,13 @@ require 'yard'
|
|
9
9
|
YARD::Rake::YardocTask.new(:doc) do |t|
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
12
|
require 'bundler/gem_tasks'
|
14
13
|
|
15
14
|
require 'rake/testtask'
|
16
15
|
|
17
16
|
Rake::TestTask.new(:test) do |t|
|
18
17
|
t.libs << 'test'
|
19
|
-
t.
|
18
|
+
t.test_files = FileList['test/**/*_test.rb'].exclude('test/tmp/**/*')
|
20
19
|
t.verbose = false
|
21
20
|
end
|
22
21
|
|
data/lib/moar/helper.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
module Moar
|
2
2
|
module Helper
|
3
3
|
|
4
|
-
#
|
5
|
-
# If JavaScript is
|
4
|
+
# Renders an anchor element that links to more paginated results.
|
5
|
+
# If JavaScript is enabled, and the current page number is less than
|
6
6
|
# the number of pagination increments (see {Moar::Config#increments}
|
7
7
|
# or {Moar::Controller::ClassMethods#moar_increments}), the link
|
8
|
-
# will use Ajax to fetch the results and
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# page of results.
|
8
|
+
# will use Ajax to fetch the results and append them to the element
|
9
|
+
# matching the CSS selector specified by +target+. Otherwise, the
|
10
|
+
# link will navigate to the next page of results.
|
12
11
|
#
|
13
12
|
# The text of the link is determined via I18n using translation key
|
14
13
|
# +:"moar.more"+. A +results_name+ interpolation argument is
|
@@ -18,17 +17,13 @@ module Moar
|
|
18
17
|
# is an array of +CowBell+ models, the link text will be "Need more
|
19
18
|
# cow bells!".
|
20
19
|
#
|
21
|
-
# This helper method accepts an +html_options+ Hash, and passes it
|
22
|
-
# to Rails' +ActionView::Helpers::UrlHelper#link_to+. See its
|
23
|
-
# documentation for information about available options.
|
24
|
-
#
|
25
20
|
# If no more results are available, this helper method will return
|
26
21
|
# nil so that no link is rendered. Whether there are more results
|
27
|
-
# is estimated by comparing +results.
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
22
|
+
# is estimated by comparing +results.size+ with the limit applied by
|
23
|
+
# {Moar::Controller#moar}. This technique eliminates the need for
|
24
|
+
# an extra database query, but can result in a false positive (i.e.
|
25
|
+
# rendering a link to an empty page) when the actual last page of
|
26
|
+
# results is also a full page. This is deemed an acceptable
|
32
27
|
# trade-off because with a large number of pages and a large total
|
33
28
|
# number of results per page it is an unlikely occurrence, and
|
34
29
|
# because an extra database query cannot entirely prevent a link to
|
@@ -36,23 +31,32 @@ module Moar
|
|
36
31
|
# user can click through to the final page.
|
37
32
|
#
|
38
33
|
# @param results [ActiveRecord::Relation, Array<ActiveModel::Naming>]
|
34
|
+
# query results for current page
|
39
35
|
# @param target [String]
|
36
|
+
# CSS selector of element containing rendered results
|
40
37
|
# @param html_options [Hash]
|
38
|
+
# HTML options (see +ActionView::Helpers::UrlHelper#link_to+)
|
41
39
|
# @return [String, nil]
|
42
40
|
# @raise [RuntimeError]
|
43
41
|
# if controller action did not invoke {Moar::Controller#moar}
|
44
42
|
def link_to_more(results, target, html_options = {})
|
45
43
|
raise "#{controller.class}##{action_name} did not invoke #moar" unless defined?(@moar)
|
46
44
|
|
47
|
-
unless results.
|
45
|
+
unless results.size < @moar.limit
|
48
46
|
params = request.query_parameters.except(Moar.config.accumulation_param.to_s)
|
49
47
|
params[Moar.config.page_param.to_s] = @moar.page + 1
|
50
48
|
|
51
49
|
options = { controller: controller_path, action: action_name, params: params }
|
52
50
|
|
51
|
+
model_name = if results.is_a?(ActiveRecord::Relation)
|
52
|
+
results.model
|
53
|
+
else
|
54
|
+
results.first
|
55
|
+
end.model_name
|
56
|
+
|
53
57
|
i18n_options = {
|
54
|
-
results_name:
|
55
|
-
count: 2, default:
|
58
|
+
results_name: model_name.human(
|
59
|
+
count: 2, default: model_name.human.pluralize(I18n.locale)
|
56
60
|
).downcase,
|
57
61
|
}
|
58
62
|
|
data/lib/moar/version.rb
CHANGED
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Hefner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -168,8 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
- !ruby/object:Gem::Version
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
|
-
|
172
|
-
rubygems_version: 2.7.6
|
171
|
+
rubygems_version: 3.0.1
|
173
172
|
signing_key:
|
174
173
|
specification_version: 4
|
175
174
|
summary: More-style pagination for Rails
|