effective_bootstrap 0.5.5 → 0.5.6
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 +37 -0
- data/app/helpers/effective_bootstrap_helper.rb +51 -0
- data/lib/effective_bootstrap/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fed9040bd034c8360e211400e6c028d53fa70fe2
|
4
|
+
data.tar.gz: f3012062b2c332d41bed498ce439a9492bba2e7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ece6c140fdd1789e027d9a003190ae7cc48746bcf1b5f71c3dfcd562991109769f41889841109729914f3390dfc7b5c8a3cf8bdd26571618b7a2e94144c05000
|
7
|
+
data.tar.gz: c0fd95a31e68baef499142c267eb92909b1dfdbb94991f4af230e7fe9b98ff7d4fb709aeed17d55b9f451c1e95216a087ccfce8975a0d1aba653d0e6087dffce
|
data/README.md
CHANGED
@@ -116,6 +116,43 @@ https://getbootstrap.com/docs/4.0/components/navbar/
|
|
116
116
|
|
117
117
|
`nav_link_to` will automatically insert the `.active` class based on the request path.
|
118
118
|
|
119
|
+
### Pagination
|
120
|
+
|
121
|
+
https://getbootstrap.com/docs/4.0/components/pagination/
|
122
|
+
|
123
|
+
Builds a pagination based on the given collection, current url and params[:page].
|
124
|
+
|
125
|
+
The collection must be an ActiveRecord relation.
|
126
|
+
|
127
|
+
```haml
|
128
|
+
= paginate(@posts, per_page: 10)
|
129
|
+
```
|
130
|
+
|
131
|
+
Add this to your model:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
scope :paginate, -> (page: nil, per_page:) {
|
135
|
+
page = (page || 1).to_i
|
136
|
+
offset = [(page - 1), 0].max * per_page
|
137
|
+
|
138
|
+
limit(per_page).offset(offset)
|
139
|
+
}
|
140
|
+
```
|
141
|
+
|
142
|
+
Add this to your controller:
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
def index
|
146
|
+
@posts = Post.all.paginate(page: params[:page], per_page: 10)
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
Add this to your view:
|
151
|
+
|
152
|
+
```haml
|
153
|
+
%nav= paginate(@posts, per_page: 10)
|
154
|
+
```
|
155
|
+
|
119
156
|
### Tabs
|
120
157
|
|
121
158
|
https://getbootstrap.com/docs/4.0/components/navs/#tabs
|
@@ -172,6 +172,57 @@ module EffectiveBootstrapHelper
|
|
172
172
|
content_tag(:div, '', class: 'dropdown-divider')
|
173
173
|
end
|
174
174
|
|
175
|
+
# Pagination
|
176
|
+
#
|
177
|
+
# https://getbootstrap.com/docs/4.0/components/pagination/
|
178
|
+
# Builds a pagination based on the given collection, current url and params[:page]
|
179
|
+
#
|
180
|
+
# = paginate(@posts, per_page: 10)
|
181
|
+
#
|
182
|
+
# Add this to your model
|
183
|
+
# scope :paginate, -> (page: nil, per_page: 10) {
|
184
|
+
# page = (page || 1).to_i
|
185
|
+
# offset = [(page - 1), 0].max * per_page
|
186
|
+
|
187
|
+
# limit(per_page).offset(offset)
|
188
|
+
# }
|
189
|
+
#
|
190
|
+
# Add this to your controller:
|
191
|
+
# @posts = Post.all.paginate(page: params[:page])
|
192
|
+
#
|
193
|
+
# Add this to your view
|
194
|
+
# %nav= paginate(@posts, per_page: 10)
|
195
|
+
#
|
196
|
+
def paginate(collection, per_page:, url: nil)
|
197
|
+
raise 'expected an ActiveRecord::Relation' unless collection.respond_to?(:limit) && collection.respond_to?(:offset)
|
198
|
+
|
199
|
+
count = collection.limit(nil).offset(nil).count
|
200
|
+
|
201
|
+
page = (params[:page] || 1).to_i
|
202
|
+
pages = (count.to_f / per_page).ceil
|
203
|
+
|
204
|
+
uri = URI(url || request.fullpath)
|
205
|
+
params = Rack::Utils.parse_nested_query(uri.query)
|
206
|
+
url = uri.path + '?'
|
207
|
+
|
208
|
+
content_tag(:ul, class: 'pagination') do
|
209
|
+
content_tag(:li, class: ['page-item', ('disabled' if page <= 1)].compact.join(' ')) do
|
210
|
+
link_to(url + params.merge('page' => page - 1).to_query, class: 'page-link', 'aria-label': 'Previous', title: 'Previous') do
|
211
|
+
content_tag(:span, '«'.html_safe, 'aria-hidden': true) + content_tag(:span, 'Previous', class: 'sr-only')
|
212
|
+
end
|
213
|
+
end + (1..pages).map do |index|
|
214
|
+
content_tag(:li, class: ['page-item', ('active' if index == page)].compact.join(' '), title: "Page #{index}") do
|
215
|
+
link_to(index, (url + params.merge('page' => index).to_query), class: 'page-link')
|
216
|
+
end
|
217
|
+
end.join.html_safe +
|
218
|
+
content_tag(:li, class: ['page-item', ('disabled' if page >= pages)].compact.join(' ')) do
|
219
|
+
link_to(url + params.merge('page' => page + 1).to_query, class: 'page-link', 'aria-label': 'Next', title: 'Next') do
|
220
|
+
content_tag(:span, '»'.html_safe, 'aria-hidden': true) + content_tag(:span, 'Next', class: 'sr-only')
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
175
226
|
# Tabs DSL
|
176
227
|
# Inserts both the tablist and the tabpanel
|
177
228
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_bootstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|