diff --git a/Gemfile b/Gemfile index f673ac6..5788b57 100644 --- a/Gemfile +++ b/Gemfile @@ -107,6 +107,10 @@ gem 'sidekiq', '~> 5.2' # Helpers for the reCAPTCHA API. gem 'recaptcha', '~> 4.13' +# Kaminari is a Scope & Engine based, clean, powerful, agnostic, customizable +# and sophisticated paginator for Rails 4+. +gem 'kaminari', '~> 1.1' + group :development, :test do # factory_bot provides a framework and DSL for defining and using factories. gem 'factory_bot_rails', '~> 4.10' diff --git a/Gemfile.lock b/Gemfile.lock index c83ddbe..d8be4cd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -184,6 +184,18 @@ GEM thor (>= 0.14, < 2.0) json (2.2.0) jwt (2.2.1) + kaminari (1.1.1) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.1.1) + kaminari-activerecord (= 1.1.1) + kaminari-core (= 1.1.1) + kaminari-actionview (1.1.1) + actionview + kaminari-core (= 1.1.1) + kaminari-activerecord (1.1.1) + activerecord + kaminari-core (= 1.1.1) + kaminari-core (1.1.1) launchy (2.4.3) addressable (~> 2.3) letter_opener (1.7.0) @@ -450,6 +462,7 @@ DEPENDENCIES font-awesome-sass (~> 5.5.0) interactor (~> 3.1) jquery-rails (~> 4.3) + kaminari (~> 1.1) letter_opener (~> 1.6) listen (>= 3.0.5, < 3.2) omniauth (~> 1.9) @@ -489,4 +502,4 @@ RUBY VERSION ruby 2.6.2p47 BUNDLED WITH - 2.0.1 + 2.0.2 diff --git a/app/views/kaminari/_first_page.html.erb b/app/views/kaminari/_first_page.html.erb new file mode 100644 index 0000000..5261a52 --- /dev/null +++ b/app/views/kaminari/_first_page.html.erb @@ -0,0 +1,7 @@ +
  • + <%= link_to_unless current_page.first?, + raw(translate('pagination.first')), + url, + remote: remote, + class: 'page-link' %> +
  • diff --git a/app/views/kaminari/_gap.html.erb b/app/views/kaminari/_gap.html.erb new file mode 100644 index 0000000..b350c97 --- /dev/null +++ b/app/views/kaminari/_gap.html.erb @@ -0,0 +1,5 @@ +
  • + <%= link_to raw(translate('pagination.truncate')), + '#', + class: 'page-link' %> +
  • diff --git a/app/views/kaminari/_last_page.html.erb b/app/views/kaminari/_last_page.html.erb new file mode 100644 index 0000000..70fc6ac --- /dev/null +++ b/app/views/kaminari/_last_page.html.erb @@ -0,0 +1,7 @@ +
  • + <%= link_to_unless current_page.last?, + raw(translate('pagination.last')), + url, + remote: remote, + class: 'page-link' %> +
  • diff --git a/app/views/kaminari/_next_page.html.erb b/app/views/kaminari/_next_page.html.erb new file mode 100644 index 0000000..de2a684 --- /dev/null +++ b/app/views/kaminari/_next_page.html.erb @@ -0,0 +1,8 @@ +
  • + <%= link_to_unless current_page.last?, + raw(translate('pagination.next')), + url, + rel: 'next', + remote: remote, + class: 'page-link' %> +
  • diff --git a/app/views/kaminari/_page.html.erb b/app/views/kaminari/_page.html.erb new file mode 100644 index 0000000..c49b8cf --- /dev/null +++ b/app/views/kaminari/_page.html.erb @@ -0,0 +1,17 @@ +<% if page.current? %> +
  • + <%= content_tag :a, + page, + data: { remote: remote }, + rel: page.rel, + class: 'page-link' %> +
  • +<% else %> +
  • + <%= link_to page, + url, + remote: remote, + rel: page.rel, + class: 'page-link' %> +
  • +<% end %> diff --git a/app/views/kaminari/_paginator.html.erb b/app/views/kaminari/_paginator.html.erb new file mode 100644 index 0000000..0fc6c36 --- /dev/null +++ b/app/views/kaminari/_paginator.html.erb @@ -0,0 +1,19 @@ +<%= paginator.render do %> + +<% end %> diff --git a/app/views/kaminari/_prev_page.html.erb b/app/views/kaminari/_prev_page.html.erb new file mode 100644 index 0000000..9fb2095 --- /dev/null +++ b/app/views/kaminari/_prev_page.html.erb @@ -0,0 +1,8 @@ +
  • + <%= link_to_unless current_page.first?, + raw(translate('pagination.previous')), + url, + rel: 'prev', + remote: remote, + class: 'page-link' %> +
  • diff --git a/config/initializers/kaminari_config.rb b/config/initializers/kaminari_config.rb new file mode 100644 index 0000000..2dd4e31 --- /dev/null +++ b/config/initializers/kaminari_config.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +Kaminari.configure do |config| + config.default_per_page = 10 + # config.max_per_page = nil + # config.window = 4 + # config.outer_window = 0 + # config.left = 0 + # config.right = 0 + # config.page_method_name = :page + # config.param_name = :page + # config.params_on_first_page = false +end diff --git a/config/locales/pagination/en.yml b/config/locales/pagination/en.yml new file mode 100644 index 0000000..f3cc467 --- /dev/null +++ b/config/locales/pagination/en.yml @@ -0,0 +1,7 @@ +en: + pagination: + first: '« First' + last: 'Last »' + previous: '‹ Prev' + next: 'Next ›' + truncate: '…' diff --git a/config/locales/pagination/ru.yml b/config/locales/pagination/ru.yml new file mode 100644 index 0000000..261aa83 --- /dev/null +++ b/config/locales/pagination/ru.yml @@ -0,0 +1,7 @@ +ru: + pagination: + first: '« Первая' + last: 'Последняя »' + previous: '‹ Пред.' + next: 'След. ›' + truncate: '…'