esse-jbuilder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4876fda971da8b7067d31ce0724bd341e29f89c9f6fb4dc3f0cf8a9aac783422
4
+ data.tar.gz: 2a19e8ef649406f2e3ed2dd6e7923d877c4ecaf32bc8afc5c66c753b0a37fdfb
5
+ SHA512:
6
+ metadata.gz: 9ff4085f2b8f84cf06829a62de34611f13530bb8961e051f53db24f5f02c3d1df028e2a4e33aa0bd2c559fbb7ce34ba4fe58c921d5e7023f9f2950fe4b66aa25
7
+ data.tar.gz: e6bfab74a4a7a19e04c56569e20758308b371a4d62d67bf435cec095aa2f79c88c115195d60082ad705b6806f58e7a1f01e70a30b6e13e3e648f433f2e3cf98d
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ inherit_mode:
2
+ merge:
3
+ - Exclude
4
+
5
+ require:
6
+ - rubocop-performance
7
+ - rubocop-rspec
8
+ - standard/cop/block_single_line_braces
9
+
10
+ inherit_gem:
11
+ standard: config/base.yml
12
+
13
+ AllCops:
14
+ TargetRubyVersion: 2.5
15
+ SuggestExtensions: false
16
+ Exclude:
17
+ - "db/**/*"
18
+ - "tmp/**/*"
19
+ - "vendor/**/*"
20
+ NewCops: enable
21
+
22
+ RSpec/MultipleExpectations:
23
+ Enabled: false
24
+
25
+ RSpec/ExampleLength:
26
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## 0.0.1 - 2023-11-27
8
+ The first release of the esse-jbuilder plugin
9
+ * Added the `Esse::Jbuilder::Template` class to render a template block.
10
+ * Added the `Esse::Jbuilder::ViewTemplate` class to render a template from a file.
11
+ * Add `search_view_path` configuration option to the `Esse::Config` class.
12
+ * Extends `search` method of index or cluster to accept a block to render a Jbuilder template.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "esse", git: "https://github.com/marcosgz/esse.git", branch: "main"
6
+ gem "jbuilder", "~> 2.11"
7
+ gem "esse-rspec"
8
+
9
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,158 @@
1
+ GIT
2
+ remote: https://github.com/marcosgz/esse.git
3
+ revision: c094ea2f7f6d6d65dc5540b98e41ecd1bd33b43f
4
+ branch: main
5
+ specs:
6
+ esse (0.2.4)
7
+ multi_json
8
+ thor (>= 0.19)
9
+
10
+ PATH
11
+ remote: .
12
+ specs:
13
+ esse-jbuilder (0.0.1)
14
+ esse (>= 0.2.4)
15
+ jbuilder (>= 2)
16
+
17
+ GEM
18
+ remote: https://rubygems.org/
19
+ specs:
20
+ actionview (7.1.2)
21
+ activesupport (= 7.1.2)
22
+ builder (~> 3.1)
23
+ erubi (~> 1.11)
24
+ rails-dom-testing (~> 2.2)
25
+ rails-html-sanitizer (~> 1.6)
26
+ activesupport (7.1.2)
27
+ base64
28
+ bigdecimal
29
+ concurrent-ruby (~> 1.0, >= 1.0.2)
30
+ connection_pool (>= 2.2.5)
31
+ drb
32
+ i18n (>= 1.6, < 2)
33
+ minitest (>= 5.1)
34
+ mutex_m
35
+ tzinfo (~> 2.0)
36
+ ast (2.4.2)
37
+ base64 (0.2.0)
38
+ bigdecimal (3.1.4)
39
+ builder (3.2.4)
40
+ coderay (1.1.3)
41
+ concurrent-ruby (1.2.2)
42
+ connection_pool (2.4.1)
43
+ crass (1.0.6)
44
+ diff-lcs (1.5.0)
45
+ drb (2.2.0)
46
+ ruby2_keywords
47
+ erubi (1.12.0)
48
+ esse-rspec (0.0.6)
49
+ esse (>= 0.2.4)
50
+ rspec (>= 3)
51
+ i18n (1.14.1)
52
+ concurrent-ruby (~> 1.0)
53
+ jbuilder (2.11.5)
54
+ actionview (>= 5.0.0)
55
+ activesupport (>= 5.0.0)
56
+ json (2.6.3)
57
+ language_server-protocol (3.17.0.3)
58
+ lint_roller (1.1.0)
59
+ loofah (2.22.0)
60
+ crass (~> 1.0.2)
61
+ nokogiri (>= 1.12.0)
62
+ method_source (1.0.0)
63
+ minitest (5.20.0)
64
+ multi_json (1.15.0)
65
+ mutex_m (0.2.0)
66
+ nokogiri (1.15.5-x86_64-linux)
67
+ racc (~> 1.4)
68
+ parallel (1.23.0)
69
+ parser (3.2.2.4)
70
+ ast (~> 2.4.1)
71
+ racc
72
+ pry (0.14.2)
73
+ coderay (~> 1.1)
74
+ method_source (~> 1.0)
75
+ racc (1.7.3)
76
+ rails-dom-testing (2.2.0)
77
+ activesupport (>= 5.0.0)
78
+ minitest
79
+ nokogiri (>= 1.6)
80
+ rails-html-sanitizer (1.6.0)
81
+ loofah (~> 2.21)
82
+ nokogiri (~> 1.14)
83
+ rainbow (3.1.1)
84
+ regexp_parser (2.8.2)
85
+ rexml (3.2.6)
86
+ rspec (3.12.0)
87
+ rspec-core (~> 3.12.0)
88
+ rspec-expectations (~> 3.12.0)
89
+ rspec-mocks (~> 3.12.0)
90
+ rspec-core (3.12.2)
91
+ rspec-support (~> 3.12.0)
92
+ rspec-expectations (3.12.3)
93
+ diff-lcs (>= 1.2.0, < 2.0)
94
+ rspec-support (~> 3.12.0)
95
+ rspec-mocks (3.12.6)
96
+ diff-lcs (>= 1.2.0, < 2.0)
97
+ rspec-support (~> 3.12.0)
98
+ rspec-support (3.12.1)
99
+ rubocop (1.57.2)
100
+ json (~> 2.3)
101
+ language_server-protocol (>= 3.17.0)
102
+ parallel (~> 1.10)
103
+ parser (>= 3.2.2.4)
104
+ rainbow (>= 2.2.2, < 4.0)
105
+ regexp_parser (>= 1.8, < 3.0)
106
+ rexml (>= 3.2.5, < 4.0)
107
+ rubocop-ast (>= 1.28.1, < 2.0)
108
+ ruby-progressbar (~> 1.7)
109
+ unicode-display_width (>= 2.4.0, < 3.0)
110
+ rubocop-ast (1.30.0)
111
+ parser (>= 3.2.1.0)
112
+ rubocop-capybara (2.19.0)
113
+ rubocop (~> 1.41)
114
+ rubocop-factory_bot (2.24.0)
115
+ rubocop (~> 1.33)
116
+ rubocop-performance (1.19.1)
117
+ rubocop (>= 1.7.0, < 2.0)
118
+ rubocop-ast (>= 0.4.0)
119
+ rubocop-rspec (2.25.0)
120
+ rubocop (~> 1.40)
121
+ rubocop-capybara (~> 2.17)
122
+ rubocop-factory_bot (~> 2.22)
123
+ ruby-progressbar (1.13.0)
124
+ ruby2_keywords (0.0.5)
125
+ standard (1.32.0)
126
+ language_server-protocol (~> 3.17.0.2)
127
+ lint_roller (~> 1.0)
128
+ rubocop (~> 1.57.2)
129
+ standard-custom (~> 1.0.0)
130
+ standard-performance (~> 1.2)
131
+ standard-custom (1.0.2)
132
+ lint_roller (~> 1.0)
133
+ rubocop (~> 1.50)
134
+ standard-performance (1.2.1)
135
+ lint_roller (~> 1.1)
136
+ rubocop-performance (~> 1.19.1)
137
+ thor (1.3.0)
138
+ tzinfo (2.0.6)
139
+ concurrent-ruby (~> 1.0)
140
+ unicode-display_width (2.5.0)
141
+
142
+ PLATFORMS
143
+ x86_64-linux
144
+
145
+ DEPENDENCIES
146
+ esse!
147
+ esse-jbuilder!
148
+ esse-rspec
149
+ jbuilder (~> 2.11)
150
+ pry
151
+ rspec
152
+ rubocop
153
+ rubocop-performance
154
+ rubocop-rspec
155
+ standard
156
+
157
+ BUNDLED WITH
158
+ 2.4.13
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Marcos G. Zimmermann
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # Esse Jbuilder Plugin
2
+
3
+ Extends the [esse](https://github.com/marcosgz/esse) search to use [jbuilder](https://github.com/rails/jbuilder) as the default template engine.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'esse-jbuilder'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ ## Configuration
20
+
21
+ This gem adds the `search_view_path` configuration option to the `Esse::Config` class.
22
+
23
+ ```ruby
24
+ Esse.configure do |config|
25
+ config.search_view_path = 'app/searches'
26
+ end
27
+ ```
28
+
29
+ This options is used to set the default path where the search templates are located. The default value is `app/searches`.
30
+
31
+ ## Usage
32
+
33
+ The block passed to the `search` method will be evaluated in the context of a `JbuilderTemplate` instance.
34
+
35
+ ```ruby
36
+ # Single index
37
+ @search = UsersIndex.search(params[:q]) do |json|
38
+ json.query do
39
+ json.match do
40
+ json.set! 'name', params[:q]
41
+ end
42
+ end
43
+ end
44
+
45
+ # Multiple indexes
46
+ @search = Esse.cluster.search(CitiesIndex, CountiesIndex) do |json|
47
+ json.query do
48
+ json.match do
49
+ json.set! 'name', params[:q]
50
+ end
51
+ end
52
+ end
53
+ ```
54
+
55
+ example using partials
56
+
57
+ ```ruby
58
+ CitiesIndex.search do |json|
59
+ json.query do
60
+ json.bool do
61
+ json.must do
62
+ json.child! do
63
+ json.match do
64
+ json.set! 'name', params[:q]
65
+ end
66
+ end
67
+ if (states = params[:state_abbr])
68
+ json.child! do
69
+ json.partial! 'shared/terms_field', field: 'state_abbr', values: state_abbr
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ json.aggs do
76
+ json.states do
77
+ json.partial! 'shared/field_aggregation', field: 'state_abbr'
78
+ end
79
+ end
80
+ end
81
+ ```
82
+
83
+ ### Rendering
84
+
85
+ For more advanced rendering, you can also use the standalone `Esse::Jbuilder::Template` or `Esse::Jbuilder::ViewTemplate` classes.
86
+
87
+ * Esse::Jbuilder::Template - This class is used to render a template block.
88
+ * Esse::Jbuilder::ViewTemplate - This class is used to render a template from a file. Note that you must have the `jbuilder` template handler registered in your Rails application.
89
+
90
+ This brings a very powerful to create searcher classes. Example:
91
+
92
+ ```ruby
93
+ class Searchers::CitiesSearcher
94
+ extend Forwardable
95
+ def_delegators :search, :results
96
+
97
+ def initialize(params)
98
+ @params = params.transform_keys(&:to_sym)
99
+ end
100
+
101
+ private
102
+
103
+ attr_reader :params
104
+
105
+ def search
106
+ CitiesIndex.search(body: body).limit(params[:limit] || 10).offset(params[:offset] || 0)
107
+ end
108
+
109
+ def body
110
+ Esse::Jbuilder::ViewTemplate.call('cities/search', **params)
111
+ end
112
+ end
113
+
114
+ Searchers::CitiesSearcher.new(params).results
115
+ ```
116
+
117
+
118
+ ## Development
119
+
120
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake none` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
121
+
122
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
123
+
124
+ ## Contributing
125
+
126
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marcosgz/esse-jbuilder.
127
+
128
+ ## License
129
+
130
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "esse", git: "https://github.com/marcosgz/esse.git", branch: "main"
6
+ gem "jbuilder", "~> 2.11"
7
+ gem "rails", "~> 5.2"
8
+ gem "esse-rspec"
9
+
10
+ gemspec path: ".."
@@ -0,0 +1,233 @@
1
+ GIT
2
+ remote: https://github.com/marcosgz/esse.git
3
+ revision: c094ea2f7f6d6d65dc5540b98e41ecd1bd33b43f
4
+ branch: main
5
+ specs:
6
+ esse (0.2.4)
7
+ multi_json
8
+ thor (>= 0.19)
9
+
10
+ PATH
11
+ remote: ..
12
+ specs:
13
+ esse-jbuilder (0.0.1)
14
+ esse (>= 0.2.4)
15
+ jbuilder (>= 2)
16
+
17
+ GEM
18
+ remote: https://rubygems.org/
19
+ specs:
20
+ actioncable (5.2.8.1)
21
+ actionpack (= 5.2.8.1)
22
+ nio4r (~> 2.0)
23
+ websocket-driver (>= 0.6.1)
24
+ actionmailer (5.2.8.1)
25
+ actionpack (= 5.2.8.1)
26
+ actionview (= 5.2.8.1)
27
+ activejob (= 5.2.8.1)
28
+ mail (~> 2.5, >= 2.5.4)
29
+ rails-dom-testing (~> 2.0)
30
+ actionpack (5.2.8.1)
31
+ actionview (= 5.2.8.1)
32
+ activesupport (= 5.2.8.1)
33
+ rack (~> 2.0, >= 2.0.8)
34
+ rack-test (>= 0.6.3)
35
+ rails-dom-testing (~> 2.0)
36
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
37
+ actionview (5.2.8.1)
38
+ activesupport (= 5.2.8.1)
39
+ builder (~> 3.1)
40
+ erubi (~> 1.4)
41
+ rails-dom-testing (~> 2.0)
42
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
43
+ activejob (5.2.8.1)
44
+ activesupport (= 5.2.8.1)
45
+ globalid (>= 0.3.6)
46
+ activemodel (5.2.8.1)
47
+ activesupport (= 5.2.8.1)
48
+ activerecord (5.2.8.1)
49
+ activemodel (= 5.2.8.1)
50
+ activesupport (= 5.2.8.1)
51
+ arel (>= 9.0)
52
+ activestorage (5.2.8.1)
53
+ actionpack (= 5.2.8.1)
54
+ activerecord (= 5.2.8.1)
55
+ marcel (~> 1.0.0)
56
+ activesupport (5.2.8.1)
57
+ concurrent-ruby (~> 1.0, >= 1.0.2)
58
+ i18n (>= 0.7, < 2)
59
+ minitest (~> 5.1)
60
+ tzinfo (~> 1.1)
61
+ arel (9.0.0)
62
+ ast (2.4.2)
63
+ builder (3.2.4)
64
+ coderay (1.1.3)
65
+ concurrent-ruby (1.2.2)
66
+ crass (1.0.6)
67
+ date (3.3.4)
68
+ diff-lcs (1.5.0)
69
+ erubi (1.12.0)
70
+ esse-rspec (0.0.6)
71
+ esse (>= 0.2.4)
72
+ rspec (>= 3)
73
+ globalid (1.1.0)
74
+ activesupport (>= 5.0)
75
+ i18n (1.14.1)
76
+ concurrent-ruby (~> 1.0)
77
+ jbuilder (2.11.5)
78
+ actionview (>= 5.0.0)
79
+ activesupport (>= 5.0.0)
80
+ json (2.6.3)
81
+ language_server-protocol (3.17.0.3)
82
+ lint_roller (1.1.0)
83
+ loofah (2.22.0)
84
+ crass (~> 1.0.2)
85
+ nokogiri (>= 1.12.0)
86
+ mail (2.8.1)
87
+ mini_mime (>= 0.1.1)
88
+ net-imap
89
+ net-pop
90
+ net-smtp
91
+ marcel (1.0.2)
92
+ method_source (1.0.0)
93
+ mini_mime (1.1.5)
94
+ minitest (5.20.0)
95
+ multi_json (1.15.0)
96
+ net-imap (0.4.6)
97
+ date
98
+ net-protocol
99
+ net-pop (0.1.2)
100
+ net-protocol
101
+ net-protocol (0.2.2)
102
+ timeout
103
+ net-smtp (0.4.0)
104
+ net-protocol
105
+ nio4r (2.6.1)
106
+ nokogiri (1.15.5-x86_64-linux)
107
+ racc (~> 1.4)
108
+ parallel (1.23.0)
109
+ parser (3.2.2.4)
110
+ ast (~> 2.4.1)
111
+ racc
112
+ pry (0.14.2)
113
+ coderay (~> 1.1)
114
+ method_source (~> 1.0)
115
+ racc (1.7.3)
116
+ rack (2.2.8)
117
+ rack-test (2.1.0)
118
+ rack (>= 1.3)
119
+ rails (5.2.8.1)
120
+ actioncable (= 5.2.8.1)
121
+ actionmailer (= 5.2.8.1)
122
+ actionpack (= 5.2.8.1)
123
+ actionview (= 5.2.8.1)
124
+ activejob (= 5.2.8.1)
125
+ activemodel (= 5.2.8.1)
126
+ activerecord (= 5.2.8.1)
127
+ activestorage (= 5.2.8.1)
128
+ activesupport (= 5.2.8.1)
129
+ bundler (>= 1.3.0)
130
+ railties (= 5.2.8.1)
131
+ sprockets-rails (>= 2.0.0)
132
+ rails-dom-testing (2.2.0)
133
+ activesupport (>= 5.0.0)
134
+ minitest
135
+ nokogiri (>= 1.6)
136
+ rails-html-sanitizer (1.6.0)
137
+ loofah (~> 2.21)
138
+ nokogiri (~> 1.14)
139
+ railties (5.2.8.1)
140
+ actionpack (= 5.2.8.1)
141
+ activesupport (= 5.2.8.1)
142
+ method_source
143
+ rake (>= 0.8.7)
144
+ thor (>= 0.19.0, < 2.0)
145
+ rainbow (3.1.1)
146
+ rake (13.1.0)
147
+ regexp_parser (2.8.2)
148
+ rexml (3.2.6)
149
+ rspec (3.12.0)
150
+ rspec-core (~> 3.12.0)
151
+ rspec-expectations (~> 3.12.0)
152
+ rspec-mocks (~> 3.12.0)
153
+ rspec-core (3.12.2)
154
+ rspec-support (~> 3.12.0)
155
+ rspec-expectations (3.12.3)
156
+ diff-lcs (>= 1.2.0, < 2.0)
157
+ rspec-support (~> 3.12.0)
158
+ rspec-mocks (3.12.6)
159
+ diff-lcs (>= 1.2.0, < 2.0)
160
+ rspec-support (~> 3.12.0)
161
+ rspec-support (3.12.1)
162
+ rubocop (1.57.2)
163
+ json (~> 2.3)
164
+ language_server-protocol (>= 3.17.0)
165
+ parallel (~> 1.10)
166
+ parser (>= 3.2.2.4)
167
+ rainbow (>= 2.2.2, < 4.0)
168
+ regexp_parser (>= 1.8, < 3.0)
169
+ rexml (>= 3.2.5, < 4.0)
170
+ rubocop-ast (>= 1.28.1, < 2.0)
171
+ ruby-progressbar (~> 1.7)
172
+ unicode-display_width (>= 2.4.0, < 3.0)
173
+ rubocop-ast (1.30.0)
174
+ parser (>= 3.2.1.0)
175
+ rubocop-capybara (2.19.0)
176
+ rubocop (~> 1.41)
177
+ rubocop-factory_bot (2.24.0)
178
+ rubocop (~> 1.33)
179
+ rubocop-performance (1.19.1)
180
+ rubocop (>= 1.7.0, < 2.0)
181
+ rubocop-ast (>= 0.4.0)
182
+ rubocop-rspec (2.25.0)
183
+ rubocop (~> 1.40)
184
+ rubocop-capybara (~> 2.17)
185
+ rubocop-factory_bot (~> 2.22)
186
+ ruby-progressbar (1.13.0)
187
+ sprockets (4.2.1)
188
+ concurrent-ruby (~> 1.0)
189
+ rack (>= 2.2.4, < 4)
190
+ sprockets-rails (3.4.2)
191
+ actionpack (>= 5.2)
192
+ activesupport (>= 5.2)
193
+ sprockets (>= 3.0.0)
194
+ standard (1.32.0)
195
+ language_server-protocol (~> 3.17.0.2)
196
+ lint_roller (~> 1.0)
197
+ rubocop (~> 1.57.2)
198
+ standard-custom (~> 1.0.0)
199
+ standard-performance (~> 1.2)
200
+ standard-custom (1.0.2)
201
+ lint_roller (~> 1.0)
202
+ rubocop (~> 1.50)
203
+ standard-performance (1.2.1)
204
+ lint_roller (~> 1.1)
205
+ rubocop-performance (~> 1.19.1)
206
+ thor (1.3.0)
207
+ thread_safe (0.3.6)
208
+ timeout (0.4.1)
209
+ tzinfo (1.2.11)
210
+ thread_safe (~> 0.1)
211
+ unicode-display_width (2.5.0)
212
+ websocket-driver (0.7.6)
213
+ websocket-extensions (>= 0.1.0)
214
+ websocket-extensions (0.1.5)
215
+
216
+ PLATFORMS
217
+ x86_64-linux
218
+
219
+ DEPENDENCIES
220
+ esse!
221
+ esse-jbuilder!
222
+ esse-rspec
223
+ jbuilder (~> 2.11)
224
+ pry
225
+ rails (~> 5.2)
226
+ rspec
227
+ rubocop
228
+ rubocop-performance
229
+ rubocop-rspec
230
+ standard
231
+
232
+ BUNDLED WITH
233
+ 2.4.13
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esse
4
+ module Jbuilder
5
+ module Config
6
+ def self.included(base)
7
+ base.__send__(:include, InstanceMethods)
8
+ end
9
+
10
+ module InstanceMethods
11
+ DEFAULT_SEARCH_VIEW_PATH = "app/searches"
12
+
13
+ def search_view_path
14
+ @search_view_path ||= Pathname.new(DEFAULT_SEARCH_VIEW_PATH)
15
+ end
16
+
17
+ def search_view_path=(path)
18
+ @search_view_path = path.is_a?(String) ? Pathname.new(path) : path
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ json.query do
2
+ json.set! :match, {"name" => @name}
3
+ end
4
+
5
+ json.aggregations do
6
+ json.partial! "states/abbr_aggs"
7
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esse
4
+ module Jbuilder
5
+ module SearchQuery
6
+ module InstanceMethods
7
+ def initialize(transport, *indices, suffix: nil, **definition, &block)
8
+ super(transport, *indices, suffix: suffix, **definition)
9
+
10
+ if block
11
+ @definition[:body] ||= {}
12
+ attrs = render_jbuilder_template(&block)
13
+ @definition[:body].merge! Esse::HashUtils.deep_transform_keys(attrs, &:to_sym)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def render_jbuilder_template(&block)
20
+ if defined?(Rails)
21
+ lookup_context = ::ActionView::LookupContext.new(Esse.config.search_view_path)
22
+ context = ActionView::Base.new(lookup_context, {}, nil, %i[json])
23
+ ::JbuilderTemplate.new(context, &block).attributes!
24
+ else
25
+ ::Jbuilder.new(&block).attributes!
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esse
4
+ module Jbuilder
5
+ class WithAssigns < ::Jbuilder
6
+ attr_reader :__assigns
7
+
8
+ def initialize(options = {})
9
+ @__assigns = options.delete(:assigns) || {}
10
+ super(options)
11
+ end
12
+
13
+ def __assign(key)
14
+ __assigns[key]
15
+ end
16
+
17
+ def partial!(view_filename, **assigns)
18
+ raise ::NotImplementedError, "Partial rendering is not supported. Consider using Esse::Jbuilder::ViewTemplate.call instead."
19
+ end
20
+ end
21
+
22
+ class Template
23
+ attr_reader :view_filename, :assigns
24
+
25
+ def self.call(view_filename = nil, **assigns, &block)
26
+ new(view_filename, **assigns).to_hash(&block)
27
+ end
28
+
29
+ def initialize(view_filename = nil, **assigns)
30
+ @view_filename = view_filename
31
+ @assigns = assigns
32
+ end
33
+
34
+ def to_hash(&block)
35
+ func = block || begin
36
+ raise ArgumentError, "Missing view or block" unless view_filename || block
37
+ fragments = view_filename.split("/")
38
+ filename = fragments.pop
39
+ filename = "#{filename}.json.jbuilder" unless filename.end_with?(".json.jbuilder")
40
+ rel_path = fragments.join("/")
41
+
42
+ ->(json) {
43
+ json.instance_eval(File.read(Esse.config.search_view_path.join("#{rel_path}/#{filename}").to_s), view_filename, 1)
44
+ }
45
+ end
46
+
47
+ WithAssigns.new(assigns: assigns, &func).attributes!
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esse
4
+ module Jbuilder
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+ require "jbuilder/jbuilder_template"
5
+
6
+ module Esse
7
+ module Jbuilder
8
+ class JbuilderTemplate < ::JbuilderTemplate
9
+ def _render_template!(path, options = {})
10
+ options[:template] = path
11
+ options[:locals] ||= {}
12
+ options.delete(:partial)
13
+ _render_partial(options)
14
+ end
15
+ end
16
+
17
+ class ViewTemplate
18
+ attr_reader :view_filename, :assigns
19
+
20
+ def self.call(view_filename, **assigns)
21
+ new(view_filename, **assigns).to_hash
22
+ end
23
+
24
+ def initialize(view_filename, **assigns)
25
+ @view_filename = view_filename
26
+ @assigns = assigns
27
+ end
28
+
29
+ def to_hash
30
+ lookup_context = ::ActionView::LookupContext.new(Esse.config.search_view_path)
31
+ view = ActionView::Base.new(lookup_context, assigns, nil, %i[json])
32
+ JbuilderTemplate.new(view) do |json|
33
+ json._render_template! view_filename
34
+ end.attributes!
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "esse"
4
+ require "action_view"
5
+ require "active_support"
6
+ require "jbuilder"
7
+
8
+ require_relative "jbuilder/version"
9
+ require_relative "jbuilder/config"
10
+ require_relative "jbuilder/template"
11
+ require_relative "jbuilder/search_query"
12
+
13
+ if defined?(::Rails)
14
+ require_relative "jbuilder/view_template"
15
+ end
16
+
17
+ Esse::Config.__send__ :include, Esse::Jbuilder::Config
18
+ Esse::Search::Query.prepend Esse::Jbuilder::SearchQuery::InstanceMethods
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: esse-jbuilder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marcos G. Zimmermann
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: esse
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: jbuilder
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: standard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Extends the Esse Search using Jbuilder DSL to build the request body
126
+ email:
127
+ - mgzmaster@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".rubocop.yml"
133
+ - CHANGELOG.md
134
+ - Gemfile
135
+ - Gemfile.lock
136
+ - LICENSE
137
+ - README.md
138
+ - Rakefile
139
+ - ci/Gemfile.rails-5.2
140
+ - ci/Gemfile.rails-5.2.lock
141
+ - lib/esse/jbuilder.rb
142
+ - lib/esse/jbuilder/config.rb
143
+ - lib/esse/jbuilder/index.json.jbuilder
144
+ - lib/esse/jbuilder/search_query.rb
145
+ - lib/esse/jbuilder/template.rb
146
+ - lib/esse/jbuilder/version.rb
147
+ - lib/esse/jbuilder/view_template.rb
148
+ homepage: https://github.com/marcosgz/esse-jbuilder
149
+ licenses:
150
+ - MIT
151
+ metadata:
152
+ homepage_uri: https://github.com/marcosgz/esse-jbuilder
153
+ source_code_uri: https://github.com/marcosgz/esse-jbuilder
154
+ changelog_uri: https://github.com/marcosgz/esse-jbuilder/blob/main/CHANGELOG.md
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: 2.5.0
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubygems_version: 3.3.7
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Extensions for the Esse Search using Jbuilder DSL
174
+ test_files: []