plok 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/plok/search/result_object_generator.rb +41 -0
- data/lib/generators/plok/search/templates/result_object.html.erb +4 -0
- data/lib/generators/plok/search/templates/result_object.rb +19 -0
- data/lib/plok/search/result_objects/base.rb +12 -1
- data/lib/plok/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7801b68f7ae1a30624a95fcf9713bb1251f2e7831960ddd173e64b152ba24f94
|
4
|
+
data.tar.gz: 057c7d13a8922bdeba6150e6d2df6ecec65d0f8af169a50b879ccadbee3688b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '087677f2caccca0fc4d2e342790860f8514aa002447f2555e018aa4e60e5bb817111209c7cea3c84452ec24b717291fe1e05dc061623cc7b5dd2cd5791271f4b'
|
7
|
+
data.tar.gz: 394542cf38ab37c5740622fee0fc6de8c0b9bd9697e91b94323a3b0edd84ce60aa750af2daf14ccdaaa5782282d548c5ac7a9a77fd56567e936f9164c9a631c2
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
class Plok::Search::ResultObjectGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('templates', __dir__)
|
5
|
+
class_option :name, type: :string
|
6
|
+
class_option :namespace, type: :string
|
7
|
+
|
8
|
+
def create
|
9
|
+
# TODO: Check for missing params
|
10
|
+
copy_file 'result_object.rb', class_path
|
11
|
+
gsub_file(class_path, '[name]', options.name)
|
12
|
+
gsub_file(class_path, '[namespace]', options.namespace)
|
13
|
+
gsub_file(class_path, '[class_name]', to_snakecase(options.name))
|
14
|
+
gsub_file(class_path, '[namespace_module_name]', to_snakecase(options.namespace))
|
15
|
+
|
16
|
+
copy_file 'result_object.html.erb', markup_path
|
17
|
+
gsub_file(markup_path, '[name]', options.name)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def app_name
|
23
|
+
Rails.application.class.name.split('::').first
|
24
|
+
end
|
25
|
+
|
26
|
+
def class_path
|
27
|
+
"lib/plok/search/result_objects/#{options.namespace}/#{options.name}.rb"
|
28
|
+
end
|
29
|
+
|
30
|
+
def markup_path
|
31
|
+
"app/views/plok/search/result_objects/#{options.namespace}/_#{options.name}.html.erb"
|
32
|
+
end
|
33
|
+
|
34
|
+
def namespace_class_spec_path
|
35
|
+
"spec/lib/plok/search/#{options.namespace}_spec.rb"
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_snakecase(name)
|
39
|
+
name.to_s.camelcase
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Plok::Search::ResultObjects
|
2
|
+
# This class should be used to further manipulate any of the data provided
|
3
|
+
# through #search_context or Plok::Search::ResultObjects::Base.
|
4
|
+
#
|
5
|
+
# A search context class is accessible through #search_context. This
|
6
|
+
# gives you access to #search_context.controller, which can be used to
|
7
|
+
# call routes upon.
|
8
|
+
#
|
9
|
+
# Example of: If an autocomplete requires additional data to be rendered in
|
10
|
+
# the partial (think another model, or an API call), one could override
|
11
|
+
# the #locals method to include more variables. You could do this directly
|
12
|
+
# in the partial as well, but this way we have separation of concerns.
|
13
|
+
class [namespace_module_name]::[class_name] < Plok::Search::ResultObjects::Base
|
14
|
+
def url
|
15
|
+
# TODO: Add a path to where people should end up by clicking the result.
|
16
|
+
#search_context.controller.[namespace]_[name]_path(searchable)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -52,12 +52,23 @@ module Plok
|
|
52
52
|
{ "#{partial_target}": index.searchable, index: index }
|
53
53
|
end
|
54
54
|
|
55
|
+
def namespace
|
56
|
+
search_context.namespace.to_s.underscore
|
57
|
+
end
|
58
|
+
|
55
59
|
def partial
|
56
60
|
"#{partial_path}/#{partial_target}"
|
57
61
|
end
|
58
62
|
|
59
63
|
def partial_path
|
60
|
-
|
64
|
+
# TODO: This is a fallback for older Plok versions whose result object
|
65
|
+
# partials still reside in app/views/backens/search/*. Best to remove
|
66
|
+
# this at a later stage, but for now they can be backwards compatible.
|
67
|
+
if File.exists?("app/views/#{namespace}/search/_#{partial_target}.html.erb")
|
68
|
+
return "#{namespace}/search/"
|
69
|
+
end
|
70
|
+
|
71
|
+
"plok/search/result_objects/#{namespace}"
|
61
72
|
end
|
62
73
|
|
63
74
|
def partial_target
|
data/lib/plok/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Davy Hellemans
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-11-
|
12
|
+
date: 2022-11-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -108,8 +108,11 @@ files:
|
|
108
108
|
- db/migrate/20221031143932_add_namespace_to_search_indices.rb
|
109
109
|
- lib/generators/plok/search/USAGE
|
110
110
|
- lib/generators/plok/search/class_generator.rb
|
111
|
+
- lib/generators/plok/search/result_object_generator.rb
|
111
112
|
- lib/generators/plok/search/templates/namespace_class.rb
|
112
113
|
- lib/generators/plok/search/templates/namespace_class_spec.rb
|
114
|
+
- lib/generators/plok/search/templates/result_object.html.erb
|
115
|
+
- lib/generators/plok/search/templates/result_object.rb
|
113
116
|
- lib/generators/plok/sidebar/USAGE
|
114
117
|
- lib/generators/plok/sidebar/sidebar_generator.rb
|
115
118
|
- lib/generators/plok/sidebar/templates/_menu_item.html.erb
|