Class: FormGen

Inherits:
Gen
  • Object
show all
Includes:
Nitro::FormHelper
Defined in:
lib/gen/form/gen.rb

Overview

This generator generates xhtml forms for Ruby objects. This generator will create some a complete xhtml form for the given object. The scaffolding code uses the object annotations to create a useful form.

Example

gen form model/user User gen form model/user

Constant Summary

Constants inherited from Gen

Gen::LibPath, Gen::Version

Instance Attribute Summary

Attributes inherited from Gen

#generator_dir

Instance Method Summary collapse

Methods inherited from Gen

#teardown, #usage

Instance Method Details

#runObject



33
34
35
36
37
38
39
40
# File 'lib/gen/form/gen.rb', line 33

def run
  @klass = constant(@klass)
  @klass.send(:define_method, :oid) { -1 }
  form = form_for(@klass.allocate, :skip_relations => true)
  File.open(@form_filename, 'w') do |f|
    f << form
  end
end

#setupObject



24
25
26
27
28
29
30
31
# File 'lib/gen/form/gen.rb', line 24

def setup
  @def_filename = ARGV[0] || usage()
  @klass = ARGV[1]
  @form_filename = ARGV[2] || "#{@klass.underscore}.html"
  require @def_filename
rescue LoadError
  puts "Cannot load ruby file '#@def_filename'!"
end