1
class ControllerGenerator < Rails::Generator::NamedBase
4
# Check for class naming collisions.
5
m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper", "#{class_name}HelperTest"
7
# Controller, helper, views, and test directories.
8
m.directory File.join('app/controllers', class_path)
9
m.directory File.join('app/helpers', class_path)
10
m.directory File.join('app/views', class_path, file_name)
11
m.directory File.join('test/functional', class_path)
12
m.directory File.join('test/unit/helpers', class_path)
14
# Controller class, functional test, and helper class.
15
m.template 'controller.rb',
16
File.join('app/controllers',
18
"#{file_name}_controller.rb")
20
m.template 'functional_test.rb',
21
File.join('test/functional',
23
"#{file_name}_controller_test.rb")
25
m.template 'helper.rb',
26
File.join('app/helpers',
28
"#{file_name}_helper.rb")
30
m.template 'helper_test.rb',
31
File.join('test/unit/helpers',
33
"#{file_name}_helper_test.rb")
35
# View template for each action.
36
actions.each do |action|
37
path = File.join('app/views', class_path, file_name, "#{action}.html.erb")
38
m.template 'view.html.erb', path,
39
:assigns => { :action => action, :path => path }