From 4dd764207cce57ae4f592b383620b2f49fe2c727 Mon Sep 17 00:00:00 2001 From: Karel Minarik Date: Sat, 17 Jan 2009 19:12:13 +0100 Subject: Clarifications and additions to the introduction part of Internationalization (I18n) guide --- railties/doc/guides/html/creating_plugins.html | 96 +++++++++++++------------- 1 file changed, 48 insertions(+), 48 deletions(-) (limited to 'railties/doc/guides/html/creating_plugins.html') diff --git a/railties/doc/guides/html/creating_plugins.html b/railties/doc/guides/html/creating_plugins.html index 3347f77228..c34bbef2f7 100644 --- a/railties/doc/guides/html/creating_plugins.html +++ b/railties/doc/guides/html/creating_plugins.html @@ -299,7 +299,7 @@ create vendor/plugins/yaffle/generators/yaffle/USAGE

vendor/plugins/yaffle/rails/init.rb

-
@@ -355,7 +355,7 @@ mysql:

For this guide you’ll need 2 tables/models, Hickwalls and Wickwalls, so add the following:

vendor/plugins/yaffle/test/schema.rb:

-
@@ -376,7 +376,7 @@ http://www.gnu.org/software/src-highlite --> end

vendor/plugins/yaffle/test/test_helper.rb:

-
@@ -419,7 +419,7 @@ ENV['RAILS_ROOT

Once you have these files in place, you can write your first test to ensure that your plugin-testing setup is correct. By default rails generates a file in vendor/plugins/yaffle/test/yaffle_test.rb with a sample test. Replace the contents of that file with:

vendor/plugins/yaffle/test/yaffle_test.rb:

-
@@ -481,7 +481,7 @@ rake DB=postgresql

In this example you will add a method to String named to_squawk. To begin, create a new test file with a few assertions:

vendor/plugins/yaffle/test/core_ext_test.rb

-
@@ -510,7 +510,7 @@ NoMethodError: undefined method `to_squawk' for "Hello World":String

Then in lib/yaffle.rb require lib/core_ext.rb:

vendor/plugins/yaffle/lib/yaffle.rb

-
@@ -518,7 +518,7 @@ http://www.gnu.org/software/src-highlite -->

Finally, create the core_ext.rb file and add the to_squawk method:

vendor/plugins/yaffle/lib/yaffle/core_ext.rb

-
@@ -540,7 +540,7 @@ http://www.gnu.org/software/src-highlite -->

If you must reopen a class in init.rb you can use module_eval or class_eval to avoid any issues:

vendor/plugins/yaffle/rails/init.rb

-
@@ -552,7 +552,7 @@ http://www.gnu.org/software/src-highlite -->

Another way is to explicitly define the top-level module space for all modules and classes, like ::Hash:

vendor/plugins/yaffle/rails/init.rb

-
@@ -568,7 +568,7 @@ http://www.gnu.org/software/src-highlite -->

To begin, set up your files so that you have:

vendor/plugins/yaffle/test/acts_as_yaffle_test.rb

-
@@ -578,14 +578,14 @@ http://www.gnu.org/software/src-highlite --> end

vendor/plugins/yaffle/lib/yaffle.rb

-
require 'yaffle/acts_as_yaffle'

vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb

-
@@ -596,7 +596,7 @@ http://www.gnu.org/software/src-highlite -->

One of the most common plugin patterns for acts_as_yaffle plugins is to structure your file like so:

vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb

-
@@ -622,7 +622,7 @@ http://www.gnu.org/software/src-highlite -->

To start out, write a failing test that shows the behavior you’d like:

vendor/plugins/yaffle/test/acts_as_yaffle_test.rb

-
@@ -650,7 +650,7 @@ http://www.gnu.org/software/src-highlite -->

To make these tests pass, you could modify your acts_as_yaffle file like so:

vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb

-
@@ -673,7 +673,7 @@ ActiveRecord::Base

To start out, write a failing test that shows the behavior you’d like:

vendor/plugins/yaffle/test/acts_as_yaffle_test.rb

-
@@ -713,7 +713,7 @@ http://www.gnu.org/software/src-highlite -->

Run this test to make sure the last two tests fail, then update acts_as_yaffle.rb to look like this:

vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb

-
@@ -770,7 +770,7 @@ ActiveRecord::Base

As always, start with a test:

vendor/plugins/yaffle/yaffle/woodpecker_test.rb:

-
@@ -786,7 +786,7 @@ http://www.gnu.org/software/src-highlite -->

This is just a simple test to make sure the class is being loaded correctly. After watching it fail with rake, you can make it pass like so:

vendor/plugins/yaffle/lib/yaffle.rb:

-
@@ -799,7 +799,7 @@ http://www.gnu.org/software/src-highlite -->

Adding directories to the load path makes them appear just like files in the the main app directory - except that they are only loaded once, so you have to restart the web server to see the changes in the browser. Removing directories from the load_once_paths allow those changes to picked up as soon as you save the file - without having to restart the web server. This is particularly useful as you develop the plugin.

vendor/plugins/yaffle/lib/app/models/woodpecker.rb:

-
@@ -808,7 +808,7 @@ http://www.gnu.org/software/src-highlite -->

Finally, add the following to your plugin’s schema.rb:

vendor/plugins/yaffle/test/schema.rb:

-
@@ -823,7 +823,7 @@ http://www.gnu.org/software/src-highlite -->

You can test your plugin’s controller as you would test any other controller:

vendor/plugins/yaffle/test/woodpeckers_controller_test.rb:

-
@@ -852,7 +852,7 @@ http://www.gnu.org/software/src-highlite -->

This is just a simple test to make sure the controller is being loaded correctly. After watching it fail with rake, you can make it pass like so:

vendor/plugins/yaffle/lib/yaffle.rb:

-
@@ -864,7 +864,7 @@ http://www.gnu.org/software/src-highlite --> end

vendor/plugins/yaffle/lib/app/controllers/woodpeckers_controller.rb:

-
@@ -883,7 +883,7 @@ http://www.gnu.org/software/src-highlite -->

You can test your plugin’s helper as you would test any other helper:

vendor/plugins/yaffle/test/woodpeckers_helper_test.rb

-
@@ -898,7 +898,7 @@ http://www.gnu.org/software/src-highlite -->

This is just a simple test to make sure the helper is being loaded correctly. After watching it fail with rake, you can make it pass like so:

vendor/plugins/yaffle/lib/yaffle.rb:

-
@@ -910,7 +910,7 @@ http://www.gnu.org/software/src-highlite --> end

vendor/plugins/yaffle/lib/app/helpers/woodpeckers_helper.rb:

-
@@ -929,7 +929,7 @@ http://www.gnu.org/software/src-highlite -->

Testing routes from plugins is slightly different from testing routes in a standard rails app. To begin, add a test like this:

vendor/plugins/yaffle/test/routing_test.rb

-
@@ -957,14 +957,14 @@ http://www.gnu.org/software/src-highlite -->

Once you see the tests fail by running rake, you can make them pass with:

vendor/plugins/yaffle/lib/yaffle.rb

-
require "yaffle/routing"

vendor/plugins/yaffle/lib/yaffle/routing.rb

-
@@ -981,7 +981,7 @@ http://www.gnu.org/software/src-highlite --> ActionController::Routing::RouteSet::Mapper.send :include, Yaffle::Routing::MapperExtensions

config/routes.rb

-
@@ -1021,7 +1021,7 @@ Removes the fake rails root

This section will describe how to create a simple generator that adds a file. For the generator in this section, the test could look something like this:

vendor/plugins/yaffle/test/definition_generator_test.rb

-
@@ -1061,7 +1061,7 @@ http://www.gnu.org/software/src-highlite -->

To make it pass, create the generator:

vendor/plugins/yaffle/generators/yaffle_definition/yaffle_definition_generator.rb

-
@@ -1101,7 +1101,7 @@ http://www.gnu.org/software/src-highlite -->

To start, add the following test method:

vendor/plugins/yaffle/test/route_generator_test.rb

-
@@ -1161,14 +1161,14 @@ http://www.gnu.org/software/src-highlite -->

Run rake to watch the test fail, then make the test pass add the following:

vendor/plugins/yaffle/lib/yaffle.rb

-
require "yaffle/commands"

vendor/plugins/yaffle/lib/yaffle/commands.rb

-
@@ -1214,7 +1214,7 @@ Rails::Generator::Generator::Commands::Update.send :include, Yaffle::Generator::Commands::Update

vendor/plugins/yaffle/generators/yaffle/yaffle_route_generator.rb

-
@@ -1248,7 +1248,7 @@ http://www.gnu.org/software/src-highlite -->

Let’s say you have the following migration in your plugin:

vendor/plugins/yaffle/lib/db/migrate/20081116181115_create_birdhouses.rb:

-
@@ -1268,7 +1268,7 @@ http://www.gnu.org/software/src-highlite -->

11.1. Create a custom rake task

vendor/plugins/yaffle/lib/db/migrate/20081116181115_create_birdhouses.rb:

-
@@ -1286,7 +1286,7 @@ http://www.gnu.org/software/src-highlite --> end

vendor/plugins/yaffle/tasks/yaffle.rake:

-
@@ -1303,7 +1303,7 @@ http://www.gnu.org/software/src-highlite -->

11.2. Call migrations directly

vendor/plugins/yaffle/lib/yaffle.rb:

-
@@ -1312,7 +1312,7 @@ http://www.gnu.org/software/src-highlite --> end

db/migrate/20081116181115_create_birdhouses.rb:

-
@@ -1351,7 +1351,7 @@ examine the generated migration, adding/removing columns or other options as nec

This example will demonstrate how to use one of the built-in generator methods named migration_template to create a migration file. Extending the rails migration generator requires a somewhat intimate knowledge of the migration generator internals, so it’s best to write a test first:

vendor/plugins/yaffle/test/yaffle_migration_generator_test.rb

-
@@ -1408,7 +1408,7 @@ http://www.gnu.org/software/src-highlite -->

After running the test with rake you can make it pass with:

vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb

-
@@ -1447,7 +1447,7 @@ http://www.gnu.org/software/src-highlite -->

and you will see a new file:

db/migrate/20080529225649_add_yaffle_fields_to_birds.rb

-
@@ -1467,7 +1467,7 @@ http://www.gnu.org/software/src-highlite -->

Many plugin authors put all of their rake tasks into a common namespace that is the same as the plugin, like so:

vendor/plugins/yaffle/tasks/yaffle.rake

-
@@ -1492,7 +1492,7 @@ http://www.gnu.org/software/src-highlite -->

It’s common practice to put any developer-centric rake tasks (such as tests, rdoc and gem package tasks) in Rakefile. A rake task that packages the gem might look like this:

vendor/plugins/yaffle/Rakefile:

-
@@ -1604,7 +1604,7 @@ Warning, gotchas or tips that might help save users time

15.2. Contents of lib/yaffle.rb

vendor/plugins/yaffle/lib/yaffle.rb:

-
-- cgit v1.2.3