Class: Effective::Generators::FormGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Helpers
Defined in:
lib/generators/effective/form_generator.rb

Instance Method Summary collapse

Instance Method Details

#assign_attributesObject



26
27
28
29
# File 'lib/generators/effective/form_generator.rb', line 26

def assign_attributes
  @attributes = invoked_attributes.presence || resource_attributes
  self.class.send(:attr_reader, :attributes)
end

#create_formObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/effective/form_generator.rb', line 35

def create_form
  with_resource_tenant do
    if admin_effective_scaffold?
      template "#{scaffold_path}/views/_form.html.haml", resource.admin_effective_view_file('form', partial: true)
      template "#{scaffold_path}/views/_form_resource.html.haml", resource.admin_effective_view_file("form_#{resource.name}", partial: true)
    elsif effective_scaffold?
      template "#{scaffold_path}/views/_form_resource.html.haml", resource.view_file("form", partial: true)
    else
      template "#{scaffold_path}/views/_form.html.haml", resource.view_file('form', partial: true)
      template "#{scaffold_path}/views/_form_resource.html.haml", resource.view_file("form_#{resource.name}", partial: true)
    end

  end
end

#invoke_formObject



31
32
33
# File 'lib/generators/effective/form_generator.rb', line 31

def invoke_form
  say_status :invoke, :form, :white
end

#validate_resourceObject



22
23
24
# File 'lib/generators/effective/form_generator.rb', line 22

def validate_resource
  exit unless resource_valid?
end