Class: Agile::Generators::NewFormGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/agile/new_form_generator.rb

Overview

rails g agile_rails:new_form MODEL

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

:nodoc:



35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/agile/new_form_generator.rb', line 35

def self.banner #:nodoc:
  <<-BANNER.chomp
  rails g agile_rails:new_form MODEL [options]

    Generates Agile Rails form for specified Rails model

      - options: --tabs will create form entry fields with tabs (default: --no-tabs) 
                 --extra will create some extra commented code for help (default: --no-extra) 
BANNER
end

Instance Method Details

#create_form_fileObject

Will create output and save it to form filename.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/generators/agile/new_form_generator.rb', line 49

def create_form_file
  @file_name = file_name.underscore
  @tabs  = options[:tabs]
  pp options
  @extra = options[:extra]
  begin
    @model = @file_name.classify.constantize
  rescue Exception => e
    pp ([e.message] + e.backtrace).join($/)
    @model = nil
  end
  return (pp "Error loading #{file_name.classify} model! Aborting.") if @model.nil?

  form = top_level_options +
         index_options +
         data_set_options +
         form_top_options +
         form_fields_options +
         localize_options
  create_file "app/forms/#{@file_name}.yml", form
end