hot-glue 0.4.9.2 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  def login_as(user)
2
2
  visit '/users/sign_in'
3
- within("#new_account") do
3
+ within("#new_user") do
4
4
  fill_in 'Email', with: user.email
5
5
  fill_in 'Password', with: 'password'
6
6
  end
@@ -2,7 +2,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
2
2
  helper :hot_glue
3
3
  include HotGlue::ControllerHelper
4
4
 
5
- <% unless @auth_identifier == '' || @god %>before_action :authenticate_<%= @auth_identifier %>!<% end %>
5
+ <% unless @auth_identifier == '' || @god %>before_action :<%= auth_root %><% end %>
6
6
  <% if any_nested? %><% nest_chain = [] %> <% @nested_set.each { |arg|
7
7
 
8
8
  if auth_identifier == arg[:singular]
@@ -19,7 +19,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
19
19
  <% } %><% end %>
20
20
  before_action :load_<%= singular_name %>, only: [:show, :edit, :update, :destroy]
21
21
  after_action -> { flash.discard }, if: -> { request.format.symbol == :turbo_stream }
22
- <% if @nested_args.any? %>
22
+ <% if @nested_set.any? %>
23
23
  def <%= @nested_set[0][:singular] %><% if @god
24
24
  next_object = nil
25
25
  collect_objects = @nested_set.reverse.collect {|x|
@@ -36,9 +36,9 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
36
36
  root_object = @auth + "." + @nested_set[0][:plural]
37
37
  end
38
38
  end
39
- %><% if !@god && @nested_set[0][:singular] == @auth_identifier %>
40
- @<%= @nested_set[0][:singular] %> ||= <%= root_object %> <% else %>
41
- @<%= @nested_set[0][:singular] %> ||= <%= root_object %>.find(params[:<%= @nested_set[0][:singular] %>_id])<%= " if params.include?(:#{@nested_set[0][:singular]}_id)" if @nested_set[0][:optional] %> <% end %>
39
+ %>
40
+ <% if !@god && @nested_set[0][:singular] == @auth_identifier %>@<%= @nested_set[0][:singular] %> ||= <%= root_object %>
41
+ <% else %> @<%= @nested_set[0][:singular] %> ||= <%= root_object %>.find(params[:<%= @nested_set[0][:singular] %>_id])<%= " if params.include?(:#{@nested_set[0][:singular]}_id)" if @nested_set[0][:optional] %> <% end %>
42
42
  end
43
43
  <% end %><% if any_nested? %><% nest_chain = [@nested_set[0][:singular]]; this_scope = @nested_set[0][:plural]; %>
44
44
  <% for index in 0..(@nested_set.count - 1) do
@@ -47,11 +47,12 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
47
47
 
48
48
  this_scope = "#{nest_chain.last}.#{arg[:plural]}"
49
49
  nest_chain << arg %>
50
+ <% unless @nested_set[0][:singular] == arg[:singular] %>
50
51
  def <%= arg[:singular] %>
51
52
  @<%= arg[:singular] %> ||= (<%= this_scope %>.find(params[:<%= arg[:singular] %>_id])<%= " if params.include?(:#{last_arg[:singular]}_id)" if last_arg && @god && last_arg[:optional] %>)
52
- <% if @god && (last_arg[:optional] ) %>@<%= arg[:singular] %> ||= (<%= collect_objects[index-1] %>.find(params[:<%= arg[:singular] %>_id]) if params.include?(:<%= arg[:singular] %>_id) ) <% end %>
53
- end<% end %> <% end %> <% if !@self_auth %>
54
-
53
+ <% if @god && last_arg && (last_arg[:optional] ) %>@<%= arg[:singular] %> ||= (<%= collect_objects[index-1] %>.find(params[:<%= arg[:singular] %>_id]) if params.include?(:<%= arg[:singular] %>_id) ) <% end %>
54
+ end<% end %>
55
+ <% end %><% end %> <% if !@self_auth %>
55
56
  def load_<%= singular_name %>
56
57
  @<%= singular_name %> = (<%= object_scope.gsub("@",'') %>.find(params[:id])<%= " if params.include?(:#{@nested_set.last[:singular]}_id)" if @nested_set[0] && @nested_set[0][:optional] %>)<% if @nested_set[0] && @nested_set[0][:optional] %> || <%= class_name %>.find(params[:id])<% end %>
57
58
  end
@@ -73,8 +74,9 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
73
74
  end
74
75
 
75
76
  <% if create_action %> def new
76
- <% if ! @god %>
77
- @<%= singular_name %> = <%= class_name %>.new(<%= @object_owner_sym %>: <%= @object_owner_eval %>)
77
+ <% if @object_owner_sym %>
78
+ @<%= singular_name %> = <%= class_name %>.new(<% if eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %><%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>)
79
+
78
80
  <% elsif @object_owner_optional && any_nested? %>
79
81
  @<%= singular_name %> = <%= class_name %>.new({}.merge(<%= @nested_set.last[:singular] %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {})) <% else %>
80
82
  @<%= singular_name %> = <%= class_name %>.new(<% if any_nested? %><%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>)
@@ -85,8 +87,8 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
85
87
  end
86
88
 
87
89
  def create
88
- modified_params = modify_date_inputs_on_params(<%= singular_name %>_params.dup<% if ! @object_owner_sym.empty? %>.merge!(<% if @object_owner_optional && any_nested? %><%= @object_owner_name %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {} <% else %> <%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>) <% end %>)
89
-
90
+ modified_params = modify_date_inputs_on_params(<%= singular_name %>_params.dup<% if @object_owner_sym && eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %>.merge!(<% if @object_owner_optional && any_nested? %><%= @object_owner_name %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {} <% else %> <%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>) <% end %>)
91
+ <% if @hawk_keys.any? %> modified_params = hawk_params( {<%= hawk_to_ruby %>}, modified_params)<% end %>
90
92
 
91
93
  @<%=singular_name %> = <%= class_name %>.create(modified_params)
92
94
 
@@ -98,7 +100,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
98
100
  format.html { redirect_to <%= path_helper_plural %> }
99
101
  end
100
102
  else
101
- flash[:alert] = "Oops, your <%= singular_name %> could not be created."
103
+ flash[:alert] = "Oops, your <%= singular_name %> could not be created. #{@hawk_alarm}"
102
104
  respond_to do |format|
103
105
  format.turbo_stream
104
106
  format.html
@@ -120,10 +122,13 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
120
122
  end
121
123
 
122
124
  <% end %><% if @build_update_action %> def update
123
- <%= controller_magic_button_update_actions %> if @<%= singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params<%= @auth ? ', ' + @auth : '' %>)<%= controller_update_params_tap_away_magic_buttons %>)
125
+ modified_params = modify_date_inputs_on_params(<%= singular %>_params<%= @auth ? ', ' + @auth : '' %>)<%= controller_update_params_tap_away_magic_buttons %>
126
+ <% if @hawk_keys.any? %> modified_params = hawk_params( {<%= hawk_to_ruby %>}, modified_params)<% end %>
127
+ <%= controller_magic_button_update_actions %> if @<%= singular_name %>.update(modified_params)
124
128
  flash[:notice] = (flash[:notice] || "") << "Saved #{@<%= singular %>.<%= display_class %>}"
129
+ flash[:alert] = @hawk_alarm if !@hawk_alarm.empty?
125
130
  else
126
- flash[:alert] = (flash[:alert] || "") << "<%= singular_name.titlecase %> could not be saved."
131
+ flash[:alert] = (flash[:alert] || "") << "<%= singular_name.titlecase %> could not be saved. #{@hawk_alarm}"
127
132
 
128
133
  end
129
134
  <% if @display_list_after_update %> load_all_<%= plural %><% end %>
@@ -137,7 +142,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
137
142
  begin
138
143
  @<%=singular_name%>.destroy
139
144
  rescue StandardError => e
140
- flash[:alert] = "<%= singular_name.titlecase %> could not be deleted"
145
+ flash[:alert] = "<%= singular_name.titlecase %> could not be deleted."
141
146
  end
142
147
  load_all_<%= plural %>
143
148
  respond_to do |format|
@@ -147,11 +152,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
147
152
  end<% end %>
148
153
 
149
154
  def <%=singular_name%>_params
150
- params.require(:<%=singular_name%>).permit( <%= @columns + @magic_buttons.collect(&:to_sym) %> )
151
- end
152
-
153
- def default_colspan
154
- <%= @default_colspan %>
155
+ params.require(:<%=singular_name%>).permit( <%= (@columns - @show_only) + @magic_buttons.collect(&:to_sym) %> )
155
156
  end
156
157
 
157
158
  def namespace
@@ -1,5 +1,5 @@
1
1
  <\%= turbo_frame_tag "<%= singular %>-new" do %>
2
2
  <div>
3
- <\%= link_to "New <%= thing_label %>", <%= new_path_name %>, disable_with: "Loading...", class: "new-<%= singular %>-button btn btn-primary pull-right <%= 'btn-sm' if @nested_args.any? %> " %>
3
+ <\%= link_to "New <%= thing_label %>", <%= new_path_name %>, disable_with: "Loading...", class: "new-<%= singular %>-button btn btn-primary pull-right <%= 'btn-sm' if @nested_set.any? %> " %>
4
4
  </div>
5
5
  <\% end %>
@@ -15,7 +15,7 @@
15
15
  <%= @singular %>: <%= @singular %>,
16
16
  <%= downnest_object_name %>: <%= @singular %>.<%= downnest %>
17
17
  }
18
- .merge({nested_for: "<% if @nested_args.any? %>#{nested_for + "__" if defined?(nested_for)}<% end %><%= @singular %>-#{<%= @singular %>.id}"})
18
+ .merge({nested_for: "<% if @nested_set.any? %>#{nested_for + "__" if defined?(nested_for)}<% end %><%= @singular %>-#{<%= @singular %>.id}"})
19
19
  <%= @nested_set.collect{|arg| ".merge(defined?(#{arg[:singular]}) ? {#{arg[:singular]}: #{arg[:singular]}} : {} )"}.join("\n") %>
20
20
  \%>
21
21
  </div>
@@ -10,7 +10,7 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
10
10
  when :integer
11
11
  if col.to_s.ends_with?("_id")
12
12
  assoc = "#{col.to_s.gsub('_id','')}"
13
- "let!(:#{assoc}1) {create(:#{assoc})}"
13
+ "let!(:#{assoc}1) {create(:#{assoc}" + (@hawk_keys["#{assoc}_id".to_sym] ? ", #{@auth.gsub('current_', '')}: #{@auth}": "") + ")}"
14
14
  end
15
15
  else
16
16
  end
@@ -1,5 +1,5 @@
1
1
  module HotGlue
2
2
  class Version
3
- CURRENT = '0.4.9.2'
3
+ CURRENT = '0.5.2'
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.4.9.2
4
+ version: 0.5.2
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: 2022-02-28 00:00:00.000000000 Z
11
+ date: 2022-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -85,7 +85,6 @@ files:
85
85
  - lib/generators/hot_glue/scaffold_generator.rb
86
86
  - lib/generators/hot_glue/templates/base_controller.rb.erb
87
87
  - lib/generators/hot_glue/templates/capybara_login.rb
88
- - lib/generators/hot_glue/templates/confirmable.js
89
88
  - lib/generators/hot_glue/templates/controller.rb.erb
90
89
  - lib/generators/hot_glue/templates/erb/_errors.erb
91
90
  - lib/generators/hot_glue/templates/erb/_flash_notices.erb
@@ -1,14 +0,0 @@
1
- import { Controller } from "@hotwired/stimulus"
2
-
3
- console.log("defining Confirmable....")
4
- export default class extends Controller {
5
- static values = { message: String }
6
-
7
- confirm(event) {
8
-
9
- if(!window.confirm(this.message)) {
10
- event.preventDefault();
11
- event.stopPropagation()
12
- }
13
- }
14
- }