Sha256: d68dae771ad8905b77870796be86fbdcc44408663020414aeaca5b6366eebf0c

Contents?: true

Size: 866 Bytes

Versions: 2

Compression:

Stored size: 866 Bytes

Contents

$NITRO_NO_ENVIRONMENT = true

require 'nano/kernel/constant'
require 'nano/string/underscore'

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

# This generator generates xhtml forms for Ruby objects.
#
# === Example
#
# gen form model/user User
# gen form model/user

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

2 entries across 2 versions & 1 rubygems

Version Path
gen-0.26.0 lib/gen/form/gen.rb
gen-0.25.0 lib/gen/form/gen.rb