volt-pagination 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/pagination/controllers/main_controller.rb +32 -25
- data/app/pagination/views/main/index.html +16 -17
- data/lib/volt/pagination.rb +2 -2
- data/lib/volt/pagination/version.rb +5 -0
- data/volt-pagination.gemspec +2 -4
- metadata +4 -18
- data/VERSION +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a186f2ffcfcf6c4ace38907c0599b20b024cef38
|
4
|
+
data.tar.gz: 80083dda88f4738bd2b7b5c962d8e4f4bac881df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdf762278f0b42c9944ace9009e2cf1c84c221f4ed74656aebc930cdae07f5181d4da6a330ad99ab1e87d1f0a2a8d221ffdbd2b2799756f670caac79621600d9
|
7
|
+
data.tar.gz: 9682d06b831441e9ed0c8e1a06032781b7211d8409c56193eecd10067d1182d1baaa412c82d6d69ad68e77c575202b7dc3d136d18135c5c2b1492e25e5739169
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ To page a collection or query, simply use ```.skip``` and ```.limit```
|
|
20
20
|
Assuming a page size of 10:
|
21
21
|
|
22
22
|
def items_on_page
|
23
|
-
store._items.
|
23
|
+
store._items.where({active: true}).skip((params._page || 1).to_i - 1) * 10).limit(10).all
|
24
24
|
end
|
25
25
|
|
26
26
|
Then in your view you can add:
|
@@ -23,31 +23,33 @@ module Pagination
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def page_numbers
|
26
|
-
|
27
|
-
cpage = current_page()
|
26
|
+
total_pages.then do |total|
|
28
27
|
|
29
|
-
|
30
|
-
middle_window = (start_pos..end_pos).to_a
|
28
|
+
cpage = current_page()
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
else
|
35
|
-
side_size = ((outer_window - 1) / 2).ceil
|
30
|
+
start_pos, end_pos = middle_window(cpage, total)
|
31
|
+
middle_window = (start_pos..end_pos).to_a
|
36
32
|
|
37
|
-
|
38
|
-
|
33
|
+
if outer_window == 0
|
34
|
+
pages = middle_window
|
35
|
+
else
|
36
|
+
side_size = ((outer_window - 1) / 2).ceil
|
39
37
|
|
40
|
-
|
41
|
-
|
38
|
+
start_outer_pos = [1 + side_size, start_pos-1].min
|
39
|
+
end_outer_pos = [total - side_size, end_pos + 1].max
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
start_window = (1..start_outer_pos).to_a
|
42
|
+
end_window = (end_outer_pos..total).to_a
|
43
|
+
|
44
|
+
pages = start_window
|
45
|
+
pages << nil unless start_outer_pos == (middle_window[0] - 1)
|
46
|
+
pages += middle_window
|
47
|
+
pages << nil unless end_outer_pos == middle_window[-1] + 1
|
48
|
+
pages += end_window
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
+
pages
|
52
|
+
end
|
51
53
|
end
|
52
54
|
|
53
55
|
def window
|
@@ -66,8 +68,11 @@ module Pagination
|
|
66
68
|
(params.send(:"_#{page_param_name}") || 1).to_i
|
67
69
|
end
|
68
70
|
|
71
|
+
# Assumes a promise and returns a promise
|
69
72
|
def total_pages
|
70
|
-
|
73
|
+
attrs.total.then do |total|
|
74
|
+
(total.to_i / per_page.to_f).ceil
|
75
|
+
end
|
71
76
|
end
|
72
77
|
|
73
78
|
def last_page
|
@@ -79,12 +84,14 @@ module Pagination
|
|
79
84
|
end
|
80
85
|
|
81
86
|
def next_page_url
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
87
|
+
total_pages.then do |total_pages|
|
88
|
+
new_page = current_page + 1
|
89
|
+
if new_page > total_pages
|
90
|
+
next ''
|
91
|
+
end
|
86
92
|
|
87
|
-
|
93
|
+
url_for_page(new_page)
|
94
|
+
end
|
88
95
|
end
|
89
96
|
|
90
97
|
def previous_page_url
|
@@ -1,18 +1,17 @@
|
|
1
|
-
|
2
|
-
<
|
3
|
-
<
|
4
|
-
|
5
|
-
|
6
|
-
{{
|
7
|
-
|
8
|
-
|
9
|
-
{{
|
10
|
-
<
|
11
|
-
|
12
|
-
</li>
|
13
|
-
{{ end }}
|
1
|
+
<ul class="pagination">
|
2
|
+
<li class="{{ if first_page }}disabled{{ end }}">
|
3
|
+
<a href="{{ previous_page_url }}">«</a>
|
4
|
+
</li>
|
5
|
+
{{ page_numbers.each do |page_number| }}
|
6
|
+
{{ if page_number.nil? }}
|
7
|
+
<li><a>...</a></li>
|
8
|
+
{{ else }}
|
9
|
+
<li class="{{ if current_page == page_number }}active{{ end }}">
|
10
|
+
<a href="{{ url_for_page(page_number) }}">{{ page_number }}</a>
|
11
|
+
</li>
|
14
12
|
{{ end }}
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
</
|
13
|
+
{{ end }}
|
14
|
+
<li class="{{ if last_page }}disabled{{ end }}">
|
15
|
+
<a href="{{ next_page_url }}">»</a>
|
16
|
+
</li>
|
17
|
+
</ul>
|
data/lib/volt/pagination.rb
CHANGED
data/volt-pagination.gemspec
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
|
5
|
-
version = File.read(File.expand_path('../VERSION', __FILE__)).strip
|
4
|
+
require 'volt/pagination/version'
|
6
5
|
|
7
6
|
|
8
7
|
Gem::Specification.new do |spec|
|
9
8
|
spec.name = "volt-pagination"
|
10
|
-
spec.version =
|
9
|
+
spec.version = Volt::Pagination::VERSION
|
11
10
|
spec.authors = ["Ryan Stout"]
|
12
11
|
spec.email = ["ryanstout@gmail.com"]
|
13
12
|
spec.summary = %q{A Volt component that provides a :pagination tag}
|
@@ -19,6 +18,5 @@ Gem::Specification.new do |spec|
|
|
19
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
19
|
spec.require_paths = ["lib"]
|
21
20
|
|
22
|
-
spec.add_development_dependency "volt", "~> 0.8.0"
|
23
21
|
spec.add_development_dependency "rake"
|
24
22
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: volt-pagination
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Stout
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: volt
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.8.0
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.8.0
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -49,12 +35,12 @@ files:
|
|
49
35
|
- Gemfile
|
50
36
|
- README.md
|
51
37
|
- Rakefile
|
52
|
-
- VERSION
|
53
38
|
- app/pagination/config/dependencies.rb
|
54
39
|
- app/pagination/config/routes.rb
|
55
40
|
- app/pagination/controllers/main_controller.rb
|
56
41
|
- app/pagination/views/main/index.html
|
57
42
|
- lib/volt/pagination.rb
|
43
|
+
- lib/volt/pagination/version.rb
|
58
44
|
- volt-pagination.gemspec
|
59
45
|
homepage: ''
|
60
46
|
licenses:
|
@@ -76,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
62
|
version: '0'
|
77
63
|
requirements: []
|
78
64
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.
|
65
|
+
rubygems_version: 2.4.5
|
80
66
|
signing_key:
|
81
67
|
specification_version: 4
|
82
68
|
summary: A Volt component that provides a :pagination tag
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.0
|