Class: Skizmo::Generators::FormGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/skizmo/form/form_generator.rb

Instance Method Summary collapse

Instance Method Details

#generate_formObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/skizmo/form/form_generator.rb', line 15

def generate_form 
  unless nested_has_many_classes.empty?
    copy_file "javascript.js", "public/javascripts/jquery.add_remove_links.js" if options.javascript?  
    copy_file "helper.rb", "app/helpers/add_remove_links_helper.rb" if options.helpers?  
  end
  unless nested_classes_with_attributes.empty? and non_nested_has_many_classes.empty? and non_nested_belongs_to_classes.empty?
    template "setup_helper.rb", "app/helpers/#{file_name}_setup_helper.rb" if options.helpers?  
  end
  template "index.html.#{engine}", "app/views/#{file_name.pluralize}/index.html.#{engine}" if options.index_view?
  template "new.html.#{engine}", "app/views/#{file_name.pluralize}/new.html.#{engine}"  
  template "edit.html.#{engine}", "app/views/#{file_name.pluralize}/edit.html.#{engine}"  
  @have_attachment_string = have_attachments? ? ", :html => { :multipart => true }" : ""
  template "_form.html.#{engine}", "app/views/#{file_name.pluralize}/_form.html.#{engine}"  
  nested_classes_with_attributes.each do |hash_with_kls_and_attrs|
    @kls   = hash_with_kls_and_attrs[:kls]    # class object
    @sym   = hash_with_kls_and_attrs[:sym]    # passed to the fields_for
    @attrs = hash_with_kls_and_attrs[:attrs]  # attrs that are worthy for this association
    @assoc = hash_with_kls_and_attrs[:assoc]  # so we know whether to use the add and remove links or not
    template "_nested_fields.html.#{engine}", "app/views/#{file_name.pluralize}/_#{@sym.to_s.singularize}_fields.html.#{engine}"
  end
end