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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 373ef27d71c2ca92b75dcff62c92ef113b7808d3
4
- data.tar.gz: 2d55d969cdbbad4233afec8d93f2b62c7bfd7e04
3
+ metadata.gz: a186f2ffcfcf6c4ace38907c0599b20b024cef38
4
+ data.tar.gz: 80083dda88f4738bd2b7b5c962d8e4f4bac881df
5
5
  SHA512:
6
- metadata.gz: e4804bb18efd502e2ce4488a649366a78c40b6c2fc2b0d6fac9333609c31a4a2c0191f922b798c5b87d5de2f4f0665db0f31563e73a6e57e8a97965e3ddee7c4
7
- data.tar.gz: b5a300aeb3e643557ee663482342b4f3f3d5775fa4bf0b511f92f8db572a844d8a1e78b0444b57b1869d4ed8acf19615348f3a5d1dabd899cab604c9402c0465
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.find({active: true}).skip((params._page || 1).to_i - 1) * 10).limit(10)
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
- total = total_pages()
27
- cpage = current_page()
26
+ total_pages.then do |total|
28
27
 
29
- start_pos, end_pos = middle_window(cpage, total)
30
- middle_window = (start_pos..end_pos).to_a
28
+ cpage = current_page()
31
29
 
32
- if outer_window == 0
33
- pages = middle_window
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
- start_outer_pos = [1 + side_size, start_pos-1].min
38
- end_outer_pos = [total - side_size, end_pos + 1].max
33
+ if outer_window == 0
34
+ pages = middle_window
35
+ else
36
+ side_size = ((outer_window - 1) / 2).ceil
39
37
 
40
- start_window = (1..start_outer_pos).to_a
41
- end_window = (end_outer_pos..total).to_a
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
- pages = start_window
44
- pages << nil unless start_outer_pos == (middle_window[0] - 1)
45
- pages += middle_window
46
- pages << nil unless end_outer_pos == middle_window[-1] + 1
47
- pages += end_window
48
- end
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
- return pages
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
- (attrs.total.to_i / per_page.to_f).ceil
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
- new_page = current_page + 1
83
- if new_page > total_pages
84
- return ''
85
- end
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
- return url_for_page(new_page)
93
+ url_for_page(new_page)
94
+ end
88
95
  end
89
96
 
90
97
  def previous_page_url
@@ -1,18 +1,17 @@
1
- <:Body>
2
- <ul class="pagination">
3
- <li class="{{ if first_page }}disabled{{ end }}">
4
- <a href="{{ previous_page_url }}">&laquo;</a>
5
- </li>
6
- {{ page_numbers.each do |page_number| }}
7
- {{ if page_number.nil? }}
8
- <li><a>...</a></li>
9
- {{ else }}
10
- <li class="{{ if current_page == page_number }}active{{ end }}">
11
- <a href="{{ url_for_page(page_number) }}">{{ page_number }}</a>
12
- </li>
13
- {{ end }}
1
+ <ul class="pagination">
2
+ <li class="{{ if first_page }}disabled{{ end }}">
3
+ <a href="{{ previous_page_url }}">&laquo;</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
- <li class="{{ if last_page }}disabled{{ end }}">
16
- <a href="{{ next_page_url }}">&raquo;</a>
17
- </li>
18
- </ul>
13
+ {{ end }}
14
+ <li class="{{ if last_page }}disabled{{ end }}">
15
+ <a href="{{ next_page_url }}">&raquo;</a>
16
+ </li>
17
+ </ul>
@@ -1,7 +1,7 @@
1
1
  require "volt/pagination/version"
2
2
 
3
- class Volt
4
- class Pagination
3
+ module Volt
4
+ module Pagination
5
5
  # Your code goes here...
6
6
  end
7
7
  end
@@ -0,0 +1,5 @@
1
+ module Volt
2
+ module Pagination
3
+ VERSION = '0.2.1'
4
+ end
5
+ end
@@ -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 = 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.0
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-04-07 00:00:00.000000000 Z
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.2.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