Class: Cf::Form

Inherits:
Thor
  • Object
show all
Includes:
Config
Defined in:
lib/cf/cli/form.rb

Overview

:nodoc: all

Instance Method Summary collapse

Methods included from Config

#config_file, #find_home, #get_api_key, #load_config, #save_config, #set_api_key, #set_target_uri

Instance Method Details

#generateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cf/cli/form.rb', line 49

def generate
  line_destination = Dir.pwd
  unless File.exist?("#{line_destination}/line.yml")
    say("The current directory is not a valid line directory.", :red) and return
  end

  FileUtils.rm_rf("#{line_destination}/station_#{options[:station]}", :verbose => true) if options.force? && Dir.exist?("#{line_destination}/station_#{options[:station]}")
  if Dir.exist?("#{line_destination}/station_#{options[:station]}")
    say "Skipping the form generation because the station_#{options[:station]} already exists with its custom form.\nUse the -f flag to force it to overwrite or check and delete the station_#{options[:station]} folder manually.", :red
  else
    say "Generating form for station #{options[:station]}", :green
    Cf::Newform.start([options[:station], options[:labels], options[:fields]])
    say "A new custom task form created in station_#{options[:station]}."
  end
end

#previewObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/cf/cli/form.rb', line 67

def preview
  line_destination = Dir.pwd
  unless File.exist?("#{line_destination}/line.yml")
    say("The current directory is not a valid line directory.", :red) and return
  end
  if Dir.exist?("#{line_destination}/station_#{options[:station]}") and !Dir["#{line_destination}/station_#{options[:station]}/*"].empty?
    say "Generating preview form for station #{options[:station]}", :green
    form_content = File.read("station_#{options[:station]}/form.html")
    Cf::FormPreview.start([options[:station], form_content])
  else
    say "No form exists for station #{options[:station]}", :red
    say "Generate the form for station 2 and then preview it.", :red
  end
end