hot-glue 0.6.1 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -1
  3. data/Gemfile.lock +2 -2
  4. data/README.md +193 -14
  5. data/app/helpers/hot_glue/controller_helper.rb +116 -12
  6. data/app/helpers/hot_glue_helper.rb +2 -0
  7. data/lib/generators/hot_glue/fields/association_field.rb +73 -2
  8. data/lib/generators/hot_glue/fields/boolean_field.rb +30 -0
  9. data/lib/generators/hot_glue/fields/date_field.rb +21 -1
  10. data/lib/generators/hot_glue/fields/date_time_field.rb +21 -1
  11. data/lib/generators/hot_glue/fields/enum_field.rb +22 -1
  12. data/lib/generators/hot_glue/fields/field.rb +4 -0
  13. data/lib/generators/hot_glue/fields/float_field.rb +12 -0
  14. data/lib/generators/hot_glue/fields/string_field.rb +18 -0
  15. data/lib/generators/hot_glue/fields/text_field.rb +20 -0
  16. data/lib/generators/hot_glue/fields/time_field.rb +17 -1
  17. data/lib/generators/hot_glue/markup_templates/erb.rb +61 -15
  18. data/lib/generators/hot_glue/scaffold_generator.rb +139 -16
  19. data/lib/generators/hot_glue/set_search_interface_install_generator.rb +26 -0
  20. data/lib/generators/hot_glue/templates/controller.rb.erb +50 -39
  21. data/lib/generators/hot_glue/templates/erb/_edit.erb +3 -1
  22. data/lib/generators/hot_glue/templates/erb/_list.erb +5 -0
  23. data/lib/generators/hot_glue/templates/erb/_new_form.erb +4 -1
  24. data/lib/generators/hot_glue/templates/javascript/date_range_picker_controller.js +45 -0
  25. data/lib/generators/hot_glue/templates/javascript/search_form_controller.js +16 -0
  26. data/lib/generators/hot_glue/templates/javascript/time_range_picker_controller.js +38 -0
  27. data/lib/generators/hot_glue/templates/typeahead_controller.rb.erb +1 -0
  28. data/lib/generators/hot_glue/typeahead_generator.rb +5 -1
  29. data/lib/hotglue/version.rb +1 -1
  30. metadata +7 -3
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class <%= controller_class_name %> < <%= controller_descends_from %>
2
4
  # regenerate this controller with
3
5
  <% if defined?(RuboCop) %># rubocop:disable Layout/LineLength
@@ -20,7 +22,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
20
22
 
21
23
  nest_chain << arg %>
22
24
  before_action :<%= arg[:singular] %><%= ", if: -> { params.include?(:#{arg[:singular]}_id) }" if arg[:optional] %><% } %><% end %>
23
- before_action :load_<%= singular_name %>, only: [:show, :edit, :update, :destroy]
25
+ before_action :load_<%= singular_name %>, only: %i[show edit update destroy]
24
26
  after_action -> { flash.discard }, if: -> { request.format.symbol == :turbo_stream }
25
27
  <% if @nested_set.any? %>def <%= @nested_set[0][:singular] %><% if @god
26
28
  next_object = nil
@@ -68,42 +70,40 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
68
70
  end<% end %>
69
71
  <% if @paginate_per_page_selector %>def per
70
72
  params[:per] || 10
73
+ end<% end %>
74
+ <% unless @no_list %>
75
+ def load_all_<%= plural %>
76
+ <%= load_all_code %>
71
77
  end
72
78
 
73
- <% end %>def load_all_<%= plural %><% if @pundit %>
74
- @<%= plural_name %> = policy_scope(<%= object_scope %>).page(params[:page])<%= n_plus_one_includes %><%= ".per(per)" if @paginate_per_page_selector %>
75
- <% else %> <% if !@self_auth %>
76
- @<%= plural_name %> = <%= object_scope.gsub("@",'') %><%= n_plus_one_includes %>.page(params[:page])<%= ".per(per)" if @paginate_per_page_selector %><%= " if params.include?(:#{ @nested_set.last[:singular]}_id)" if @nested_set.any? && @nested_set[0] && @nested_set[0][:optional] %><% if @nested_set[0] && @nested_set[0][:optional] %>
77
- @<%= plural_name %> = <%= class_name %>.all<% end %><% else %>
78
- @<%= plural_name %> = <%= class_name %>.where(id: <%= auth_object.gsub("@",'') %>.id)<%= n_plus_one_includes %>.page(params[:page])<%= ".per(per)" if @paginate_per_page_selector %><% end %>
79
- <% end %>
80
- end
81
-
82
- def index
79
+ def index <% if @search == "set" %>
80
+ @q = params[:q] || <%= {"0" => @search_fields.collect{|foo| {"#{foo}_match".to_sym => "", "#{foo}_search".to_sym => ""}}.reduce({}, :merge) } %> <% end %><% if @search_fields %>
81
+ <%= @search_fields.collect{|field_name| @columns_map[field_name.to_sym].code_to_reset_match_if_search_is_blank}.compact.join(" \n") %><% end %>
83
82
  load_all_<%= plural %><% if @pundit %><% if @pundit %>
84
83
  authorize @<%= plural_name %><% end %>
85
84
  rescue Pundit::NotAuthorizedError
86
- flash[:alert] = "You are not authorized to perform this action."
87
- render "layouts/error"<% end %>
88
- end
85
+ flash[:alert] = 'You are not authorized to perform this action.'
86
+ render 'layouts/error'<% end %>
87
+ end<% end %>
89
88
 
90
89
  <% if create_action %> def new<% if @object_owner_sym %>
91
- @<%= singular_name %> = <% if @pundit %>policy_scope(<% end %><%= class_name %><% if @pundit %>)<% end %>.new(<% if eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %><%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>)<% elsif @object_owner_optional && any_nested? %>
90
+ @<%= singular_name %> = <% if @pundit %>policy_scope(<% end %><%= class_name %><% if @pundit %>)<% end %>.new<% if eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %>(<%= @object_owner_sym %>: <%= @object_owner_eval %>)<% end %><% elsif @object_owner_optional && any_nested? %>
92
91
  @<%= singular_name %> = <% if @pundit %>policy_scope(<% end %><%= class_name %><% if @pundit %>)<% end %>.new({}.merge(<%= @nested_set.last[:singular] %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {}))<% else %>
93
92
  @<%= singular_name %> = <% if @pundit %>policy_scope(<% end %><%= class_name %><% if @pundit %>)<% end %>.new(<% if any_nested? %><%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>)<% end %>
94
93
  <% if @pundit %>authorize @<%= singular_name %><% end %><% if @pundit %>
95
- @action = "new"
94
+ @action = 'new'
96
95
  rescue Pundit::NotAuthorizedError
97
- flash[:alert] = "You are not authorized to perform this action."
96
+ flash[:alert] = 'You are not authorized to perform this action.'
98
97
  load_all_users
99
98
  render :index<% end %>
100
99
  end
101
100
 
102
101
  def create
103
- modified_params = modify_date_inputs_on_params(<%= singular_name %>_params.dup, <%= current_user_object %>, <%= datetime_fields_list %>) <% if @object_owner_sym && eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %>
102
+ flash[:alert] = +''
103
+ flash[:notice] = +''
104
+ modified_params = modify_date_inputs_on_params(<%= singular_name %>_params.dup, <%= current_user_object %>, <%= datetime_fields_list %>)<% if @object_owner_sym && eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %>
104
105
  modified_params = modified_params.merge(<%= @object_owner_sym %>: <%= @object_owner_eval %>) <% elsif @object_owner_optional && any_nested? %>
105
- modified_params = modified_params.merge(<%= @object_owner_name %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {}) <% elsif !@object_owner_eval.empty? && !@god %>
106
- modified_params = modified_params.merge(<%= @object_owner_eval %>) <% end %>
106
+ modified_params = modified_params.merge(<%= @object_owner_name %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {}) <% end %>
107
107
 
108
108
  <% if @hawk_keys.any? %>
109
109
  modified_params = hawk_params({<%= hawk_to_ruby %>}, modified_params)<% end %>
@@ -112,36 +112,37 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
112
112
  <% if @pundit %><% @related_sets.each do |key, related_set| %>
113
113
  check_<%= related_set[:association_ids_method].to_s %>_permissions(modified_params, :create)<% end %><% end %>
114
114
  <% if @pundit %>authorize @<%= singular %><% end %>
115
-
116
- if @<%= singular_name %>.save
115
+ <%= @code_before_create ? "\n " + @code_before_create.gsub(";", "\n") : "" %>
116
+ if @<%= singular_name %>.save<%= @code_after_create ? ("\n " + @code_after_create.gsub(";", "\n")) : ""%>
117
117
  flash[:notice] = "Successfully created #{@<%= singular %>.<%= display_class %>}"
118
118
  <%= post_action_parental_updates %>
119
119
  load_all_<%= plural %>
120
120
  render :create
121
121
  else
122
122
  flash[:alert] = "Oops, your <%= singular_name %> could not be created. #{@hawk_alarm}"
123
- @action = "new"
123
+ @action = 'new'
124
124
  render :create, status: :unprocessable_entity
125
125
  end<% if @pundit %>
126
- rescue Pundit::NotAuthorizedError
127
- flash[:alert] = "Creating <%= singular %> not authorized. #{@<%= singular %>.errors.collect{|k| "#{k.attribute} #{k.message}"}.join(" ")} #{flash[:notice]} "
128
- render :index <% end %>
126
+ rescue Pundit::NotAuthorizedError => e
127
+ @user.errors.add(:base, e.message)
128
+ render :create, status: :unprocessable_entity<% end %>
129
129
  end
130
130
 
131
131
  <% end %>
132
132
  <% unless @no_edit %>
133
133
  def show
134
+ <% if @pundit %>authorize @<%= singular %><% end %>
134
135
  redirect_to <%= HotGlue.optionalized_ternary(namespace: @namespace,
135
136
  target: @singular,
136
137
  nested_set: @nested_set,
137
- modifier: "edit_",
138
+ modifier: 'edit_',
138
139
  with_params: true,
139
140
  put_form: true).gsub("(#{singular}", "(@#{singular}") %>
140
141
  end
141
142
 
142
143
  def edit<% if @pundit %>
143
144
  authorize @<%= singular_name %><% end %>
144
- @action = "edit"
145
+ @action = 'edit'
145
146
  render :edit<% if @pundit %>
146
147
  rescue Pundit::NotAuthorizedError
147
148
  flash[:alert] = "Editing #{@<%= singular %>.<%= display_class %>} not authorized."
@@ -160,27 +161,29 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
160
161
 
161
162
  modified_params = modify_date_inputs_on_params(<% if @update_show_only %>update_<% end %><%= singular_name %>_params.dup<%= controller_update_params_tap_away_magic_buttons %>, <%= current_user_object %>, <%= datetime_fields_list %>) <% if @object_owner_sym && eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %>
162
163
  modified_params = modified_params.merge(<%= @object_owner_sym %>: <%= @object_owner_eval %>) <% elsif @object_owner_optional && any_nested? %>
163
- modified_params = modified_params.merge(<%= @object_owner_name %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {}) <% elsif ! @object_owner_eval.empty? && !@self_auth && ! @god%>
164
- modified_params = modified_params.merge(<%= @object_owner_eval %>) <% end %>
164
+ modified_params = modified_params.merge(<%= @object_owner_name %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {}) <% end %>
165
165
  <% if @pundit %><% @related_sets.each do |key, related_set| %>
166
166
  check_<%= related_set[:association_ids_method].to_s %>_permissions(modified_params, :update)<% end %><% end %>
167
167
 
168
168
  <% if @hawk_keys.any? %> modified_params = hawk_params({<%= hawk_to_ruby %>}, modified_params)<% end %>
169
- <%= controller_attachment_orig_filename_pickup_syntax %>
169
+ <%= controller_attachment_orig_filename_pickup_syntax %>
170
170
  <% if @pundit %>
171
171
  if @<%= singular_name %>.attributes = modified_params
172
172
  authorize @<%= singular_name %>
173
+ <%= @code_before_update ? "\n " + @code_before_update.gsub(";", "\n") : "" %>
173
174
  @<%= singular_name %>.save
174
175
  <% else %>
176
+ <%= @code_before_update ? "\n " + @code_before_update.gsub(";", "\n") : "" %>
175
177
  if @<%= singular_name %>.update(modified_params)
176
178
  <% end %>
179
+ <%= @code_after_update ? "\n " + @code_after_update.gsub(";", "\n") : "" %>
177
180
  <% if @display_list_after_update %> load_all_<%= plural %><% end %>
178
181
  flash[:notice] << "Saved #{@<%= singular %>.<%= display_class %>}"
179
182
  flash[:alert] = @hawk_alarm if @hawk_alarm
180
183
  render :update
181
184
  else
182
185
  flash[:alert] = "<%= singular_name.titlecase %> could not be saved. #{@hawk_alarm}"
183
- @action = "edit"
186
+ @action = 'edit'
184
187
  render :update, status: :unprocessable_entity
185
188
  end<% if @pundit %>
186
189
  rescue Pundit::NotAuthorizedError
@@ -204,23 +207,31 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
204
207
 
205
208
  <% if @pundit %><% @related_sets.each do |key, rs| %>
206
209
  def check_<%= rs[:association_ids_method] %>_permissions(modified_params, action)
207
- if modified_params[:<%= rs[:association_ids_method] %>].present? && modified_params[:<%= rs[:association_ids_method] %>] != @<%= singular %>.<%= rs[:association_ids_method] %>
208
- # authorize the <%= rs[:association_ids_method] %> change using special modified_relations: {<%= rs[:association_ids_method] %>: modified_params[:<%= rs[:association_ids_method] %>>]} syntax for Pundit
209
- if ! <%= singular_class %>Policy.new(current_user, @<%= singular %>, modified_relations: {role_ids: modified_params[:<%= rs[:association_ids_method] %>]}).method("#{action}?".to_sym).call
210
- authorize @<%= singular %>, "#{action}?".to_sym
211
- raise Pundit::NotAuthorizedError, message: @<%= singular %>.errors.collect{|k| "#{k.attribute} #{k.message}"}.join(" ")
212
- end
213
- end
210
+ # authorize the <%= rs[:association_ids_method] %> change using special modified_relations: {
211
+ # <%= rs[:association_ids_method] %>: modified_params[:<%= rs[:association_ids_method] %>>]} syntax for Pundit
212
+ modified_relations = { <%= rs[:association_ids_method] %>: modified_params[:<%= rs[:association_ids_method] %>] }
213
+ return unless modified_params[:<%= rs[:association_ids_method] %>].present?
214
+ policy_check = <%= singular_class %>Policy.new(current_user, @<%= singular %>,
215
+ modified_relations:).method("#{action}?".to_sym).call
216
+ return if policy_check
217
+ raise Pundit::NotAuthorizedError, message: @<%= singular %>.errors.collect{|k| "#{k.attribute} #{k.message}"}.join(" ")
214
218
  end<% end %><% end %>
215
219
 
216
220
  def <%=singular_name%>_params
217
221
  params.require(:<%= testing_name %>).permit(<%= ((fields_filtered_for_strong_params - @show_only ) + @magic_buttons.collect{|x| "__#{x}"}).collect{|sym| ":#{sym}"}.join(", ") %><%= ", " + @related_sets.collect{|key, rs| "#{rs[:association_ids_method]}: []"}.join(", ") if @related_sets.any? %>)
218
222
  end<% if @update_show_only %>
219
223
 
224
+ <% unless @no_edit %>
220
225
  def update_<%=singular_name%>_params
221
226
  params.require(:<%= testing_name %>).permit(<%= ((fields_filtered_for_strong_params - @update_show_only) + @magic_buttons.collect{|x| "__#{x}"}).collect{|sym| ":#{sym}"}.join(", ") %><%= ", " + @related_sets.collect{|key, rs| "#{rs[:association_ids_method]}: []"}.join(", ") if @related_sets.any? %>)
222
227
  end<% end %>
228
+ <% end %>
223
229
 
230
+ <% if @search %>
231
+ def search_params
232
+ params.permit(:q, :page)
233
+ end
234
+ <% end %>
224
235
  def namespace
225
236
  <% if @namespace %>'<%= @namespace %>/'<% else %><% end %>
226
237
  end
@@ -5,7 +5,9 @@
5
5
  <\% end %>
6
6
  <h2>Editing <\%= <%= singular %>.<%= display_class %> %></h2>
7
7
  <\%= form_with model: <%= singular %>, url: <%= form_path_edit_helper %> do |f| %>
8
- <\%= render partial: "<%= namespace_with_trailing_dash + @controller_build_folder + "/" %>form", locals: {:<%= singular %> => <%= singular %>, f: f}<%= @nested_set.collect{|arg| ".merge(#{arg[:singular]} ? {#{arg[:singular]}: #{arg[:singular]}} : {})" }.join %> \%>
8
+ <\%= render partial: "<%= namespace_with_trailing_dash + @controller_build_folder + "/" %>form", locals: {:<%= singular %> => <%= singular %>, f: f}<%= @nested_set.collect{|arg| ".merge(#{arg[:singular]} ? {#{arg[:singular]}: #{arg[:singular]}} : {})" }.join %> \%>
9
+ <% if @edit_within_form_partial %><\%= render partial: "edit_within_form", locals: {f: f, <%= singular %>: <%= singular %>}<%= @nested_set.collect{|arg| ".merge(#{arg[:singular]} ? {#{arg[:singular]}: #{arg[:singular]}} : {})" }.join %> %><% end %>
9
10
  <\% end %>
11
+ <% if @edit_within_form_partial %><\%= render partial: "edit_after_form", locals: {<%= singular %>: <%= singular %>}<%= @nested_set.collect{|arg| ".merge(#{arg[:singular]} ? {#{arg[:singular]}: #{arg[:singular]}} : {})" }.join %> %><% end %>
10
12
  </div>
11
13
  <\% end %>
@@ -1,4 +1,5 @@
1
1
  <\%= turbo_frame_tag "<%= @namespace %>__<%= plural %>-list" <%= nested_for_turbo_id_list_constructor %> do %>
2
+
2
3
  <div class="<%= @container_name %> <%= @layout_strategy.list_classes %>">
3
4
  <% unless @no_list || @no_list_label || (@nested_set.any? && !@nested_set.collect{|x| x[:optional]}.any?) %>
4
5
  <% unless list_label.nil? %><h4>
@@ -40,6 +41,10 @@
40
41
  </div>
41
42
  <% end %>
42
43
 
44
+ <% if @search %>
45
+ <%= @template_builder.search_input_area %>
46
+ <% end %>
47
+
43
48
  <\% if <%= plural %>.empty? %>
44
49
  <div>
45
50
  None
@@ -5,5 +5,8 @@
5
5
  <\%= form_with model: <%= singular %>, url: <%= form_path_new_helper %>, method: :post do |f| \%>
6
6
  <\%= render partial: "<%= namespace_with_slash + @controller_build_folder %>/form",
7
7
  locals: { <%= singular %>: <%= singular %>, f: f}<%= @nested_set.collect{|arg| ".merge(defined?(#{arg[:singular]}) ? {#{arg[:singular]}: #{arg[:singular]}}: {})" }.join %> \%>
8
- <\% end %>
8
+
9
+ <% if @new_within_form_partial %><\%= render partial: "new_within_form", locals: {f: f, <%= singular %>: <%= singular %>}<%= @nested_set.collect{|arg| ".merge(#{arg[:singular]} ? {#{arg[:singular]}: #{arg[:singular]}} : {})" }.join %> %><% end %>
10
+ <\% end %>
11
+ <% if @new_after_form_partial %><\%= render partial: "new_after_form", locals: {<%= singular %>: <%= singular %>}<%= @nested_set.collect{|arg| ".merge(#{arg[:singular]} ? {#{arg[:singular]}: #{arg[:singular]}} : {})" }.join %> %><% end %>
9
12
  <\% end %>
@@ -0,0 +1,45 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ // Connects to data-controller="date-range-picker"
4
+ export default class extends Controller {
5
+
6
+ static targets = [ "matchSelector", "start", "end" ];
7
+ connect() {
8
+
9
+ console.log("date_range_picker_controller.js connect.....")
10
+ }
11
+
12
+ matchSelection(event) {
13
+
14
+ console.log("date_range_picker_controller.js matchSelection.....")
15
+ console.log(event.target.value)
16
+ // this.matchSelectorTarget.value = event.target.value
17
+
18
+ switch(event.target.value) {
19
+ case "is_on":
20
+ this.startTarget.disabled = false
21
+ this.endTarget.disabled = true
22
+ this.endTarget.value = ""
23
+ break;
24
+ case "is_between":
25
+ this.startTarget.disabled = false
26
+ this.endTarget.disabled = false
27
+ break;
28
+ case "is_on_or_after":
29
+ this.startTarget.disabled = false
30
+ this.endTarget.disabled = true
31
+ this.endTarget.value = ""
32
+ break;
33
+ case "is_before_or_on":
34
+ this.startTarget.disabled = true
35
+ this.startTarget.value = ""
36
+ this.endTarget.disabled = false
37
+ break;
38
+ case "not_on":
39
+ this.startTarget.disabled = false
40
+ this.endTarget.disabled = true
41
+ this.endTarget.value = ""
42
+ break;
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,16 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ // Connects to data-controller="search_form"
4
+ export default class extends Controller {
5
+ static targets = ["clearButton"];
6
+
7
+ connect() {
8
+
9
+ if (this.hasClearButtonTarget) {
10
+ this.clearButtonTarget.addEventListener("click", (event) => {
11
+ event.preventDefault()
12
+ this.element.reset()
13
+ })
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,38 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ // Connects to data-controller="time-range-picker"
4
+ export default class extends Controller {
5
+ static targets = [ "matchSelector", "start", "end" ];
6
+ connect() {
7
+ console.log("time_range_picker_controller.js connect.....")
8
+ }
9
+
10
+ matchSelection(event) {
11
+
12
+ console.log("time_range_picker_controller.js matchSelection.....")
13
+ console.log(event.target.value)
14
+ // this.matchSelectorTarget.value = event.target.value
15
+
16
+ switch(event.target.value) {
17
+ case "is_at":
18
+ this.startTarget.disabled = false
19
+ this.endTarget.disabled = true
20
+ this.endTarget.value = ""
21
+ break;
22
+ case "is_between":
23
+ this.startTarget.disabled = false
24
+ this.endTarget.disabled = false
25
+ break;
26
+ case "is_at_or_after":
27
+ this.startTarget.disabled = false
28
+ this.endTarget.disabled = true
29
+ this.endTarget.value = ""
30
+ break;
31
+ case "is_before_or_at":
32
+ this.startTarget.disabled = true
33
+ this.startTarget.value = ""
34
+ this.endTarget.disabled = false
35
+ break;
36
+ }
37
+ }
38
+ }
@@ -5,6 +5,7 @@ class <%= ((@namespace.titleize.gsub(" ", "") + "::" if @namespace) || "") + @pl
5
5
  # rubocop:enable Layout/LineLength <% end %>
6
6
 
7
7
  def index
8
+ <% if @pundit %>authorize <%= @class_name %>, :typeahead? <% end %>
8
9
  query = params[:query]
9
10
  @typeahead_identifier = params[:typeahead_identifier]
10
11
  @<%= @plural %> = <%= @singular.titleize.gsub(" ", "") %>.where("<%= @search_by.collect{|search| "LOWER(#{search}) LIKE ?" }.join(" OR ") %>", <%= @search_by.collect{|search| "\"%\#{query.downcase}%\"" }.join(", ") %>).limit(10)
@@ -1,9 +1,12 @@
1
+ require_relative './default_config_loader'
2
+
1
3
  module HotGlue
2
4
  class TypeaheadGenerator < Rails::Generators::Base
3
5
  source_root File.expand_path('templates', __dir__)
4
6
  class_option :namespace, type: :string, default: nil
5
7
  class_option :search_by, type: :string, default: nil
6
8
 
9
+ include DefaultConfigLoader
7
10
  def filepath_prefix
8
11
  # todo: inject the context
9
12
  'spec/dummy/' if $INTERNAL_SPECS
@@ -19,9 +22,10 @@ module HotGlue
19
22
  puts message
20
23
  raise(HotGlue::Error, message)
21
24
  end
25
+ @pundit = get_default_from_config(key: :pundit_default)
22
26
 
23
27
  @singular = args.first.tableize.singularize
24
-
28
+ @class_name = args.first
25
29
  @plural = args.first.tableize.pluralize
26
30
  @namespace = options['namespace']
27
31
 
@@ -1,5 +1,5 @@
1
1
  module HotGlue
2
2
  class Version
3
- CURRENT = '0.6.1'
3
+ CURRENT = '0.6.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hot-glue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Fleetwood-Boldt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-21 00:00:00.000000000 Z
11
+ date: 2024-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '2.16'
55
55
  description: Simple, plug & play Rails scaffold building companion for Turbo-Rails
56
56
  and Hotwire
57
- email: code@jasonfb.net
57
+ email: hello@jfbcodes.com
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
@@ -107,6 +107,7 @@ files:
107
107
  - lib/generators/hot_glue/markup_templates/erb.rb
108
108
  - lib/generators/hot_glue/nav_template_generator.rb
109
109
  - lib/generators/hot_glue/scaffold_generator.rb
110
+ - lib/generators/hot_glue/set_search_interface_install_generator.rb
110
111
  - lib/generators/hot_glue/templates/base_controller.rb.erb
111
112
  - lib/generators/hot_glue/templates/capybara_login.rb
112
113
  - lib/generators/hot_glue/templates/computer_code.jpg
@@ -127,7 +128,10 @@ files:
127
128
  - lib/generators/hot_glue/templates/erb/index.erb
128
129
  - lib/generators/hot_glue/templates/erb/new.erb
129
130
  - lib/generators/hot_glue/templates/erb/update.turbo_stream.erb
131
+ - lib/generators/hot_glue/templates/javascript/date_range_picker_controller.js
130
132
  - lib/generators/hot_glue/templates/javascript/dropzone_controller.js
133
+ - lib/generators/hot_glue/templates/javascript/search_form_controller.js
134
+ - lib/generators/hot_glue/templates/javascript/time_range_picker_controller.js
131
135
  - lib/generators/hot_glue/templates/system_spec.rb.erb
132
136
  - lib/generators/hot_glue/templates/themes/hotglue_scaffold_dark_knight.scss
133
137
  - lib/generators/hot_glue/templates/themes/hotglue_scaffold_like_bootstrap.scss