aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides/creating_plugins/custom_generator.txt
diff options
context:
space:
mode:
authorrick <technoweenie@gmail.com>2008-08-26 11:53:33 -0700
committerrick <technoweenie@gmail.com>2008-08-26 11:53:33 -0700
commit0aef9d1a2651fa0acd2adcd2de308eeb0ec8cdd2 (patch)
tree1a782151632dd80c8a18c3960536bdf8643debe3 /railties/doc/guides/creating_plugins/custom_generator.txt
parent0a6d75dedd79407376aae1f01302164dfd3e44b6 (diff)
parent229eedfda87a7706dbb5e3e51af8707b3adae375 (diff)
downloadrails-0aef9d1a2651fa0acd2adcd2de308eeb0ec8cdd2.tar.gz
rails-0aef9d1a2651fa0acd2adcd2de308eeb0ec8cdd2.tar.bz2
rails-0aef9d1a2651fa0acd2adcd2de308eeb0ec8cdd2.zip
Merge branch 'master' of git@github.com:rails/rails
Diffstat (limited to 'railties/doc/guides/creating_plugins/custom_generator.txt')
-rw-r--r--railties/doc/guides/creating_plugins/custom_generator.txt69
1 files changed, 69 insertions, 0 deletions
diff --git a/railties/doc/guides/creating_plugins/custom_generator.txt b/railties/doc/guides/creating_plugins/custom_generator.txt
new file mode 100644
index 0000000000..6d9613ea01
--- /dev/null
+++ b/railties/doc/guides/creating_plugins/custom_generator.txt
@@ -0,0 +1,69 @@
+== Add a custom generator command ==
+
+You may have noticed above that you can used one of the built-in rails migration commands `m.migration_template`. You can create your own commands for these, using the following steps:
+
+ 1. Add the require and hook statements to init.rb.
+ 2. Create the commands - creating 3 sets, Create, Destroy, List.
+ 3. Add the method to your generator.
+
+Working with the internals of generators is beyond the scope of this tutorial, but here is a basic example:
+
+[source, ruby]
+-----------------------------------------------------------
+# File: vendor/plugins/yaffle/init.rb
+require "commands"
+Rails::Generator::Commands::Create.send :include, Yaffle::Generator::Commands::Create
+Rails::Generator::Commands::Destroy.send :include, Yaffle::Generator::Commands::Destroy
+Rails::Generator::Commands::List.send :include, Yaffle::Generator::Commands::List
+-----------------------------------------------------------
+
+[source, ruby]
+-----------------------------------------------------------
+# File: vendor/plugins/yaffle/lib/commands.rb
+
+require 'rails_generator'
+require 'rails_generator/commands'
+
+module Yaffle #:nodoc:
+ module Generator #:nodoc:
+ module Commands #:nodoc:
+ module Create
+ def yaffle_definition
+ file("definition.txt", "definition.txt")
+ end
+ end
+
+ module Destroy
+ def yaffle_definition
+ file("definition.txt", "definition.txt")
+ end
+ end
+
+ module List
+ def yaffle_definition
+ file("definition.txt", "definition.txt")
+ end
+ end
+ end
+ end
+end
+-----------------------------------------------------------
+
+-----------------------------------------------------------
+# File: vendor/plugins/yaffle/generators/yaffle/templates/definition.txt
+
+Yaffle is a bird
+-----------------------------------------------------------
+
+[source, ruby]
+-----------------------------------------------------------
+# File: vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb
+
+class YaffleGenerator < Rails::Generator::NamedBase
+ def manifest
+ m.yaffle_definition
+ end
+end
+-----------------------------------------------------------
+
+This example just uses the built-in "file" method, but you could do anything that Ruby allows.