Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jfb/2025 01 04 removing optionalization #184

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions lib/generators/hot_glue/scaffold_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
class_option :code_after_update, default: nil
class_option :record_scope, default: nil
class_option :no_nav_menu, type: :boolean, default: false # suppress writing to _nav template

class_option :new_button_position, type: :string, default: 'above'
class_option :downnest_shows_headings, type: :boolean, default: nil


# SEARCH OPTIONS
Expand Down Expand Up @@ -337,6 +338,9 @@ def initialize(*meta_args)

@smart_layout = options['smart_layout']
@record_scope = options['record_scope']
@downnest_shows_headings = options['downnest_shows_headings']
@new_button_position = options['new_button_position']


@pundit = options['pundit']

Expand Down Expand Up @@ -463,6 +467,7 @@ def initialize(*meta_args)
identify_object_owner
setup_fields


if (@columns - @show_only - (@ownership_field ? [@ownership_field.to_sym] : [])).empty?
@no_field_form = true
end
Expand Down Expand Up @@ -1069,15 +1074,15 @@ def form_path_new_helper
HotGlue.optionalized_ternary(namespace: @namespace,
target: @controller_build_folder,
nested_set: @nested_set,
with_params: true,
with_params: false,
top_level: false)
end

def form_path_edit_helper
HotGlue.optionalized_ternary(namespace: @namespace,
target: @singular,
nested_set: @nested_set,
with_params: true,
with_params: false,
put_form: true,
top_level: false)
end
Expand All @@ -1086,7 +1091,7 @@ def delete_path_helper
HotGlue.optionalized_ternary(namespace: @namespace,
target: @singular,
nested_set: @nested_set,
with_params: true,
with_params: false,
put_form: true)
end

Expand All @@ -1095,7 +1100,7 @@ def edit_path_helper
target: @singular,
nested_set: @nested_set,
modifier: "edit_",
with_params: true,
with_params: false,
put_form: true)
end

Expand Down Expand Up @@ -1124,7 +1129,7 @@ def new_path_name
target: singular,
nested_set: @nested_set,
modifier: "new_",
with_params: true)
with_params: false)
end

def nested_assignments
Expand Down Expand Up @@ -1222,7 +1227,7 @@ def magic_button_output
path: HotGlue.optionalized_ternary( namespace: @namespace,
target: @singular,
nested_set: @nested_set,
with_params: true,
with_params: false,
put_form: true),
big_edit: @big_edit,
singular: singular,
Expand Down
7 changes: 7 additions & 0 deletions lib/generators/hot_glue/templates/erb/_list.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
</h4><% end %>
<% end %>

<% if @new_button_position == 'above' %>
<% unless @no_create %><%= '<%= render partial: "' + ((@namespace+"/" if @namespace) || "") + @controller_build_folder + '/new_button", locals: {}' + @nested_set.collect{|arg| ".merge(defined?(#{arg[:singular]}) ? {#{arg[:singular]}: #{arg[:singular]}} : {})"}.join() + ' %\>'.gsub('\\',"") %><br /><% end %>
<% end %>

<% unless @no_list %>
<% unless @no_list_heading %>
Expand Down Expand Up @@ -66,5 +68,10 @@
<% end %>
<%= @no_paginate ? "" : paginate %>
<% end %>


<% if @new_button_position == 'below' %>
<% unless @no_create %><%= '<%= render partial: "' + ((@namespace+"/" if @namespace) || "") + @controller_build_folder + '/new_button", locals: {}' + @nested_set.collect{|arg| ".merge(defined?(#{arg[:singular]}) ? {#{arg[:singular]}: #{arg[:singular]}} : {})"}.join() + ' %\>'.gsub('\\',"") %><br /><% end %>
<% end %>
</div>
<\% end %>
7 changes: 6 additions & 1 deletion lib/generators/hot_glue/templates/erb/_show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
<% downnest_object_name = eval("#{downnest_class}.table_name") %>
<% downnest_style = @layout_strategy.downnest_style %>
<% if !@stacked_downnesting %><div class="<%= @layout_strategy.downnest_portal_column_width(downnest) %> scaffold-downnest" <%= downnest_style %> ><% end %>
<\%= render partial: "<%= namespace_with_trailing_dash %><%= downnest_object_name %>/list", locals: {
<% if @downnest_shows_headings %>
<h3>
<%= downnest_object_name.pluralize.humanize %>
</h3>
<% end %>
<\%= render partial: "<%= namespace_with_trailing_dash %><%= downnest_object_name %>/list", locals: {
<%= @singular %>: <%= @singular %>,
<%= downnest_object_name %>: <%= @singular %>.<%= downnest %>
}
Expand Down
6 changes: 5 additions & 1 deletion lib/generators/hot_glue/templates/erb/edit.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
<% downnest_class = downnest_object.class_name %>
<% downnest_object_name = eval("#{downnest_class}.table_name") %>
<% downnest_style = @layout_strategy.downnest_style %>

<% if @downnest_shows_headings %>
<h3>
<%= downnest_class.humanize %>
</h3>
<% end %>
<\%= render partial: "<%= namespace_with_trailing_dash %><%= downnest_object_name %>/list", locals: {<%= @singular %>: @<%= @singular %>, <%= downnest_object_name %>: @<%= @singular %>.<%= downnest %><% if @nested_set.any? %>, <%= @nested_set.collect{|x| "#{x[:singular]}: @#{x[:singular]}"}.join(", ") %>, nested_for: "<%= @nested_set.collect{|x| "#{x[:singular]}-" + "\#{" + "@#{x[:singular]}.id}"}.join("__") %>__<%= singular %>-#{@<%= @singular %>.id}" <% end %> } \%>

</div>
Expand Down
Loading