aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/generators/rails/controller
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-18 13:44:32 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-18 16:21:11 +0100
commit9fffdc5cdb80b1824473a6d7ae1fedf9e74aa748 (patch)
tree88f429511bf65f1104efeab10d6310b68ab24837 /railties/lib/generators/rails/controller
parente75ea474346e74e36d92febd47985c3571b1472b (diff)
downloadrails-9fffdc5cdb80b1824473a6d7ae1fedf9e74aa748.tar.gz
rails-9fffdc5cdb80b1824473a6d7ae1fedf9e74aa748.tar.bz2
rails-9fffdc5cdb80b1824473a6d7ae1fedf9e74aa748.zip
Generators load path now will be Ruby load path. If you want to use rspec:install generator, you need generators/rspec/install_generator in your load path.
Diffstat (limited to 'railties/lib/generators/rails/controller')
-rw-r--r--railties/lib/generators/rails/controller/USAGE18
-rw-r--r--railties/lib/generators/rails/controller/controller_generator.rb14
-rw-r--r--railties/lib/generators/rails/controller/templates/controller.rb7
3 files changed, 39 insertions, 0 deletions
diff --git a/railties/lib/generators/rails/controller/USAGE b/railties/lib/generators/rails/controller/USAGE
new file mode 100644
index 0000000000..6ed4b2edfc
--- /dev/null
+++ b/railties/lib/generators/rails/controller/USAGE
@@ -0,0 +1,18 @@
+Description:
+ Stubs out a new controller and its views. Pass the controller name, either
+ CamelCased or under_scored, and a list of views as arguments.
+
+ To create a controller within a module, specify the controller name as a
+ path like 'parent_module/controller_name'.
+
+ This generates a controller class in app/controllers and invokes helper,
+ template engine and test framework generators.
+
+Example:
+ `./script/generate controller CreditCard open debit credit close`
+
+ Credit card controller with URLs like /credit_card/debit.
+ Controller: app/controllers/credit_card_controller.rb
+ Functional Test: test/functional/credit_card_controller_test.rb
+ Views: app/views/credit_card/debit.html.erb [...]
+ Helper: app/helpers/credit_card_helper.rb
diff --git a/railties/lib/generators/rails/controller/controller_generator.rb b/railties/lib/generators/rails/controller/controller_generator.rb
new file mode 100644
index 0000000000..91470be833
--- /dev/null
+++ b/railties/lib/generators/rails/controller/controller_generator.rb
@@ -0,0 +1,14 @@
+module Rails
+ module Generators
+ class ControllerGenerator < NamedBase
+ argument :actions, :type => :array, :default => [], :banner => "action action"
+ check_class_collision :suffix => "Controller"
+
+ def create_controller_files
+ template 'controller.rb', File.join('app/controllers', class_path, "#{file_name}_controller.rb")
+ end
+
+ hook_for :template_engine, :test_framework, :helper
+ end
+ end
+end
diff --git a/railties/lib/generators/rails/controller/templates/controller.rb b/railties/lib/generators/rails/controller/templates/controller.rb
new file mode 100644
index 0000000000..cda2659e69
--- /dev/null
+++ b/railties/lib/generators/rails/controller/templates/controller.rb
@@ -0,0 +1,7 @@
+class <%= class_name %>Controller < ApplicationController
+<% for action in actions -%>
+ def <%= action %>
+ end
+
+<% end -%>
+end