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.

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



65
66
67
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 65

def create_child_form
  template "child_form.rb.tt", child_form_path
end

#create_fields_viewObject



69
70
71
72
73
74
75
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 69

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



77
78
79
80
81
82
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 77

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



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 113

def post_install
  if @position_migration
    say_status :migrate, "#{child_table_name}.#{position_column} was added — " \
                         "run bin/rails db:migrate before using the fieldset.", :yellow
  end
  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.



60
61
62
63
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 60

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.



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

def wire_channel
  inject_channel_include
  inject_edit_preload
  inject_option_collections
end

#wire_controllerObject



109
110
111
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 109

def wire_controller
  inject_permitted_params
end

#wire_formObject



88
89
90
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 88

def wire_form
  inject_form_nested
end

#wire_modelObject



84
85
86
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 84

def wire_model
  inject_parent_model
end

#wire_page_formObject



105
106
107
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 105

def wire_page_form
  inject_page_form
end

#wire_viewsObject



101
102
103
# File 'lib/generators/hibiki/rails/nested/nested_generator.rb', line 101

def wire_views
  inject_container_fieldset
end