From 44ac659754a03aebd98aea563f7c138515441de2 Mon Sep 17 00:00:00 2001 From: Jason Fleetwood-Boldt Date: Tue, 28 Jan 2025 13:11:38 -0600 Subject: [PATCH] Jfb/2025 01 04 removing optionalization2 (#186) * removing optionalization * README --- README.md | 13 +++++++++++++ lib/generators/hot_glue/scaffold_generator.rb | 18 ++++++++++++------ .../hot_glue/templates/erb/_list.erb | 7 +++++++ .../hot_glue/templates/erb/_show.erb | 7 ++++++- lib/generators/hot_glue/templates/erb/edit.erb | 6 +++++- 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1a41b9d9..b8458351 100644 --- a/README.md +++ b/README.md @@ -987,6 +987,13 @@ Omits controller. Omits list views. +`--new-button-position` (above, below; default: above) +Show the new button above or below the list. + +`--downnest-shows-headings` (default: false) +Show headings above downnested portals. + + ### `--big-edit` If you do not want inline editing of your list items but instead want to fallback to full-page style behavior for your edit views, use `--big-edit`. @@ -1771,6 +1778,12 @@ e.g. "Editing author Edgar Allan Poe" vs "Editing Edgar Allan Poe" Can also be specified globally in `config/hot_glue.yml` +`--new-button-position` (above, below; default: above) +Show the new button above or below the list. + +`--downnest-shows-headings` (default: false) +Show headings above downnested portals. + #### 2024-12-25 v0.6.10 • adds `--no-nav-menu` option to supress writing to the _nav template diff --git a/lib/generators/hot_glue/scaffold_generator.rb b/lib/generators/hot_glue/scaffold_generator.rb index 2ce85f7a..a391c07a 100644 --- a/lib/generators/hot_glue/scaffold_generator.rb +++ b/lib/generators/hot_glue/scaffold_generator.rb @@ -99,6 +99,8 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator class_option :record_scope, default: nil class_option :no_nav_menu, type: :boolean, default: false # suppress writing to _nav template class_option :include_object_names, type: :boolean, default: false + class_option :new_button_position, type: :string, default: 'above' + class_option :downnest_shows_headings, type: :boolean, default: nil # SEARCH OPTIONS @@ -338,6 +340,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'] @@ -468,6 +473,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 @@ -1074,7 +1080,7 @@ 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 @@ -1082,7 +1088,7 @@ 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 @@ -1091,7 +1097,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 @@ -1100,7 +1106,7 @@ def edit_path_helper target: @singular, nested_set: @nested_set, modifier: "edit_", - with_params: true, + with_params: false, put_form: true) end @@ -1129,7 +1135,7 @@ def new_path_name target: singular, nested_set: @nested_set, modifier: "new_", - with_params: true) + with_params: false) end def nested_assignments @@ -1227,7 +1233,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, diff --git a/lib/generators/hot_glue/templates/erb/_list.erb b/lib/generators/hot_glue/templates/erb/_list.erb index 3c99039e..1d55d258 100644 --- a/lib/generators/hot_glue/templates/erb/_list.erb +++ b/lib/generators/hot_glue/templates/erb/_list.erb @@ -7,7 +7,9 @@ <% 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('\\',"") %>
<% end %> + <% end %> <% unless @no_list %> <% unless @no_list_heading %> @@ -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('\\',"") %>
<% end %> + <% end %> <\% end %> diff --git a/lib/generators/hot_glue/templates/erb/_show.erb b/lib/generators/hot_glue/templates/erb/_show.erb index 1bd1b425..0155dc30 100644 --- a/lib/generators/hot_glue/templates/erb/_show.erb +++ b/lib/generators/hot_glue/templates/erb/_show.erb @@ -12,7 +12,12 @@ <% downnest_object_name = eval("#{downnest_class}.table_name") %> <% downnest_style = @layout_strategy.downnest_style %> <% if !@stacked_downnesting %>
><% end %> - <\%= render partial: "<%= namespace_with_trailing_dash %><%= downnest_object_name %>/list", locals: { + <% if @downnest_shows_headings %> +

+ <%= downnest_object_name.pluralize.humanize %> +

+ <% end %> + <\%= render partial: "<%= namespace_with_trailing_dash %><%= downnest_object_name %>/list", locals: { <%= @singular %>: <%= @singular %>, <%= downnest_object_name %>: <%= @singular %>.<%= downnest %> } diff --git a/lib/generators/hot_glue/templates/erb/edit.erb b/lib/generators/hot_glue/templates/erb/edit.erb index 7b383a78..ede564c8 100644 --- a/lib/generators/hot_glue/templates/erb/edit.erb +++ b/lib/generators/hot_glue/templates/erb/edit.erb @@ -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 %> +

+ <%= downnest_class.humanize %> +

+ <% 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 %> } \%>