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/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/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/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 ]
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
diff --git a/lib/pagy/extras/elasticsearch_rails.rb b/lib/pagy/extras/elasticsearch_rails.rb
index 7a40a5dba..a44098d66 100644
--- a/lib/pagy/extras/elasticsearch_rails.rb
+++ b/lib/pagy/extras/elasticsearch_rails.rb
@@ -13,7 +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 = response.raw_response['hits']['total']
+ 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
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