kaminari-jets-core 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +1 -0
- data/MIT-LICENSE +21 -0
- data/README.md +31 -0
- data/app/views/kaminari/_first_page.html.erb +11 -0
- data/app/views/kaminari/_first_page.html.haml +9 -0
- data/app/views/kaminari/_first_page.html.slim +10 -0
- data/app/views/kaminari/_gap.html.erb +8 -0
- data/app/views/kaminari/_gap.html.haml +8 -0
- data/app/views/kaminari/_gap.html.slim +9 -0
- data/app/views/kaminari/_last_page.html.erb +11 -0
- data/app/views/kaminari/_last_page.html.haml +9 -0
- data/app/views/kaminari/_last_page.html.slim +10 -0
- data/app/views/kaminari/_next_page.html.erb +11 -0
- data/app/views/kaminari/_next_page.html.haml +9 -0
- data/app/views/kaminari/_next_page.html.slim +10 -0
- data/app/views/kaminari/_page.html.erb +12 -0
- data/app/views/kaminari/_page.html.haml +10 -0
- data/app/views/kaminari/_page.html.slim +11 -0
- data/app/views/kaminari/_paginator.html.erb +25 -0
- data/app/views/kaminari/_paginator.html.haml +18 -0
- data/app/views/kaminari/_paginator.html.slim +19 -0
- data/app/views/kaminari/_prev_page.html.erb +11 -0
- data/app/views/kaminari/_prev_page.html.haml +9 -0
- data/app/views/kaminari/_prev_page.html.slim +10 -0
- data/config/locales/kaminari.yml +23 -0
- data/kaminari-core.gemspec +26 -0
- data/lib/generators/kaminari/config_generator.rb +19 -0
- data/lib/generators/kaminari/templates/kaminari_config.rb +14 -0
- data/lib/generators/kaminari/views_generator.rb +137 -0
- data/lib/kaminari/config.rb +40 -0
- data/lib/kaminari/core/version.rb +8 -0
- data/lib/kaminari/core.rb +29 -0
- data/lib/kaminari/engine.rb +6 -0
- data/lib/kaminari/exceptions.rb +5 -0
- data/lib/kaminari/helpers/helper_methods.rb +247 -0
- data/lib/kaminari/helpers/paginator.rb +191 -0
- data/lib/kaminari/helpers/tags.rb +164 -0
- data/lib/kaminari/jets/engine.rb +6 -0
- data/lib/kaminari/jets/turbine.rb +9 -0
- data/lib/kaminari/models/array_extension.rb +73 -0
- data/lib/kaminari/models/configuration_methods.rb +60 -0
- data/lib/kaminari/models/page_scope_methods.rb +91 -0
- data/lib/kaminari/railtie.rb +9 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d6fa53c672bfdad72daf39edf38180804d16ec0b8cc1b82ebf05fff5473c9830
|
4
|
+
data.tar.gz: 06df30f45dc8c13e286355c3c053bb900d04ae644e3320ed20d44e242aa8302e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 872a806dd93447bc59c4e02196bbbd4d71f281d814bcc142bf3f3f925698c03465fac090ec03403eefb14ba4af94b9a475879cb82a3b190e4383bdaa6ba92e11
|
7
|
+
data.tar.gz: 7ef12987d2357d8f9a52e48ea0838c44084da457db3a2c381176d31fa166794e4437dc069bf573d68aca9638fe4e4f01ac2531792435f727dc794dd6dc7ebe66
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
See https://github.com/kaminari/kaminari/tree/master/CHANGELOG.md for changes.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Akira Matsuda
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Kaminari::Core
|
2
|
+
|
3
|
+
Kaminari core libraries.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'kaminari-core'
|
12
|
+
```
|
13
|
+
|
14
|
+
And bundle.
|
15
|
+
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
This gem is basically an internal gem that will be automatically bundled from kaminari gem or kaminari adapter gems.
|
20
|
+
|
21
|
+
See [Kaminari README](https://github.com/kaminari/kaminari/blob/master/README.md) for the documentation.
|
22
|
+
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
Pull requests are welcome on GitHub at https://github.com/kaminari/kaminari.
|
27
|
+
|
28
|
+
|
29
|
+
## License
|
30
|
+
|
31
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%# Link to the "First" page
|
2
|
+
- available local variables
|
3
|
+
url: url to the first page
|
4
|
+
current_page: a page object for the currently displayed page
|
5
|
+
total_pages: total number of pages
|
6
|
+
per_page: number of items to fetch per page
|
7
|
+
remote: data-remote
|
8
|
+
-%>
|
9
|
+
<span class="first">
|
10
|
+
<%= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, remote: remote %>
|
11
|
+
</span>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
-# Link to the "First" page
|
2
|
+
-# available local variables
|
3
|
+
-# url: url to the first page
|
4
|
+
-# current_page: a page object for the currently displayed page
|
5
|
+
-# total_pages: total number of pages
|
6
|
+
-# per_page: number of items to fetch per page
|
7
|
+
-# remote: data-remote
|
8
|
+
%span.first
|
9
|
+
= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, remote: remote
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/ Link to the "First" page
|
2
|
+
- available local variables
|
3
|
+
url : url to the first page
|
4
|
+
current_page : a page object for the currently displayed page
|
5
|
+
total_pages : total number of pages
|
6
|
+
per_page : number of items to fetch per page
|
7
|
+
remote : data-remote
|
8
|
+
span.first
|
9
|
+
== link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, remote: remote
|
10
|
+
'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%# Non-link tag that stands for skipped pages...
|
2
|
+
- available local variables
|
3
|
+
current_page: a page object for the currently displayed page
|
4
|
+
total_pages: total number of pages
|
5
|
+
per_page: number of items to fetch per page
|
6
|
+
remote: data-remote
|
7
|
+
-%>
|
8
|
+
<span class="page gap"><%= t('views.pagination.truncate').html_safe %></span>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
-# Non-link tag that stands for skipped pages...
|
2
|
+
-# available local variables
|
3
|
+
-# current_page: a page object for the currently displayed page
|
4
|
+
-# total_pages: total number of pages
|
5
|
+
-# per_page: number of items to fetch per page
|
6
|
+
-# remote: data-remote
|
7
|
+
%span.page.gap
|
8
|
+
= t('views.pagination.truncate').html_safe
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/ Non-link tag that stands for skipped pages...
|
2
|
+
- available local variables
|
3
|
+
current_page : a page object for the currently displayed page
|
4
|
+
total_pages : total number of pages
|
5
|
+
per_page : number of items to fetch per page
|
6
|
+
remote : data-remote
|
7
|
+
span.page.gap
|
8
|
+
== t('views.pagination.truncate').html_safe
|
9
|
+
'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%# Link to the "Last" page
|
2
|
+
- available local variables
|
3
|
+
url: url to the last page
|
4
|
+
current_page: a page object for the currently displayed page
|
5
|
+
total_pages: total number of pages
|
6
|
+
per_page: number of items to fetch per page
|
7
|
+
remote: data-remote
|
8
|
+
-%>
|
9
|
+
<span class="last">
|
10
|
+
<%= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, remote: remote %>
|
11
|
+
</span>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
-# Link to the "Last" page
|
2
|
+
-# available local variables
|
3
|
+
-# url: url to the last page
|
4
|
+
-# current_page: a page object for the currently displayed page
|
5
|
+
-# total_pages: total number of pages
|
6
|
+
-# per_page: number of items to fetch per page
|
7
|
+
-# remote: data-remote
|
8
|
+
%span.last
|
9
|
+
= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, remote: remote
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/ Link to the "Last" page
|
2
|
+
- available local variables
|
3
|
+
url : url to the last page
|
4
|
+
current_page : a page object for the currently displayed page
|
5
|
+
total_pages : total number of pages
|
6
|
+
per_page : number of items to fetch per page
|
7
|
+
remote : data-remote
|
8
|
+
span.last
|
9
|
+
== link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, remote: remote
|
10
|
+
'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%# Link to the "Next" page
|
2
|
+
- available local variables
|
3
|
+
url: url to the next page
|
4
|
+
current_page: a page object for the currently displayed page
|
5
|
+
total_pages: total number of pages
|
6
|
+
per_page: number of items to fetch per page
|
7
|
+
remote: data-remote
|
8
|
+
-%>
|
9
|
+
<span class="next">
|
10
|
+
<%= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, rel: 'next', remote: remote %>
|
11
|
+
</span>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
-# Link to the "Next" page
|
2
|
+
-# available local variables
|
3
|
+
-# url: url to the next page
|
4
|
+
-# current_page: a page object for the currently displayed page
|
5
|
+
-# total_pages: total number of pages
|
6
|
+
-# per_page: number of items to fetch per page
|
7
|
+
-# remote: data-remote
|
8
|
+
%span.next
|
9
|
+
= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, rel: 'next', remote: remote
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/ Link to the "Next" page
|
2
|
+
- available local variables
|
3
|
+
url : url to the next page
|
4
|
+
current_page : a page object for the currently displayed page
|
5
|
+
total_pages : total number of pages
|
6
|
+
per_page : number of items to fetch per page
|
7
|
+
remote : data-remote
|
8
|
+
span.next
|
9
|
+
== link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, rel: 'next', remote: remote
|
10
|
+
'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%# Link showing page number
|
2
|
+
- available local variables
|
3
|
+
page: a page object for "this" page
|
4
|
+
url: url to this page
|
5
|
+
current_page: a page object for the currently displayed page
|
6
|
+
total_pages: total number of pages
|
7
|
+
per_page: number of items to fetch per page
|
8
|
+
remote: data-remote
|
9
|
+
-%>
|
10
|
+
<span class="page<%= ' current' if page.current? %>">
|
11
|
+
<%= link_to_unless page.current?, page, url, {remote: remote, rel: page.rel} %>
|
12
|
+
</span>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
-# Link showing page number
|
2
|
+
-# available local variables
|
3
|
+
-# page: a page object for "this" page
|
4
|
+
-# url: url to this page
|
5
|
+
-# current_page: a page object for the currently displayed page
|
6
|
+
-# total_pages: total number of pages
|
7
|
+
-# per_page: number of items to fetch per page
|
8
|
+
-# remote: data-remote
|
9
|
+
%span{class: "page#{' current' if page.current?}"}
|
10
|
+
= link_to_unless page.current?, page, url, {remote: remote, rel: page.rel}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/ Link showing page number
|
2
|
+
- available local variables
|
3
|
+
page : a page object for "this" page
|
4
|
+
url : url to this page
|
5
|
+
current_page : a page object for the currently displayed page
|
6
|
+
total_pages : total number of pages
|
7
|
+
per_page : number of items to fetch per page
|
8
|
+
remote : data-remote
|
9
|
+
span class="page#{' current' if page.current?}"
|
10
|
+
== link_to_unless page.current?, page, url, {remote: remote, rel: page.rel}
|
11
|
+
'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<%# The container tag
|
2
|
+
- available local variables
|
3
|
+
current_page: a page object for the currently displayed page
|
4
|
+
total_pages: total number of pages
|
5
|
+
per_page: number of items to fetch per page
|
6
|
+
remote: data-remote
|
7
|
+
paginator: the paginator that renders the pagination tags inside
|
8
|
+
-%>
|
9
|
+
<%= paginator.render do -%>
|
10
|
+
<nav class="pagination" role="navigation" aria-label="pager">
|
11
|
+
<%= first_page_tag unless current_page.first? %>
|
12
|
+
<%= prev_page_tag unless current_page.first? %>
|
13
|
+
<% each_page do |page| -%>
|
14
|
+
<% if page.display_tag? -%>
|
15
|
+
<%= page_tag page %>
|
16
|
+
<% elsif !page.was_truncated? -%>
|
17
|
+
<%= gap_tag %>
|
18
|
+
<% end -%>
|
19
|
+
<% end -%>
|
20
|
+
<% unless current_page.out_of_range? %>
|
21
|
+
<%= next_page_tag unless current_page.last? %>
|
22
|
+
<%= last_page_tag unless current_page.last? %>
|
23
|
+
<% end %>
|
24
|
+
</nav>
|
25
|
+
<% end -%>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
-# The container tag
|
2
|
+
-# available local variables
|
3
|
+
-# current_page: a page object for the currently displayed page
|
4
|
+
-# total_pages: total number of pages
|
5
|
+
-# per_page: number of items to fetch per page
|
6
|
+
-# remote: data-remote
|
7
|
+
-# paginator: the paginator that renders the pagination tags inside
|
8
|
+
= paginator.render do
|
9
|
+
%nav.pagination
|
10
|
+
= first_page_tag unless current_page.first?
|
11
|
+
= prev_page_tag unless current_page.first?
|
12
|
+
- each_page do |page|
|
13
|
+
- if page.display_tag?
|
14
|
+
= page_tag page
|
15
|
+
- elsif !page.was_truncated?
|
16
|
+
= gap_tag
|
17
|
+
= next_page_tag unless current_page.last?
|
18
|
+
= last_page_tag unless current_page.last?
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/ The container tag
|
2
|
+
- available local variables
|
3
|
+
current_page : a page object for the currently displayed page
|
4
|
+
total_pages : total number of pages
|
5
|
+
per_page : number of items to fetch per page
|
6
|
+
remote : data-remote
|
7
|
+
paginator : the paginator that renders the pagination tags inside
|
8
|
+
|
9
|
+
== paginator.render do
|
10
|
+
nav.pagination
|
11
|
+
== first_page_tag unless current_page.first?
|
12
|
+
== prev_page_tag unless current_page.first?
|
13
|
+
- each_page do |page|
|
14
|
+
- if page.display_tag?
|
15
|
+
== page_tag page
|
16
|
+
- elsif !page.was_truncated?
|
17
|
+
== gap_tag
|
18
|
+
== next_page_tag unless current_page.last?
|
19
|
+
== last_page_tag unless current_page.last?
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%# Link to the "Previous" page
|
2
|
+
- available local variables
|
3
|
+
url: url to the previous page
|
4
|
+
current_page: a page object for the currently displayed page
|
5
|
+
total_pages: total number of pages
|
6
|
+
per_page: number of items to fetch per page
|
7
|
+
remote: data-remote
|
8
|
+
-%>
|
9
|
+
<span class="prev">
|
10
|
+
<%= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote %>
|
11
|
+
</span>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
-# Link to the "Previous" page
|
2
|
+
-# available local variables
|
3
|
+
-# url: url to the previous page
|
4
|
+
-# current_page: a page object for the currently displayed page
|
5
|
+
-# total_pages: total number of pages
|
6
|
+
-# per_page: number of items to fetch per page
|
7
|
+
-# remote: data-remote
|
8
|
+
%span.prev
|
9
|
+
= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/ Link to the "Previous" page
|
2
|
+
- available local variables
|
3
|
+
url : url to the previous page
|
4
|
+
current_page : a page object for the currently displayed page
|
5
|
+
total_pages : total number of pages
|
6
|
+
per_page : number of items to fetch per page
|
7
|
+
remote : data-remote
|
8
|
+
span.prev
|
9
|
+
== link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote
|
10
|
+
'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Sample localization file for Kaminari. You can override these values in your app's locales file if you want.
|
2
|
+
|
3
|
+
en:
|
4
|
+
views:
|
5
|
+
pagination:
|
6
|
+
first: "« First"
|
7
|
+
last: "Last »"
|
8
|
+
previous: "‹ Prev"
|
9
|
+
next: "Next ›"
|
10
|
+
truncate: "…"
|
11
|
+
helpers:
|
12
|
+
page_entries_info:
|
13
|
+
entry:
|
14
|
+
zero: "entries"
|
15
|
+
one: "entry"
|
16
|
+
other: "entries"
|
17
|
+
one_page:
|
18
|
+
display_entries:
|
19
|
+
zero: "No %{entry_name} found"
|
20
|
+
one: "Displaying <b>1</b> %{entry_name}"
|
21
|
+
other: "Displaying <b>all %{count}</b> %{entry_name}"
|
22
|
+
more_pages:
|
23
|
+
display_entries: "Displaying %{entry_name} <b>%{first} - %{last}</b> of <b>%{total}</b> in total"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'kaminari/core/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "kaminari-jets-core"
|
9
|
+
spec.version = Kaminari::Core::FORK_VERSION
|
10
|
+
spec.authors = ['Tung Nguyen']
|
11
|
+
spec.email = ['tongueroo@gmail.com']
|
12
|
+
# Keep original authors as comment. Give them credit but they're not maintaining this fork.
|
13
|
+
# spec.authors = ["Akira Matsuda"]
|
14
|
+
# spec.email = ["ronnie@dio.jp"]
|
15
|
+
spec.summary = "Kaminari's core pagination library"
|
16
|
+
spec.description = 'kaminari-core includes pagination logic independent from ORMs and view libraries'
|
17
|
+
spec.homepage = 'https://github.com/kaminari/kaminari'
|
18
|
+
spec.license = "MIT"
|
19
|
+
spec.required_ruby_version = '>= 2.0.0'
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", ">= 1.13"
|
25
|
+
spec.add_development_dependency "rake", ">= 10.0"
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kaminari
|
4
|
+
module Generators
|
5
|
+
# rails g kaminari:config
|
6
|
+
class ConfigGenerator < Rails::Generators::Base # :nodoc:
|
7
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
8
|
+
|
9
|
+
desc <<DESC
|
10
|
+
Description:
|
11
|
+
Copies Kaminari configuration file to your application's initializer directory.
|
12
|
+
DESC
|
13
|
+
|
14
|
+
def copy_config_file
|
15
|
+
template 'kaminari_config.rb', 'config/initializers/kaminari_config.rb'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Kaminari.configure do |config|
|
4
|
+
# config.default_per_page = 25
|
5
|
+
# config.max_per_page = nil
|
6
|
+
# config.window = 4
|
7
|
+
# config.outer_window = 0
|
8
|
+
# config.left = 0
|
9
|
+
# config.right = 0
|
10
|
+
# config.page_method_name = :page
|
11
|
+
# config.param_name = :page
|
12
|
+
# config.max_pages = nil
|
13
|
+
# config.params_on_first_page = false
|
14
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kaminari
|
4
|
+
module Generators
|
5
|
+
# rails g kaminari:views THEME
|
6
|
+
class ViewsGenerator < Rails::Generators::NamedBase # :nodoc:
|
7
|
+
source_root File.expand_path('../../../../app/views/kaminari', __FILE__)
|
8
|
+
|
9
|
+
class_option :template_engine, type: :string, aliases: '-e', desc: 'Template engine for the views. Available options are "erb", "haml", and "slim".'
|
10
|
+
class_option :views_prefix, type: :string, desc: 'Prefix for path to put views in.'
|
11
|
+
|
12
|
+
def self.banner #:nodoc:
|
13
|
+
<<-BANNER.chomp
|
14
|
+
rails g kaminari:views THEME [options]
|
15
|
+
|
16
|
+
Copies all paginator partial templates to your application.
|
17
|
+
You can choose a template THEME by specifying one from the list below:
|
18
|
+
|
19
|
+
- default
|
20
|
+
The default one.
|
21
|
+
This one is used internally while you don't override the partials.
|
22
|
+
#{themes.map {|t| " - #{t.name}\n#{t.description}"}.join("\n")}
|
23
|
+
BANNER
|
24
|
+
end
|
25
|
+
|
26
|
+
desc ''
|
27
|
+
def copy_or_fetch #:nodoc:
|
28
|
+
return copy_default_views if file_name == 'default'
|
29
|
+
|
30
|
+
if (theme = self.class.themes.detect {|t| t.name == file_name})
|
31
|
+
if download_templates(theme).empty?
|
32
|
+
say "template_engine: #{template_engine} is not available for theme: #{file_name}"
|
33
|
+
end
|
34
|
+
else
|
35
|
+
say "no such theme: #{file_name}\n available themes: #{self.class.themes.map(&:name).join ', '}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def self.themes
|
41
|
+
@themes ||= GitHubApiHelper.get_files_in_master.group_by {|fn, _| fn[0...(fn.index('/') || 0)]}.delete_if {|fn, _| fn.blank?}.map do |name, files|
|
42
|
+
Theme.new name, files
|
43
|
+
end
|
44
|
+
rescue SocketError
|
45
|
+
[]
|
46
|
+
end
|
47
|
+
|
48
|
+
def download_templates(theme)
|
49
|
+
theme.templates_for(template_engine).each do |template|
|
50
|
+
say " downloading #{template.name} from kaminari_themes..."
|
51
|
+
create_file view_path_for(template.name), GitHubApiHelper.get_content_for("#{theme.name}/#{template.name}")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def copy_default_views
|
56
|
+
filename_pattern = File.join self.class.source_root, "*.html.#{template_engine}"
|
57
|
+
Dir.glob(filename_pattern).map {|f| File.basename f}.each do |f|
|
58
|
+
copy_file f, view_path_for(f)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def view_path_for(file)
|
63
|
+
['app', 'views', views_prefix, 'kaminari', File.basename(file)].compact.join('/')
|
64
|
+
end
|
65
|
+
|
66
|
+
def views_prefix
|
67
|
+
options[:views_prefix].try(:to_s)
|
68
|
+
end
|
69
|
+
|
70
|
+
def template_engine
|
71
|
+
engine = options[:template_engine].try(:to_s).try(:downcase)
|
72
|
+
|
73
|
+
if engine == 'haml' || engine == 'slim'
|
74
|
+
ActiveSupport::Deprecation.warn 'The -e option is deprecated and will be removed in the near future. Please use the html2slim gem or the html2haml gem ' \
|
75
|
+
'to convert erb templates manually.'
|
76
|
+
end
|
77
|
+
|
78
|
+
engine || 'erb'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
Template = Struct.new(:name, :sha) do
|
83
|
+
def description?
|
84
|
+
name == 'DESCRIPTION'
|
85
|
+
end
|
86
|
+
|
87
|
+
def view?
|
88
|
+
name =~ /^app\/views\//
|
89
|
+
end
|
90
|
+
|
91
|
+
def engine #:nodoc:
|
92
|
+
File.extname(name).sub(/^\./, '')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class Theme
|
97
|
+
attr_accessor :name
|
98
|
+
def initialize(name, templates) #:nodoc:
|
99
|
+
@name, @templates = name, templates.map {|fn, sha| Template.new fn.sub(/^#{name}\//, ''), sha}
|
100
|
+
end
|
101
|
+
|
102
|
+
def description #:nodoc:
|
103
|
+
file = @templates.detect(&:description?)
|
104
|
+
return "#{' ' * 12}#{name}" unless file
|
105
|
+
GitHubApiHelper.get_content_for("#{@name}/#{file.name}").chomp.gsub(/^/, ' ' * 12)
|
106
|
+
end
|
107
|
+
|
108
|
+
def templates_for(template_engine) #:nodoc:
|
109
|
+
@templates.select {|t| t.engine == template_engine }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
module GitHubApiHelper
|
114
|
+
require 'open-uri'
|
115
|
+
|
116
|
+
def get_files_in_master
|
117
|
+
master_tree_sha = URI.open('https://api.github.com/repos/amatsuda/kaminari_themes/git/refs/heads/master') do |json|
|
118
|
+
ActiveSupport::JSON.decode(json.read)['object']['sha']
|
119
|
+
end
|
120
|
+
URI.open('https://api.github.com/repos/amatsuda/kaminari_themes/git/trees/' + master_tree_sha + '?recursive=1') do |json|
|
121
|
+
blobs = ActiveSupport::JSON.decode(json.read)['tree'].find_all {|i| i['type'] == 'blob' }
|
122
|
+
blobs.map do |blob|
|
123
|
+
[blob['path'], blob['sha']]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
module_function :get_files_in_master
|
128
|
+
|
129
|
+
def get_content_for(path)
|
130
|
+
URI.open('https://api.github.com/repos/amatsuda/kaminari_themes/contents/' + path) do |json|
|
131
|
+
Base64.decode64(ActiveSupport::JSON.decode(json.read)['content'])
|
132
|
+
end
|
133
|
+
end
|
134
|
+
module_function :get_content_for
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kaminari
|
4
|
+
# Configures global settings for Kaminari
|
5
|
+
# Kaminari.configure do |config|
|
6
|
+
# config.default_per_page = 10
|
7
|
+
# end
|
8
|
+
class << self
|
9
|
+
def configure
|
10
|
+
yield config
|
11
|
+
end
|
12
|
+
|
13
|
+
def config
|
14
|
+
@_config ||= Config.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Config
|
19
|
+
attr_accessor :default_per_page, :max_per_page, :window, :outer_window, :left, :right, :page_method_name, :max_pages, :params_on_first_page
|
20
|
+
attr_writer :param_name
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@default_per_page = 25
|
24
|
+
@max_per_page = nil
|
25
|
+
@window = 4
|
26
|
+
@outer_window = 0
|
27
|
+
@left = 0
|
28
|
+
@right = 0
|
29
|
+
@page_method_name = :page
|
30
|
+
@param_name = :page
|
31
|
+
@max_pages = nil
|
32
|
+
@params_on_first_page = false
|
33
|
+
end
|
34
|
+
|
35
|
+
# If param_name was given as a callable object, call it when returning
|
36
|
+
def param_name
|
37
|
+
@param_name.respond_to?(:call) ? @param_name.call : @param_name
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kaminari
|
4
|
+
end
|
5
|
+
|
6
|
+
# load Rails/Railtie
|
7
|
+
begin
|
8
|
+
require 'rails'
|
9
|
+
rescue LoadError
|
10
|
+
#do nothing
|
11
|
+
end unless defined?(Jets)
|
12
|
+
|
13
|
+
# load Kaminari components
|
14
|
+
require 'kaminari/config'
|
15
|
+
require 'kaminari/exceptions'
|
16
|
+
require 'kaminari/helpers/paginator'
|
17
|
+
require 'kaminari/models/page_scope_methods'
|
18
|
+
require 'kaminari/models/configuration_methods'
|
19
|
+
require 'kaminari/models/array_extension'
|
20
|
+
|
21
|
+
if defined? ::Rails::Railtie
|
22
|
+
require 'kaminari/railtie'
|
23
|
+
require 'kaminari/engine'
|
24
|
+
end
|
25
|
+
|
26
|
+
if defined? ::Jets::Turbine
|
27
|
+
require 'kaminari/jets/turbine'
|
28
|
+
require 'kaminari/jets/engine'
|
29
|
+
end
|