smart_pagination 0.2.6 → 0.2.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3914632522e00ca6ba04328501f0ee2b3640075e5f741935923263870db9f3c0
4
- data.tar.gz: b49c5a85f4e2d0bc2e17631ce742face1b0d8229d6a627723fc30f180a0fed98
3
+ metadata.gz: 622958f99bacc734c5e67d7371358dc02b814582c9765f7b0dd097aa05f5ef1c
4
+ data.tar.gz: 71e2679df477bf457a4e368de908d8e841c870063284bc21041fb6e059be7558
5
5
  SHA512:
6
- metadata.gz: 9674a59d5b985baec207bb8176666a32e0882583d54561d69f38cbeaf81de0693e5303ff21f8341778d0b9c45fba2f2b31937c2f21447f8e42f4e0319a3d6c0c
7
- data.tar.gz: a94144d2bf68180725da5c73190bcd68a2ddb05316adab489661cee0371497f66c0427a36deb1bf7ab438683178b462c25a3202eee3986a07b2cc6b7085c1c1a
6
+ metadata.gz: 0fd88c944be240ff5727bdeb2916f5c2e828c0776d21b533f9c99d2a51369dad2f7bfb0d14646b821ee777051556d0976f495b5baffe6afc2d35659f5a3468f6
7
+ data.tar.gz: b4084bb59c6114a8135ce408443e80b25f2a51b06a228dcdbee11909ebf770e53818332f1799633b2c66c5905498c32a3ae189679088c17de8b9eb85b64a4d2a
data/README.md CHANGED
@@ -92,12 +92,8 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
92
92
 
93
93
  ## Contributing
94
94
 
95
- Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/smart-pagination. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
95
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/smart-pagination.
96
96
 
97
97
  ## License
98
98
 
99
99
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
100
-
101
- ## Code of Conduct
102
-
103
- Everyone interacting in the SmartPagination project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hardpixel/smart-pagination/blob/master/CODE_OF_CONDUCT.md).
@@ -1,29 +1,23 @@
1
1
  module SmartPagination
2
2
  module Helper
3
- # Render pagination links
4
- def smart_pagination_for(collection, options={})
3
+ def smart_pagination_for(collection, options = {})
5
4
  SmartPagination::Renderer.new(self, collection, options).render
6
5
  end
7
6
 
8
- # Alias helper method
9
7
  alias :pagination_for :smart_pagination_for
10
8
 
11
- # Render pager links
12
- def smart_pager_for(collection, options={})
9
+ def smart_pager_for(collection, options = {})
13
10
  options = options.merge(pager_mode: true)
14
11
  SmartPagination::Renderer.new(self, collection, options).render
15
12
  end
16
13
 
17
- # Alias helper method
18
14
  alias :pager_for :smart_pager_for
19
15
 
20
- # Render pagination info text
21
- def smart_pagination_info_for(collection, options={})
16
+ def smart_pagination_info_for(collection, options = {})
22
17
  options = options.merge(info_mode: true)
23
18
  SmartPagination::Renderer.new(self, collection, options).render
24
19
  end
25
20
 
26
- # Alias helper method
27
21
  alias :pagination_info_for :smart_pagination_info_for
28
22
  end
29
23
  end
@@ -1,13 +1,11 @@
1
1
  module SmartPagination
2
2
  class Renderer
3
- # Initialize pagination renderer
4
- def initialize(context, collection, options={})
3
+ def initialize(context, collection, options = {})
5
4
  @context = context
6
5
  @collection = collection
7
6
  @options = default_options.merge(options)
8
7
  end
9
8
 
10
- # Render pagination links
11
9
  def render
12
10
  if auto_hide?
13
11
  nil
@@ -22,221 +20,195 @@ module SmartPagination
22
20
 
23
21
  private
24
22
 
25
- # Default options
26
- def default_options
27
- {
28
- info_mode: false,
29
- pager_mode: false,
30
- auto_hide: false,
31
- item_class: '',
32
- previous_text: '«',
33
- previous_class: 'previous',
34
- next_text: '»',
35
- next_class: 'next',
36
- active_class: 'active',
37
- disabled_class: 'disabled',
38
- wrapper: 'ul',
39
- wrapper_class: 'pagination',
40
- item_wrapper: 'li',
41
- inner_window: 2,
42
- outer_window: 0
43
- }
44
- end
23
+ def default_options
24
+ {
25
+ info_mode: false,
26
+ pager_mode: false,
27
+ auto_hide: false,
28
+ item_class: '',
29
+ previous_text: '«',
30
+ previous_class: 'previous',
31
+ next_text: '»',
32
+ next_class: 'next',
33
+ active_class: 'active',
34
+ disabled_class: 'disabled',
35
+ wrapper: 'ul',
36
+ wrapper_class: 'pagination',
37
+ item_wrapper: 'li',
38
+ inner_window: 2,
39
+ outer_window: 0
40
+ }
41
+ end
45
42
 
46
- # Get collection name
47
- def collection_name
48
- if @collection.is_a? ActiveRecord::Relation
49
- @collection.model_name.human(count: total_entries)
50
- else
51
- total_entries == 1 ? 'Item' : 'Items'
52
- end
43
+ def collection_name
44
+ if @collection.is_a? ActiveRecord::Relation
45
+ @collection.model_name.human(count: total_entries)
46
+ else
47
+ total_entries == 1 ? 'Item' : 'Items'
53
48
  end
49
+ end
54
50
 
55
- # Get current_page
56
- def current_page
57
- @collection.current_page.to_i
58
- end
51
+ def current_page
52
+ @collection.current_page.to_i
53
+ end
59
54
 
60
- # Get total pages
61
- def total_pages
62
- @total_pages ||= @collection.total_pages.to_i
63
- end
55
+ def total_pages
56
+ @total_pages ||= @collection.total_pages.to_i
57
+ end
64
58
 
65
- # Check if current page
66
- def current_page?(page)
67
- page.to_i == current_page
68
- end
59
+ def current_page?(page)
60
+ page.to_i == current_page
61
+ end
69
62
 
70
- # Get entries per page
71
- def per_page
72
- @collection.per_page.to_i
73
- end
63
+ def per_page
64
+ @collection.per_page.to_i
65
+ end
74
66
 
75
- # Get current entries
76
- def current_entries
77
- entries = current_page * per_page
78
- entries < total_entries ? entries : total_entries
79
- end
67
+ def current_entries
68
+ entries = current_page * per_page
69
+ entries < total_entries ? entries : total_entries
70
+ end
80
71
 
81
- # Get total entries
82
- def total_entries
83
- @total_entries ||= @collection.total_entries.to_i
84
- end
72
+ def total_entries
73
+ @total_entries ||= @collection.total_entries.to_i
74
+ end
85
75
 
86
- # Check if should hide pagination
87
- def auto_hide?
88
- @options[:auto_hide].present? and total_pages < 2
89
- end
76
+ def auto_hide?
77
+ @options[:auto_hide].present? and total_pages < 2
78
+ end
90
79
 
91
- # Check if pager mode enabled
92
- def pager_mode?
93
- @options[:pager_mode].present?
94
- end
80
+ def pager_mode?
81
+ @options[:pager_mode].present?
82
+ end
95
83
 
96
- # Check if info mode enabled
97
- def info_mode?
98
- @options[:info_mode].present?
99
- end
84
+ def info_mode?
85
+ @options[:info_mode].present?
86
+ end
100
87
 
101
- # Current url parameters
102
- def url_params
103
- url = URI.parse(@context.request.url)
104
- params = Rack::Utils.parse_nested_query(url.query).symbolize_keys
88
+ def url_params
89
+ url = URI.parse(@context.request.url)
90
+ params = Rack::Utils.parse_nested_query(url.query).symbolize_keys
105
91
 
106
- params.except(:page)
107
- end
92
+ params.except(:page)
93
+ end
108
94
 
109
- # Get page numbers
110
- def page_numbers
111
- inner = @options[:inner_window].to_i
112
- outer = @options[:outer_window].to_i
113
- from = current_page - inner
114
- to = current_page + inner
115
-
116
- if to > total_pages
117
- from -= to - total_pages
118
- to = total_pages
119
- end
120
-
121
- if from < 1
122
- to += 1 - from
123
- from = 1
124
- to = total_pages if to > total_pages
125
- end
126
-
127
- middle = from..to
128
-
129
- if outer + 3 < middle.first
130
- left = (1..(outer + 1)).to_a
131
- left << :sep
132
- else
133
- left = 1...middle.first
134
- end
135
-
136
- if total_pages - outer - 2 > middle.last
137
- right = ((total_pages - outer)..total_pages).to_a
138
- right.unshift :sep
139
- else
140
- right = (middle.last + 1)..total_pages
141
- end
142
-
143
- left.to_a + middle.to_a + right.to_a
144
- end
95
+ def page_numbers
96
+ inner = @options[:inner_window].to_i
97
+ outer = @options[:outer_window].to_i
98
+ from = current_page - inner
99
+ to = current_page + inner
145
100
 
146
- # Get link params
147
- def link_params(page)
148
- page = @collection.send(:"#{page}_page") unless page.is_a? Integer
149
- { page: page }
101
+ if to > total_pages
102
+ from -= to - total_pages
103
+ to = total_pages
150
104
  end
151
105
 
152
- # Get link options
153
- def link_options(page)
154
- if page.is_a? Integer
155
- active = @options[:active_class] if current_page? page
156
- { class: "#{@options[:item_class]} #{active}".strip }
157
- else
158
- disabled = @options[:disabled_class] unless @collection.send(:"#{page}_page?")
159
- item_class = @options[:"#{page}_class"]
160
-
161
- { class: "#{@options[:item_class]} #{item_class} #{disabled}".strip }
162
- end
106
+ if from < 1
107
+ to += 1 - from
108
+ from = 1
109
+ to = total_pages if to > total_pages
163
110
  end
164
111
 
165
- # Page link
166
- def page_link(page)
167
- item_link page, link_params(page), link_options(page)
168
- end
112
+ middle = from..to
169
113
 
170
- # Previous link
171
- def previous_link
172
- item_link @options[:previous_text], link_params(:previous), link_options(:previous)
114
+ if outer + 3 < middle.first
115
+ left = (1..(outer + 1)).to_a
116
+ left << :sep
117
+ else
118
+ left = 1...middle.first
173
119
  end
174
120
 
175
- # Next link
176
- def next_link
177
- item_link @options[:next_text], link_params(:next), link_options(:next)
121
+ if total_pages - outer - 2 > middle.last
122
+ right = ((total_pages - outer)..total_pages).to_a
123
+ right.unshift :sep
124
+ else
125
+ right = (middle.last + 1)..total_pages
178
126
  end
179
127
 
180
- # Render item link
181
- def item_link(text, params={}, html_options={})
182
- wrapper = @options[:item_wrapper]
183
- link_opt = html_options if wrapper.blank?
184
- item_tag = link_to text, params, link_opt
185
- item_tag = tag wrapper, item_tag, html_options if wrapper.present?
128
+ left.to_a + middle.to_a + right.to_a
129
+ end
186
130
 
187
- item_tag
188
- end
131
+ def link_params(page)
132
+ page = @collection.send(:"#{page}_page") unless page.is_a? Integer
133
+ { page: page }
134
+ end
189
135
 
190
- # Render item separator
191
- def item_sep
192
- item_link '&hellip;', {}, class: "#{@options[:item_class]} #{@options[:disabled_class]}".strip
193
- end
136
+ def link_options(page)
137
+ if page.is_a? Integer
138
+ active = @options[:active_class] if current_page? page
139
+ { class: "#{@options[:item_class]} #{active}".strip }
140
+ else
141
+ disabled = @options[:disabled_class] unless @collection.send(:"#{page}_page?")
142
+ item_class = @options[:"#{page}_class"]
194
143
 
195
- # Render content tag
196
- def tag(*args, &block)
197
- @context.content_tag(*args, &block)
144
+ { class: "#{@options[:item_class]} #{item_class} #{disabled}".strip }
198
145
  end
146
+ end
199
147
 
200
- # Render link tag
201
- def link_to(text, params={}, html_options={})
202
- prm = params.except(:page) if params[:page] == 1
203
- url = @context.url_for url_params.merge(prm || params)
204
- opt = html_options.to_h
205
- opt = opt.merge(href: url) if params[:page].present?
148
+ def page_link(page)
149
+ item_link page, link_params(page), link_options(page)
150
+ end
206
151
 
207
- tag :a, "#{text}".html_safe, opt
208
- end
152
+ def previous_link
153
+ item_link @options[:previous_text], link_params(:previous), link_options(:previous)
154
+ end
209
155
 
210
- # Render wrapper
211
- def wrapper(links)
212
- wrapper = @options[:wrapper]
213
- wrap_opt = { class: @options[:wrapper_class] }
214
- wrap_tag = links.html_safe
215
- wrap_tag = tag wrapper, wrap_tag, wrap_opt if wrapper.present?
156
+ def next_link
157
+ item_link @options[:next_text], link_params(:next), link_options(:next)
158
+ end
216
159
 
217
- wrap_tag
218
- end
160
+ def item_link(text, params = {}, html_options = {})
161
+ wrapper = @options[:item_wrapper]
162
+ link_opt = html_options if wrapper.blank?
163
+ item_tag = link_to text, params, link_opt
164
+ item_tag = tag wrapper, item_tag, html_options if wrapper.present?
219
165
 
220
- # Render pagination info
221
- def pagination_info
222
- current = tag :strong, current_entries, class: 'current'
223
- total = tag :strong, total_entries, class: 'total'
166
+ item_tag
167
+ end
224
168
 
225
- "Displaying #{current} of #{total} #{collection_name}".html_safe
226
- end
169
+ def item_sep
170
+ item_link '&hellip;', {}, class: "#{@options[:item_class]} #{@options[:disabled_class]}".strip
171
+ end
227
172
 
228
- # Render pager
229
- def pager
230
- items = [previous_link, next_link]
231
- wrapper items.map(&:to_s).join
232
- end
173
+ def tag(*args, &block)
174
+ @context.content_tag(*args, &block)
175
+ end
233
176
 
234
- # Render pagination
235
- def pagination
236
- items = page_numbers.map { |page| page == :sep ? item_sep : page_link(page) }
237
- items = [previous_link, *items, next_link]
177
+ def link_to(text, params = {}, html_options = {})
178
+ prm = params.except(:page) if params[:page] == 1
179
+ url = @context.url_for url_params.merge(prm || params)
180
+ opt = html_options.to_h
181
+ opt = opt.merge(href: url) if params[:page].present?
238
182
 
239
- wrapper items.map(&:to_s).join
240
- end
183
+ tag :a, "#{text}".html_safe, opt
184
+ end
185
+
186
+ def wrapper(links)
187
+ wrapper = @options[:wrapper]
188
+ wrap_opt = { class: @options[:wrapper_class] }
189
+ wrap_tag = links.html_safe
190
+ wrap_tag = tag wrapper, wrap_tag, wrap_opt if wrapper.present?
191
+
192
+ wrap_tag
193
+ end
194
+
195
+ def pagination_info
196
+ current = tag :strong, current_entries, class: 'current'
197
+ total = tag :strong, total_entries, class: 'total'
198
+
199
+ "Displaying #{current} of #{total} #{collection_name}".html_safe
200
+ end
201
+
202
+ def pager
203
+ items = [previous_link, next_link]
204
+ wrapper items.map(&:to_s).join
205
+ end
206
+
207
+ def pagination
208
+ items = page_numbers.map { |page| page == :sep ? item_sep : page_link(page) }
209
+ items = [previous_link, *items, next_link]
210
+
211
+ wrapper items.map(&:to_s).join
212
+ end
241
213
  end
242
214
  end
@@ -1,3 +1,3 @@
1
1
  module SmartPagination
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'
3
3
  end
@@ -6,7 +6,6 @@ module SmartPagination
6
6
  extend ActiveSupport::Autoload
7
7
  extend ActiveSupport::Concern
8
8
 
9
- # Autoload modules
10
9
  autoload :Renderer
11
10
  autoload :Helper
12
11
 
@@ -15,7 +14,6 @@ module SmartPagination
15
14
  end
16
15
  end
17
16
 
18
- # Include action view helpers
19
17
  if defined? ActionView::Base
20
18
  ActionView::Base.send :include, SmartPagination::Helper
21
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_pagination
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonian Guveli
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-13 00:00:00.000000000 Z
11
+ date: 2019-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smart_paginate
@@ -88,9 +88,7 @@ executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - CODE_OF_CONDUCT.md
92
91
  - Gemfile
93
- - Gemfile.lock
94
92
  - LICENSE.txt
95
93
  - README.md
96
94
  - Rakefile
@@ -118,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
116
  version: '0'
119
117
  requirements: []
120
118
  rubyforge_project:
121
- rubygems_version: 2.7.6
119
+ rubygems_version: 2.7.7
122
120
  signing_key:
123
121
  specification_version: 4
124
122
  summary: View helpers for SmartPaginate
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at info@hardpixel.eu. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile.lock DELETED
@@ -1,61 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- smart_pagination (0.1.0)
5
- actionview (>= 4.0.0, < 5.2)
6
- smart_paginate (~> 0.2)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- actionview (5.1.1)
12
- activesupport (= 5.1.1)
13
- builder (~> 3.1)
14
- erubi (~> 1.4)
15
- rails-dom-testing (~> 2.0)
16
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
17
- activemodel (5.1.1)
18
- activesupport (= 5.1.1)
19
- activerecord (5.1.1)
20
- activemodel (= 5.1.1)
21
- activesupport (= 5.1.1)
22
- arel (~> 8.0)
23
- activesupport (5.1.1)
24
- concurrent-ruby (~> 1.0, >= 1.0.2)
25
- i18n (~> 0.7)
26
- minitest (~> 5.1)
27
- tzinfo (~> 1.1)
28
- arel (8.0.0)
29
- builder (3.2.3)
30
- concurrent-ruby (1.0.5)
31
- erubi (1.6.0)
32
- i18n (0.8.4)
33
- loofah (2.0.3)
34
- nokogiri (>= 1.5.9)
35
- mini_portile2 (2.1.0)
36
- minitest (5.10.2)
37
- nokogiri (1.7.2)
38
- mini_portile2 (~> 2.1.0)
39
- rails-dom-testing (2.0.3)
40
- activesupport (>= 4.2.0)
41
- nokogiri (>= 1.6)
42
- rails-html-sanitizer (1.0.3)
43
- loofah (~> 2.0)
44
- rake (10.5.0)
45
- smart_paginate (0.2.0)
46
- activerecord (>= 4.0.0, < 5.2)
47
- thread_safe (0.3.6)
48
- tzinfo (1.2.3)
49
- thread_safe (~> 0.1)
50
-
51
- PLATFORMS
52
- ruby
53
-
54
- DEPENDENCIES
55
- bundler (~> 1.14)
56
- minitest (~> 5.0)
57
- rake (~> 10.0)
58
- smart_pagination!
59
-
60
- BUNDLED WITH
61
- 1.14.6