aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides/source/creating_plugins
diff options
context:
space:
mode:
authorJeff Dean <jeff@zilkey.com>2008-11-14 00:38:52 -0500
committerJeff Dean <jeff@zilkey.com>2008-11-14 00:38:52 -0500
commit8a9bd56ca0d43c703f330e378474ddbdca2acd8e (patch)
treee320aa2cc7e3431cabeb95799e2a9ce8e1a2510f /railties/doc/guides/source/creating_plugins
parent4146efc380255319768031f26e63210fd4158e99 (diff)
downloadrails-8a9bd56ca0d43c703f330e378474ddbdca2acd8e.tar.gz
rails-8a9bd56ca0d43c703f330e378474ddbdca2acd8e.tar.bz2
rails-8a9bd56ca0d43c703f330e378474ddbdca2acd8e.zip
Plugin Guide: updated test setup and generator sections
Diffstat (limited to 'railties/doc/guides/source/creating_plugins')
-rw-r--r--railties/doc/guides/source/creating_plugins/generator_method.txt (renamed from railties/doc/guides/source/creating_plugins/custom_generator.txt)52
-rw-r--r--railties/doc/guides/source/creating_plugins/index.txt2
-rw-r--r--railties/doc/guides/source/creating_plugins/test_setup.txt2
3 files changed, 37 insertions, 19 deletions
diff --git a/railties/doc/guides/source/creating_plugins/custom_generator.txt b/railties/doc/guides/source/creating_plugins/generator_method.txt
index a8cf1b48ce..126692f2c4 100644
--- a/railties/doc/guides/source/creating_plugins/custom_generator.txt
+++ b/railties/doc/guides/source/creating_plugins/generator_method.txt
@@ -1,21 +1,35 @@
== 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:
+You may have noticed above that you can used one of the built-in rails migration commands `migration_template`. If your plugin needs to add and remove lines of text from existing files you will need to write your own generator methods.
- 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.
+This section describes how you you can create your own commands to add and remove a line of text from 'routes.rb'. This example creates a very simple method that adds or removes a text file.
-Working with the internals of generators is beyond the scope of this tutorial, but here is a basic example:
+To start, add the following test method:
-*vendor/plugins/yaffle/init.rb*
+*vendor/plugins/yaffle/test/generator_test.rb*
[source, ruby]
-----------------------------------------------------------
-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
+def test_generates_definition
+ Rails::Generator::Scripts::Generate.new.run(["yaffle", "bird"], :destination => fake_rails_root)
+ definition = File.read(File.join(fake_rails_root, "definition.txt"))
+ assert_match /Yaffle\:/, definition
+end
+-----------------------------------------------------------
+
+Run `rake` to watch the test fail, then make the test pass add the following:
+
+*vendor/plugins/yaffle/generators/yaffle/templates/definition.txt*
+
+-----------------------------------------------------------
+Yaffle: A bird
+-----------------------------------------------------------
+
+*vendor/plugins/yaffle/lib/yaffle.rb*
+
+[source, ruby]
+-----------------------------------------------------------
+require "yaffle/commands"
-----------------------------------------------------------
*vendor/plugins/yaffle/lib/commands.rb*
@@ -45,16 +59,24 @@ module Yaffle #:nodoc:
file("definition.txt", "definition.txt")
end
end
+
+ module Update
+ def yaffle_definition
+ file("definition.txt", "definition.txt")
+ end
+ end
end
end
end
------------------------------------------------------------
-*vendor/plugins/yaffle/generators/yaffle/templates/definition.txt*
------------------------------------------------------------
-Yaffle is a bird
+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
+Rails::Generator::Commands::Update.send :include, Yaffle::Generator::Commands::Update
-----------------------------------------------------------
+Finally, call your new method in the manifest:
+
*vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb*
[source, ruby]
@@ -65,5 +87,3 @@ class YaffleGenerator < Rails::Generator::NamedBase
end
end
-----------------------------------------------------------
-
-This example just uses the built-in "file" method, but you could do anything that Ruby allows.
diff --git a/railties/doc/guides/source/creating_plugins/index.txt b/railties/doc/guides/source/creating_plugins/index.txt
index 91d7027323..bd7dfe65c3 100644
--- a/railties/doc/guides/source/creating_plugins/index.txt
+++ b/railties/doc/guides/source/creating_plugins/index.txt
@@ -39,7 +39,7 @@ include::view_helper.txt[]
include::migration_generator.txt[]
-include::custom_generator.txt[]
+include::generator_method.txt[]
include::custom_route.txt[]
diff --git a/railties/doc/guides/source/creating_plugins/test_setup.txt b/railties/doc/guides/source/creating_plugins/test_setup.txt
index 4bcb2d5c2b..9e6763bc30 100644
--- a/railties/doc/guides/source/creating_plugins/test_setup.txt
+++ b/railties/doc/guides/source/creating_plugins/test_setup.txt
@@ -153,9 +153,7 @@ def load_schema
end
ActiveRecord::Base.establish_connection(config[db_adapter])
-
load(File.dirname(__FILE__) + "/schema.rb")
-
require File.dirname(__FILE__) + '/../init.rb'
end
----------------------------------------------