Sha256: 29194ebbca4dd0cd62bcceb73ab3a54ae2a17ca6818c9ab336ceb12e0e7c5dca

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

$NITRO_NO_ENVIRONMENT = true

require 'facet/kernel/constant'
require 'facet/string/underscore'

require 'gen'
require 'nitro'
require 'nitro/helper/form'
require 'og'

# 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

class FormGen < Gen
  include Nitro::FormHelper
  
  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
  
  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
end

$generator = FormGen.new

# * George Moschovitis <gm@navel.gr>

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gen-0.29.0 lib/gen/form/gen.rb
gen-0.30.0 lib/gen/form/gen.rb
gen-0.31.0 lib/gen/form/gen.rb