Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Apr 23, 2020
2 parents 7ced96c + 6dbd376 commit c2c4f39
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 5 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/extras/elasticsearch_rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
```

Expand Down
2 changes: 1 addition & 1 deletion lib/config/pagy.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/javascripts/pagy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions lib/locales/km.yml
Original file line number Diff line number Diff line change
@@ -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: "&lsaquo;&nbsp;មុន"
next: "បន្ទាប់&nbsp;&rsaquo;"
gap: "&hellip;"

info:
no_items: "មិនមាន %{item_name} ទេ"
single_page: "បង្ហាញ <b>%{count}</b> %{item_name}"
multiple_pages: "បង្ហាញ %{item_name} <b>%{from}-%{to}</b> នៃ <b>%{count}</b> ជាចំនួនសរុប"

combo_nav_js: "ទំព័រ %{page_input} នៃ %{pages}"

items_selector_js: "បង្ហាញ %{items_input} %{item_name} ក្នុង ១ ទំព័រ"
1 change: 1 addition & 0 deletions lib/locales/utils/p11n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy/extras/elasticsearch_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions test/mock_helpers/elasticsearch_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions test/pagy/extras/elasticsearch_rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c2c4f39

Please sign in to comment.