Class: Cf::Generators::FormGenerator

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

Overview

TODO: if the parameter like ‘company’ below is not provided, then its a survey form. But how to name it is not defined. If we just use survey_name, then it might collide if the developer generates another survey form

> rails generate cf:form company ceo:string Website:url

<label>{company}</label> <p><label>ceo</label><input id=“ceo” type=“text” name=“output” data-valid-type=“string” /></p> <p><label>Website</label><input id=“website” type=“text” name=“output” data-valid-type=“url” /></p>

> rails generate cf:form [company,website] CEO:string Website:url

<label>{company}</label> <label>{website}</label> <p><label>CEO</label><input id=“ceo” type=“text” name=“output” data-valid-type=“string” /></p> <p><label>Website</label><input id=“website” type=“text” name=“output” data-valid-type=“url” /></p>

Instance Method Summary collapse

Instance Method Details

#generate_formObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/generators/cf/form/form_generator.rb', line 30

def generate_form
  @labels = nil

  attributes.detect {|item| @labels = item.match(/^\[(.*)\]$/) }

  @labels = @labels.to_a.last unless @labels.nil?
  attributes.delete(attributes.first) unless @labels.nil?

  file_name = make_file_name(@labels)

  say_status("Generating", "CloudFactory CustomTaskForm", :green)
  template "cf_form.html.erb", "app/cf_forms/#{file_name}"
end