Class: Hibiki::Rails::Generators::NestedGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
ActiveRecord::Generators::Migration, GeneratorHelpers, NestedHelpers, NestedInjections, ScaffoldHelpers, ScaffoldModelInjection, ScaffoldPhlexHelpers, ScaffoldViewHelpers, Rails::Generators::ResourceHelpers
Defined in:
lib/generators/hibiki/rails/nested/nested_generator.rb

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

Constants included from NestedInjections

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

Constants included from ScaffoldPhlexHelpers

ScaffoldPhlexHelpers::HELPER_MODULES, ScaffoldPhlexHelpers::PHLEX_BASE, ScaffoldPhlexHelpers::PHLEX_INITIALIZER, ScaffoldPhlexHelpers::PHLEX_NAMESPACE, ScaffoldPhlexHelpers::PLAIN_TYPES

Constants included from ScaffoldViewHelpers

ScaffoldViewHelpers::FIELD_TOKENS

Constants included from GeneratorHelpers

GeneratorHelpers::APPLICATION_HELPER, GeneratorHelpers::IMPORTMAP, GeneratorHelpers::INDEX_JS, GeneratorHelpers::REGISTER_FRAGMENT, GeneratorHelpers::SHIM

Instance Method Summary collapse

Instance Method Details

#create_child_formObject



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_modelObject



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?

  # to_argv, never GeneratedAttribute#to_s: `title:string!` round-trips
  # through to_s as "title:string{null}", which .parse then rejects.
  invoke "active_record:model", child_model_argv
end

#create_fields_viewObject



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_migrationObject



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_installObject



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

#preflightObject

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_channelObject

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_controllerObject



119
120
121
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 119

def wire_controller
  inject_permitted_params
end

#wire_formObject



98
99
100
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 98

def wire_form
  inject_form_nested
end

#wire_modelObject



94
95
96
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 94

def wire_model
  inject_parent_model
end

#wire_page_formObject



115
116
117
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 115

def wire_page_form
  inject_page_form
end

#wire_viewsObject



111
112
113
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 111

def wire_views
  inject_container_fieldset
end