Class: Formtastic::FormGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Formtastic::FormGenerator
- Defined in:
- lib/generators/formtastic/form/form_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.banner ⇒ Object
22 23 24 |
# File 'lib/generators/formtastic/form/form_generator.rb', line 22 def self. "rails generate formtastic:form ExistingModelName [options]" end |
.source_root ⇒ Object
17 18 19 20 |
# File 'lib/generators/formtastic/form/form_generator.rb', line 17 def self.source_root # Set source directory for the templates to the rails2 generator template directory @source_root ||= File.(File.join('..', '..', '..', '..', 'generators', 'form', 'templates'), File.dirname(__FILE__)) end |
Instance Method Details
#create_or_show ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/formtastic/form/form_generator.rb', line 26 def create_or_show if [:partial] empty_directory "app/views/#{controller_path}" template "view__form.html.#{template_type}", "app/views/#{controller_path}/_form.html.#{template_type}" else template = File.read("#{self.class.source_root}/view__form.html.#{template_type}") erb = ERB.new(template, nil, '-') generated_code = erb.result(binding).strip rescue nil puts "# ---------------------------------------------------------" puts "# GENERATED FORMTASTIC CODE" puts "# ---------------------------------------------------------" puts puts generated_code || "Nothing could be generated - model exists?" puts puts "# ---------------------------------------------------------" puts "Copied to clipboard - just paste it!" if save_to_clipboard(generated_code) end end |