Skip to content

Commit

Permalink
Jfb/2025 01 04 removing optionalization2 (#186)
Browse files Browse the repository at this point in the history
* removing optionalization

* README
  • Loading branch information
jasonfb authored Jan 28, 2025
1 parent f682b55 commit 44ac659
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions lib/generators/hot_glue/scaffold_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1074,15 +1080,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 @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
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

0 comments on commit 44ac659

Please sign in to comment.