Class: NewScaffoldGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/new_scaffold/new_scaffold_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



7
8
9
# File 'lib/generators/new_scaffold/new_scaffold_generator.rb', line 7

def self.source_root
  File.expand_path('../templates', __FILE__)
end

Instance Method Details

#copy_rails_controller_templateObject



33
34
35
36
# File 'lib/generators/new_scaffold/new_scaffold_generator.rb', line 33

def copy_rails_controller_template
  copy_file File.join(Rails::Generators::ScaffoldControllerGenerator.default_source_root, 'controller.rb'),
            "#{singular_name}_scaffold/templates/controller.rb"
end

#copy_rails_erb_templatesObject



19
20
21
22
23
24
# File 'lib/generators/new_scaffold/new_scaffold_generator.rb', line 19

def copy_rails_erb_templates
  %w[ _form.html.erb edit.html.erb index.html.erb new.html.erb show.html.erb ].each do |file_name|
    copy_file File.join(Erb::Generators::ScaffoldGenerator.default_source_root, file_name),
              "#{singular_name}_scaffold/templates/#{file_name}"
  end
end

#copy_rails_model_templateObject



26
27
28
29
30
31
# File 'lib/generators/new_scaffold/new_scaffold_generator.rb', line 26

def copy_rails_model_template
  copy_file File.join(ActiveRecord::Generators::ModelGenerator.default_source_root, 'model.rb'),
            "#{singular_name}_scaffold/templates/model.rb"
  copy_file File.join(ActiveRecord::Generators::ModelGenerator.default_source_root, 'migration.rb'),
            "#{singular_name}_scaffold/templates/migration.rb"
end

#copy_scaffold_screenshotObject



15
16
17
# File 'lib/generators/new_scaffold/new_scaffold_generator.rb', line 15

def copy_scaffold_screenshot
  copy_file 'screenshot.png', "#{singular_name}_scaffold/#{singular_name}_screenshot.png"
end

#copy_scaffold_specObject



11
12
13
# File 'lib/generators/new_scaffold/new_scaffold_generator.rb', line 11

def copy_scaffold_spec
  template 'scaffold_spec.rb.erb', "#{singular_name}_scaffold/scaffold_spec.rb"
end