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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4281765768b325decfff165db5df09cf406e2f6d9e211f6ecdfedbfa0dfd0a9
4
- data.tar.gz: b654970a986c50e67112464b33649650f9fb0e43f858d8aade49330ae1cbad60
3
+ metadata.gz: 7801b68f7ae1a30624a95fcf9713bb1251f2e7831960ddd173e64b152ba24f94
4
+ data.tar.gz: 057c7d13a8922bdeba6150e6d2df6ecec65d0f8af169a50b879ccadbee3688b3
5
5
  SHA512:
6
- metadata.gz: 866911090a04393d7d92c618daac7dd6bb02330e939d23a654375b014c363d44c574f2948cf3cd6f7bf536c44c2ccac24086774685436054a8557cb400b05ba2
7
- data.tar.gz: 89fa51203f3af3018585810f1631ef15a5f71f53dd9a0ac27a8141c929b22a57f8890d53581dcf53e1aec26af9a7f7dca7c5c730fab7bb71dc2c1a7e3c939113
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,4 @@
1
+ <% [name] = [name].decorate if [name].respond_to?(:decorate) %>
2
+
3
+ <strong><%= t 'b.[name]' %></strong><br>
4
+ <small class="text-muted"><%= [name].id %></small>
@@ -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
- "#{search_context.namespace.to_s.underscore}/search"
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
@@ -1,3 +1,3 @@
1
1
  module Plok
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
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.0
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-04 00:00:00.000000000 Z
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