From d58a39d35fa51bc81db4b382632b8b63f8f719a5 Mon Sep 17 00:00:00 2001 From: radin reth Date: Thu, 23 Apr 2020 08:43:21 +0700 Subject: [PATCH 1/4] Khmer translation for pagy (#235) --- lib/locales/km.yml | 19 +++++++++++++++++++ lib/locales/utils/p11n.rb | 1 + 2 files changed, 20 insertions(+) create mode 100644 lib/locales/km.yml diff --git a/lib/locales/km.yml b/lib/locales/km.yml new file mode 100644 index 000000000..259f52ef0 --- /dev/null +++ b/lib/locales/km.yml @@ -0,0 +1,19 @@ +# :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb) + +km: + pagy: + item_name: "ធាតុ" + + nav: + prev: "‹ មុន" + next: "បន្ទាប់ ›" + gap: "…" + + info: + no_items: "មិនមាន %{item_name} ទេ" + single_page: "បង្ហាញ %{count} %{item_name}" + multiple_pages: "បង្ហាញ %{item_name} %{from}-%{to} នៃ %{count} ជាចំនួនសរុប" + + combo_nav_js: "ទំព័រ %{page_input} នៃ %{pages}" + + items_selector_js: "បង្ហាញ %{items_input} %{item_name} ក្នុង ១ ទំព័រ" diff --git a/lib/locales/utils/p11n.rb b/lib/locales/utils/p11n.rb index ad5d8c150..4767c8f73 100644 --- a/lib/locales/utils/p11n.rb +++ b/lib/locales/utils/p11n.rb @@ -72,6 +72,7 @@ hash['zh-CN'] = p11n[:other] hash['zh-HK'] = p11n[:other] hash['zh-TW'] = p11n[:other] + hash['km'] = p11n[:other] end [ plurals, p11n ] From a9cee7d0b006e428c13442382bf5da7538c5fbd8 Mon Sep 17 00:00:00 2001 From: Luka Huang Date: Thu, 23 Apr 2020 10:09:38 +0800 Subject: [PATCH 2/4] Support ES5 on elasticsearch rails (#234) --- docs/extras/elasticsearch_rails.md | 2 +- lib/pagy/extras/elasticsearch_rails.rb | 6 ++++- test/mock_helpers/elasticsearch_rails.rb | 27 ++++++++++++++++++++ test/pagy/extras/elasticsearch_rails_test.rb | 18 +++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/docs/extras/elasticsearch_rails.md b/docs/extras/elasticsearch_rails.md index f801b0422..bd44811fb 100644 --- a/docs/extras/elasticsearch_rails.md +++ b/docs/extras/elasticsearch_rails.md @@ -20,7 +20,7 @@ require 'pagy/extras/elasticsearch_rails' If you have an already paginated `Elasticsearch::Model::Response::Response` object, you can get the `Pagy` object out of it: ```ruby -@response = Model.search('*', from: 0; size: 10, ...) +@response = Model.search('*', from: 0, size: 10, ...) @pagy = Pagy.new_from_elasticsearch_rails(@response, ...) ``` diff --git a/lib/pagy/extras/elasticsearch_rails.rb b/lib/pagy/extras/elasticsearch_rails.rb index 7a40a5dba..68b078ce9 100644 --- a/lib/pagy/extras/elasticsearch_rails.rb +++ b/lib/pagy/extras/elasticsearch_rails.rb @@ -13,7 +13,11 @@ class Pagy def self.new_from_elasticsearch_rails(response, vars={}) vars[:items] = response.search.options[:size] || 10 vars[:page] = (response.search.options[:from] || 0) / vars[:items] + 1 - total = response.raw_response['hits']['total'] + total = if response.respond_to?(:raw_response) + response.raw_response['hits']['total'] + else + response.response['hits']['total'] + end vars[:count] = total.is_a?(Hash) ? total['value'] : total new(vars) end diff --git a/test/mock_helpers/elasticsearch_rails.rb b/test/mock_helpers/elasticsearch_rails.rb index a84fe341e..b8ad6a205 100644 --- a/test/mock_helpers/elasticsearch_rails.rb +++ b/test/mock_helpers/elasticsearch_rails.rb @@ -60,4 +60,31 @@ def self.search(*args) end end + + class ResponseES5 + + attr_reader :search, :response + + def initialize(query, options={}) + @search = Search.new(query, options) + @response = {'hits' => {'hits' => @search.results, 'total' => RESULTS[query].size}} + end + + def records + @response['hits']['hits'].map{|r| "R-#{r}"} + end + + def count + @response['hits']['hits'].size + end + + end + + class ModelES5 < Model + + def self.search(*args) + ResponseES5.new(*args) + end + + end end diff --git a/test/pagy/extras/elasticsearch_rails_test.rb b/test/pagy/extras/elasticsearch_rails_test.rb index a6a5bb40e..27b781a7a 100644 --- a/test/pagy/extras/elasticsearch_rails_test.rb +++ b/test/pagy/extras/elasticsearch_rails_test.rb @@ -182,6 +182,24 @@ _(pagy.vars[:link_extra]).must_equal 'X' end + it 'paginates response with defaults on Elasticearch 5' do + response = MockElasticsearchRails::ModelES5.search('a') + pagy = Pagy.new_from_elasticsearch_rails(response) + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 10 + _(pagy.page).must_equal 1 + end + + it 'paginates response with vars on Elasticsearch 5' do + response = MockElasticsearchRails::ModelES5.search('b', from: 15, size: 15) + pagy = Pagy.new_from_elasticsearch_rails(response, link_extra: 'X') + _(pagy).must_be_instance_of Pagy + _(pagy.count).must_equal 1000 + _(pagy.items).must_equal 15 + _(pagy.page).must_equal 2 + _(pagy.vars[:link_extra]).must_equal 'X' + end end end From bba1bca18d7e67e299f255339d24e55a95c48630 Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Thu, 23 Apr 2020 09:17:44 +0700 Subject: [PATCH 3/4] used ternary conditional --- lib/pagy/extras/elasticsearch_rails.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/pagy/extras/elasticsearch_rails.rb b/lib/pagy/extras/elasticsearch_rails.rb index 68b078ce9..a44098d66 100644 --- a/lib/pagy/extras/elasticsearch_rails.rb +++ b/lib/pagy/extras/elasticsearch_rails.rb @@ -13,11 +13,7 @@ class Pagy def self.new_from_elasticsearch_rails(response, vars={}) vars[:items] = response.search.options[:size] || 10 vars[:page] = (response.search.options[:from] || 0) / vars[:items] + 1 - total = if response.respond_to?(:raw_response) - response.raw_response['hits']['total'] - else - response.response['hits']['total'] - end + total = response.respond_to?(:raw_response) ? response.raw_response['hits']['total'] : response.response['hits']['total'] vars[:count] = total.is_a?(Hash) ? total['value'] : total new(vars) end From 6dbd3769cf42e40116815e1b64b3b1cf89413450 Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Thu, 23 Apr 2020 09:35:00 +0700 Subject: [PATCH 4/4] version 3.8.0 --- CHANGELOG.md | 16 ++++++++++++++++ lib/config/pagy.rb | 2 +- lib/javascripts/pagy.js | 2 +- lib/pagy.rb | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45d316a42..1e63ec685 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # CHANGELOG +## Version 3.8.0 + +### Changes + +- Khmer tranlation +- Added support for elasticsearch < 6 +- Documentation fixes + +### Commits + +- [bba1bca](http://github.com/ddnexus/pagy/commit/bba1bca): used ternary conditional +- [a9cee7d](http://github.com/ddnexus/pagy/commit/a9cee7d): Support ES5 on elasticsearch rails (#234) +- [d58a39d](http://github.com/ddnexus/pagy/commit/d58a39d): Khmer translation for pagy (#235) +- [7ced96c](http://github.com/ddnexus/pagy/commit/7ced96c): fix for missing suffix fr method reference in doc +- [73600be](http://github.com/ddnexus/pagy/commit/73600be): improved consistency in searchkick and elasticsearch_rails documentation examples (#231) + ## Version 3.7.5 ### Changes diff --git a/lib/config/pagy.rb b/lib/config/pagy.rb index f6fc05239..1b7aaf1d3 100644 --- a/lib/config/pagy.rb +++ b/lib/config/pagy.rb @@ -1,7 +1,7 @@ # encoding: utf-8 # frozen_string_literal: true -# Pagy initializer file (3.7.5) +# Pagy initializer file (3.8.0) # Customize only what you really need and notice that Pagy works also without any of the following lines. # Should you just cherry pick part of this file, please maintain the require-order of the extras diff --git a/lib/javascripts/pagy.js b/lib/javascripts/pagy.js index c29f4cb38..4428dbd26 100644 --- a/lib/javascripts/pagy.js +++ b/lib/javascripts/pagy.js @@ -2,7 +2,7 @@ function Pagy(){} -Pagy.version = '3.7.5'; +Pagy.version = '3.8.0'; Pagy.init = function(arg){ var target = arg instanceof Event || arg === undefined ? document : arg, diff --git a/lib/pagy.rb b/lib/pagy.rb index dea39bc92..bf1e0ac12 100644 --- a/lib/pagy.rb +++ b/lib/pagy.rb @@ -4,7 +4,7 @@ require 'pathname' -class Pagy ; VERSION = '3.7.5' +class Pagy ; VERSION = '3.8.0' # Root pathname to get the path of Pagy files like templates or dictionaries def self.root; @root ||= Pathname.new(__FILE__).dirname.freeze end