Class: Hibiki::Rails::Generators::NestedGenerator
Overview
One parent→child edge of a nested form, onto a resource
hibiki:rails:scaffold_controller already generated: the child's
ReactiveForm and fields partial (path-addressed inputs riding the
generic Hibiki::Rails::NestedActions), reactive_nested on the parent
form, the model wiring, the classic fields_for fallback in the
full-page form, and the controller's params.expect double-array group.
A missing child model is created from the field list (model +
migration via active_record:model, the parent reference prepended).
Depth is composition — run once per edge. A run whose parent is
itself a nested child injects into the parent's own fields partial
instead of the row form, and nests every other wiring one level
deeper.
Constant Summary
Hibiki::Rails::Generators::NestedInjections::CHANNEL_ANCHOR, Hibiki::Rails::Generators::NestedInjections::ERB_FIELDSET_CLOSE, Hibiki::Rails::Generators::NestedInjections::ERB_FIELDS_CLOSE, Hibiki::Rails::Generators::NestedInjections::ERB_SUBMIT_DIV, Hibiki::Rails::Generators::NestedInjections::FILE_END, Hibiki::Rails::Generators::NestedInjections::FORM_ANCHOR, Hibiki::Rails::Generators::NestedInjections::PHLEX_CONTROLS_CALL, Hibiki::Rails::Generators::NestedInjections::PHLEX_CONTROLS_DEF, Hibiki::Rails::Generators::NestedInjections::PHLEX_FORM_ACTIONS_CALL, Hibiki::Rails::Generators::NestedInjections::PHLEX_FORM_ACTIONS_DEF, Hibiki::Rails::Generators::NestedInjections::PHLEX_PAGE_FIELDS_CALL, Hibiki::Rails::Generators::NestedInjections::REMAINING_ANCHOR, Hibiki::Rails::Generators::NestedInjections::URL_PARAMS_ANCHOR
ScaffoldPhlexHelpers::HELPER_MODULES, ScaffoldPhlexHelpers::PHLEX_BASE, ScaffoldPhlexHelpers::PHLEX_INITIALIZER, ScaffoldPhlexHelpers::PHLEX_NAMESPACE, ScaffoldPhlexHelpers::PLAIN_TYPES
ScaffoldViewHelpers::FIELD_TOKENS
GeneratorHelpers::APPLICATION_HELPER, GeneratorHelpers::IMPORTMAP, GeneratorHelpers::INDEX_JS, GeneratorHelpers::REGISTER_FRAGMENT, GeneratorHelpers::SHIM
Instance Method Summary
collapse
Instance Method Details
75
76
77
|
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 75
def create_child_form
template "child_form.rb.tt", child_form_path
end
|
#create_child_model ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 67
def create_child_model
return unless create_child?
invoke "active_record:model", child_model_argv
end
|
#create_fields_view ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 79
def create_fields_view
if phlex?
template "fields_component.rb.tt", fields_view_target
else
template "_fields.html.erb.tt", fields_view_target
end
end
|
#create_position_migration ⇒ Object
87
88
89
90
91
92
|
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 87
def create_position_migration
return unless (@position_migration = position_migration_needed?)
migration_template "position_migration.rb.tt",
"db/migrate/add_#{position_column}_to_#{child_table_name}.rb"
end
|
#post_install ⇒ Object
123
124
125
126
127
128
129
130
|
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 123
def post_install
migrate_notice
schema.belongs_tos.each do |column|
say_status :assoc, "using #{column.association_class_name}##{column.label_column} as " \
"the #{column.human_name.downcase} option label — edit " \
"@#{column.options_local} in #{resource_channel_path} if that's wrong", :blue
end
end
|
#preflight ⇒ Object
Everything that can refuse, before anything is written.
62
63
64
65
|
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 62
def preflight
check_wireable!
warn_without_phlex_rails
end
|
#wire_channel ⇒ Object
BEFORE the fieldset injection: the threading guards probe for each
options local's name, and the injected render line would satisfy
them vacuously.
105
106
107
108
109
|
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 105
def wire_channel
inject_channel_include
inject_edit_preload
inject_option_collections
end
|
#wire_controller ⇒ Object
119
120
121
|
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 119
def wire_controller
inject_permitted_params
end
|
98
99
100
|
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 98
def wire_form
inject_form_nested
end
|
#wire_model ⇒ Object
94
95
96
|
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 94
def wire_model
inject_parent_model
end
|
#wire_page_form ⇒ Object
115
116
117
|
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 115
def wire_page_form
inject_page_form
end
|
#wire_views ⇒ Object
111
112
113
|
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 111
def wire_views
inject_container_fieldset
end
|