Class: Infold::Views::FormGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Infold::Views::FormGenerator
- Defined in:
- lib/generators/infold/views/form_generator.rb
Instance Method Summary collapse
- #association_form_file ⇒ Object
- #edit_file ⇒ Object
- #form_file ⇒ Object
- #form_turbo_stream_file ⇒ Object
- #new_file ⇒ Object
- #setup ⇒ Object
Instance Method Details
#association_form_file ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/infold/views/form_generator.rb', line 41 def association_form_file @writer.form_fields.each do |field| if field.association&.has_child? @association_field = field template "views/_form_association.haml", Rails.root.join("app/views/admin/#{name.underscore.pluralize}/_form_#{field.name(:single)}.html.haml"), force: true end end end |
#edit_file ⇒ Object
26 27 28 29 |
# File 'lib/generators/infold/views/form_generator.rb', line 26 def edit_file template "views/edit.html+turbo_frame.haml", Rails.root.join("app/views/admin/#{name.underscore.pluralize}/edit.html+turbo_frame.haml"), force: true end |
#form_file ⇒ Object
31 32 33 34 |
# File 'lib/generators/infold/views/form_generator.rb', line 31 def form_file template "views/_form.haml", Rails.root.join("app/views/admin/#{name.underscore.pluralize}/_form.html.haml"), force: true end |
#form_turbo_stream_file ⇒ Object
36 37 38 39 |
# File 'lib/generators/infold/views/form_generator.rb', line 36 def form_turbo_stream_file template "views/form.turbo_stream.haml", Rails.root.join("app/views/admin/#{name.underscore.pluralize}/form.turbo_stream.haml"), force: true end |
#new_file ⇒ Object
21 22 23 24 |
# File 'lib/generators/infold/views/form_generator.rb', line 21 def new_file template "views/new.html+turbo_frame.haml", Rails.root.join("app/views/admin/#{name.underscore.pluralize}/new.html+turbo_frame.haml"), force: true end |
#setup ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/generators/infold/views/form_generator.rb', line 12 def setup resource_name = name.camelize.singularize db_schema_file = Rails.root.join('db/schema.rb') db_schema = DbSchema.new(File.exist?(db_schema_file) ? File.read(db_schema_file) : nil) yaml = YAML.load_file(Rails.root.join("config/infold/#{resource_name.underscore}.yml")) resource = YamlReader.generate_resource(resource_name, yaml, db_schema) @writer = FormWriter.new(resource) end |