Froze rails gems
[depot.git] / vendor / rails / railties / doc / guides / html / creating_plugins.html
diff --git a/vendor/rails/railties/doc/guides/html/creating_plugins.html b/vendor/rails/railties/doc/guides/html/creating_plugins.html
new file mode 100644 (file)
index 0000000..375d216
--- /dev/null
@@ -0,0 +1,1594 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head>
+       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+       <title>The Basics of Creating Rails Plugins</title>
+       <!--[if lt IE 8]>
+       <script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js" type="text/javascript"></script>
+       <![endif]-->
+       <link href="stylesheets/base.css" media="screen" rel="Stylesheet" type="text/css" />
+       <link href="stylesheets/forms.css" media="screen" rel="Stylesheet" type="text/css" />
+       <link href="stylesheets/more.css" media="screen" rel="Stylesheet" type="text/css" />
+       <style type="text/css">
+               div#container {
+       max-width: 900px;
+       padding-bottom: 3em;
+}
+
+div#content {
+       margin-left: 200px;
+}
+
+div#container.notoc {
+       max-width: 600px;
+}
+
+.notoc div#content {
+       margin-left: 0;
+}
+
+pre {
+       line-height: 1.4em;
+}
+
+#content p tt {
+       background: #eeeeee;
+       border: solid 1px #cccccc;
+       padding: 3px;
+}
+
+dt {
+       font-weight: bold;
+}
+
+#content dt tt {
+       font-size: 10pt;
+}
+
+dd {
+       margin-left: 3em;
+}
+
+#content dt tt, #content pre tt {
+       background: none;
+       padding: 0;
+       border: 0;
+}
+
+#content .olist ol {
+       margin-left: 2em;
+}
+
+#header {
+       position: relative;
+       max-width: 840px;
+       margin-left: auto;
+       margin-right: auto;
+}
+
+#header.notoc {
+       max-width: 580px;
+}
+
+#logo {
+       position: absolute;
+       left: 10px;
+       top: 10px;
+       width: 110px;
+       height: 140px;
+}
+
+div#header h1#site_title {
+       background: url('images/ruby_on_rails_by_mike_rundle2.gif') top left no-repeat;
+       position: absolute;
+       width: 392px;
+       height: 55px;
+       left: 145px;
+       top: 20px;
+       margin: 0;
+       padding: 0;
+}
+
+#site_title span {
+       display: none;
+}
+
+#site_title_tagline {
+       display: none;
+}
+
+ul#navMain {
+       position: absolute;
+       margin: 0;
+       padding: 0;
+       top: 97px;
+       left: 145px;
+}
+
+.left-floaty, .right-floaty {
+       padding: 15px;
+}
+
+.admonitionblock,
+.tableblock {
+       margin-left: 1em;
+       margin-right: 1em;
+       margin-top: 0.25em;
+       margin-bottom: 1em;
+}
+
+.admonitionblock .icon {
+       padding-right: 8px;
+}
+
+.admonitionblock .content {
+       border: solid 1px #ffda78;
+       background: #fffebd;
+       padding: 10px;
+       padding-top: 8px;
+       padding-bottom: 8px;
+}
+
+.admonitionblock .title {
+       font-size: 140%;
+       margin-bottom: 0.5em;
+}
+
+.tableblock table {
+       border: solid 1px #aaaaff;
+       background: #f0f0ff;
+}
+
+.tableblock th {
+       background: #e0e0e0;
+}
+
+.tableblock th,
+.tableblock td {
+       padding: 3px;
+       padding-left: 5px;
+       padding-right: 5px;
+}
+
+.sidebarblock {
+       margin-top: 0.25em;
+       margin: 1em;
+       border: solid 1px #ccccbb;
+       padding: 8px;
+       background: #ffffe0;
+}
+
+.sidebarblock .sidebar-title {
+       font-size: 140%;
+       font-weight: 600;
+       margin-bottom: 0.3em;
+}
+
+.sidebarblock .sidebar-content > .para:last-child > p {
+       margin-bottom: 0;
+}
+
+.sidebarblock .sidebar-title a {
+       text-decoration: none;
+}
+
+.sidebarblock .sidebar-title a:hover {
+       text-decoration: underline;
+}
+
+       </style>
+</head>
+<body>
+       <div id="header" >
+               <div id="logo">
+                       <a href="index.html" title="Ruby on Rails"><img src="images/rails_logo_remix.gif" alt="Rails" height="140" width="110" /></a>
+               </div>
+               
+               <h1 id="site_title"><span>Ruby on Rails</span></h1>
+               <h2 id="site_title_tagline">Sustainable productivity for web-application development</h2>
+
+               <ul id="navMain">
+                       <li class="first-child"><a href="http://www.rubyonrails.org/" title="Ruby on Rails" class="ruby_on_rails">Ruby on Rails</a></li>
+                       <li><a class="manuals" href="index.html" title="Manuals Index">Guides Index</a></li>
+               </ul>
+       </div>
+
+       <div id="container">
+               
+               <div id="sidebar">
+                       <h2>Chapters</h2>
+                       <ol>
+                                       <li>
+                                       <a href="#_preparation">Preparation</a>
+                                               <ul>
+                                               
+                                                       <li><a href="#_create_the_basic_app">Create the basic app</a></li>
+                                               
+                                                       <li><a href="#_generate_the_plugin_skeleton">Generate the plugin skeleton</a></li>
+                                               
+                                                       <li><a href="#_setup_the_plugin_for_testing">Setup the plugin for testing</a></li>
+                                               
+                                                       <li><a href="#_run_the_plugin_tests">Run the plugin tests</a></li>
+                                               
+                                               </ul>
+                                       </li>
+                                       <li>
+                                       <a href="#_extending_core_classes">Extending core classes</a>
+                                               <ul>
+                                               
+                                                       <li><a href="#_creating_the_test">Creating the test</a></li>
+                                               
+                                                       <li><a href="#_organize_your_files">Organize your files</a></li>
+                                               
+                                                       <li><a href="#_working_with_init_rb">Working with init.rb</a></li>
+                                               
+                                               </ul>
+                                       </li>
+                                       <li>
+                                       <a href="#_add_an_tt_acts_as_yaffle_tt_method_to_active_record">Add an <tt>acts_as_yaffle</tt> method to Active Record</a>
+                                               <ul>
+                                               
+                                                       <li><a href="#_add_a_class_method">Add a class method</a></li>
+                                               
+                                                       <li><a href="#_add_an_instance_method">Add an instance method</a></li>
+                                               
+                                               </ul>
+                                       </li>
+                                       <li>
+                                       <a href="#_create_a_generator">Create a generator</a>
+                                               <ul>
+                                               
+                                                       <li><a href="#_testing_generators">Testing generators</a></li>
+                                               
+                                                       <li><a href="#_adding_to_the_manifest">Adding to the manifest</a></li>
+                                               
+                                                       <li><a href="#_manually_test_the_generator">Manually test the generator</a></li>
+                                               
+                                                       <li><a href="#_the_usage_file">The USAGE file</a></li>
+                                               
+                                               </ul>
+                                       </li>
+                                       <li>
+                                       <a href="#_add_a_custom_generator_command">Add a custom generator command</a>
+                                       </li>
+                                       <li>
+                                       <a href="#_add_a_model">Add a model</a>
+                                       </li>
+                                       <li>
+                                       <a href="#_add_a_controller">Add a controller</a>
+                                       </li>
+                                       <li>
+                                       <a href="#_add_a_helper">Add a helper</a>
+                                       </li>
+                                       <li>
+                                       <a href="#_add_a_custom_route">Add a Custom Route</a>
+                                       </li>
+                                       <li>
+                                       <a href="#_odds_and_ends">Odds and ends</a>
+                                               <ul>
+                                               
+                                                       <li><a href="#_generate_rdoc_documentation">Generate RDoc Documentation</a></li>
+                                               
+                                                       <li><a href="#_write_custom_rake_tasks_in_your_plugin">Write custom Rake tasks in your plugin</a></li>
+                                               
+                                                       <li><a href="#_store_plugins_in_alternate_locations">Store plugins in alternate locations</a></li>
+                                               
+                                                       <li><a href="#_create_your_own_plugin_loaders_and_plugin_locators">Create your own Plugin Loaders and Plugin Locators</a></li>
+                                               
+                                                       <li><a href="#_use_custom_plugin_generators">Use Custom Plugin Generators</a></li>
+                                               
+                                               </ul>
+                                       </li>
+                                       <li>
+                                       <a href="#_appendix">Appendix</a>
+                                               <ul>
+                                               
+                                                       <li><a href="#_references">References</a></li>
+                                               
+                                                       <li><a href="#_final_plugin_directory_structure">Final plugin directory structure</a></li>
+                                               
+                                               </ul>
+                                       </li>
+                       </ol>
+               </div>
+               
+               <div id="content">
+                               <h1>The Basics of Creating Rails Plugins</h1>
+                       <div id="preamble">\r
+<div class="sectionbody">\r
+<div class="para"><p>A Rails plugin is either an extension or a modification of the core framework. Plugins provide:</p></div>\r
+<div class="ilist"><ul>\r
+<li>\r
+<p>\r
+a way for developers to share bleeding-edge ideas without hurting the stable code base\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+a segmented architecture so that units of code can be fixed or updated on their own release schedule\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+an outlet for the core developers so that they don’t have to include every cool new feature under the sun\r
+</p>\r
+</li>\r
+</ul></div>\r
+<div class="para"><p>After reading this guide you should be familiar with:</p></div>\r
+<div class="ilist"><ul>\r
+<li>\r
+<p>\r
+Creating a plugin from scratch\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Writing and running tests for the plugin\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Storing models, views, controllers, helpers and even other plugins in your plugins\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Writing generators\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Writing custom Rake tasks in your plugin\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Generating RDoc documentation for your plugin\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Avoiding common pitfalls with <em>init.rb</em>\r
+</p>\r
+</li>\r
+</ul></div>\r
+<div class="para"><p>This guide describes how to build a test-driven plugin that will:</p></div>\r
+<div class="ilist"><ul>\r
+<li>\r
+<p>\r
+Extend core ruby classes like Hash and String\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Add methods to ActiveRecord::Base in the tradition of the <em>acts_as</em> plugins\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Add a view helper that can be used in erb templates\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Add a new generator that will generate a migration\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Add a custom generator command\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+A custom route method that can be used in routes.rb\r
+</p>\r
+</li>\r
+</ul></div>\r
+<div class="para"><p>For the purpose of this guide pretend for a moment that you are an avid bird watcher.  Your favorite bird is the Yaffle, and you want to create a plugin that allows other developers to share in the Yaffle goodness.  First, you need to get setup for development.</p></div>\r
+</div>\r
+</div>\r
+<h2 id="_preparation">1. Preparation</h2>\r
+<div class="sectionbody">\r
+<h3 id="_create_the_basic_app">1.1. Create the basic app</h3>\r
+<div class="para"><p>The examples in this guide require that you have a working rails application.  To create a simple rails app execute:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>gem install rails\r
+rails yaffle_guide\r
+cd yaffle_guide\r
+script/generate scaffold bird name:string\r
+rake db:migrate\r
+script/server</tt></pre>\r
+</div></div>\r
+<div class="para"><p>Then navigate to <a href="http://localhost:3000/birds">http://localhost:3000/birds</a>.  Make sure you have a functioning rails app before continuing.</p></div>\r
+<div class="admonitionblock">\r
+<table><tr>\r
+<td class="icon">\r
+<img src="./images/icons/note.png" alt="Note" />\r
+</td>\r
+<td class="content">\r
+<div class="title">Editor's note:</div>The aforementioned instructions will work for sqlite3.  For more detailed instructions on how to create a rails app for other databases see the API docs.</td>\r
+</tr></table>\r
+</div>\r
+<h3 id="_generate_the_plugin_skeleton">1.2. Generate the plugin skeleton</h3>\r
+<div class="para"><p>Rails ships with a plugin generator which creates a basic plugin skeleton. Pass the plugin name, either <em>CamelCased</em> or <em>under_scored</em>, as an argument. Pass <tt>--with-generator</tt> to add an example generator also.</p></div>\r
+<div class="para"><p>This creates a plugin in <em>vendor/plugins</em> including an <em>init.rb</em> and <em>README</em> as well as standard <em>lib</em>, <em>task</em>, and <em>test</em> directories.</p></div>\r
+<div class="para"><p>Examples:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>./script/generate plugin yaffle\r
+./script/generate plugin yaffle --with-generator</tt></pre>\r
+</div></div>\r
+<div class="para"><p>To get more detailed help on the plugin generator, type <tt>./script/generate plugin</tt>.</p></div>\r
+<div class="para"><p>Later on this guide will describe how to work with generators, so go ahead and generate your plugin with the <tt>--with-generator</tt> option now:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>./script/generate plugin yaffle --with-generator</tt></pre>\r
+</div></div>\r
+<div class="para"><p>You should see the following output:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>create  vendor/plugins/yaffle/lib\r
+create  vendor/plugins/yaffle/tasks\r
+create  vendor/plugins/yaffle/test\r
+create  vendor/plugins/yaffle/README\r
+create  vendor/plugins/yaffle/MIT-LICENSE\r
+create  vendor/plugins/yaffle/Rakefile\r
+create  vendor/plugins/yaffle/init.rb\r
+create  vendor/plugins/yaffle/install.rb\r
+create  vendor/plugins/yaffle/uninstall.rb\r
+create  vendor/plugins/yaffle/lib/yaffle.rb\r
+create  vendor/plugins/yaffle/tasks/yaffle_tasks.rake\r
+create  vendor/plugins/yaffle/test/core_ext_test.rb\r
+create  vendor/plugins/yaffle/generators\r
+create  vendor/plugins/yaffle/generators/yaffle\r
+create  vendor/plugins/yaffle/generators/yaffle/templates\r
+create  vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb\r
+create  vendor/plugins/yaffle/generators/yaffle/USAGE</tt></pre>\r
+</div></div>\r
+<div class="para"><p>To begin just change one thing - move <em>init.rb</em> to <em>rails/init.rb</em>.</p></div>\r
+<h3 id="_setup_the_plugin_for_testing">1.3. Setup the plugin for testing</h3>\r
+<div class="para"><p>If your plugin interacts with a database, you'll need to setup a database connection.  In this guide you will learn how to test your plugin against multiple different database adapters using Active Record.  This guide will not cover how to use fixtures in plugin tests.</p></div>\r
+<div class="para"><p>To setup your plugin to allow for easy testing you'll need to add 3 files:</p></div>\r
+<div class="ilist"><ul>\r
+<li>\r
+<p>\r
+A <em>database.yml</em> file with all of your connection strings\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+A <em>schema.rb</em> file with your table definitions\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+A test helper method that sets up the database\r
+</p>\r
+</li>\r
+</ul></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/test/database.yml:</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>sqlite:\r
+  :adapter: sqlite\r
+  :dbfile: vendor/plugins/yaffle/test/yaffle_plugin.sqlite.db\r
+\r
+sqlite3:\r
+  :adapter: sqlite3\r
+  :dbfile: vendor/plugins/yaffle/test/yaffle_plugin.sqlite3.db\r
+\r
+postgresql:\r
+  :adapter: postgresql\r
+  :username: postgres\r
+  :password: postgres\r
+  :database: yaffle_plugin_test\r
+  :min_messages: ERROR\r
+\r
+mysql:\r
+  :adapter: mysql\r
+  :host: localhost\r
+  :username: root\r
+  :password: password\r
+  :database: yaffle_plugin_test</tt></pre>\r
+</div></div>\r
+<div class="para"><p>For this guide you'll need 2 tables/models, Hickwalls and Wickwalls, so add the following:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/test/schema.rb:</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt>ActiveRecord<span style="color: #990000">::</span>Schema<span style="color: #990000">.</span>define<span style="color: #990000">(:</span>version <span style="color: #990000">=&gt;</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span>\r
+  create_table <span style="color: #990000">:</span>hickwalls<span style="color: #990000">,</span> <span style="color: #990000">:</span>force <span style="color: #990000">=&gt;</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>t<span style="color: #990000">|</span>\r
+    t<span style="color: #990000">.</span>string <span style="color: #990000">:</span>name\r
+    t<span style="color: #990000">.</span>string <span style="color: #990000">:</span>last_squawk\r
+    t<span style="color: #990000">.</span>datetime <span style="color: #990000">:</span>last_squawked_at\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+  create_table <span style="color: #990000">:</span>wickwalls<span style="color: #990000">,</span> <span style="color: #990000">:</span>force <span style="color: #990000">=&gt;</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>t<span style="color: #990000">|</span>\r
+    t<span style="color: #990000">.</span>string <span style="color: #990000">:</span>name\r
+    t<span style="color: #990000">.</span>string <span style="color: #990000">:</span>last_tweet\r
+    t<span style="color: #990000">.</span>datetime <span style="color: #990000">:</span>last_tweeted_at\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+  create_table <span style="color: #990000">:</span>woodpeckers<span style="color: #990000">,</span> <span style="color: #990000">:</span>force <span style="color: #990000">=&gt;</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>t<span style="color: #990000">|</span>\r
+    t<span style="color: #990000">.</span>string <span style="color: #990000">:</span>name\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/test/test_helper.rb:</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt>ENV<span style="color: #990000">[</span><span style="color: #FF0000">'RAILS_ENV'</span><span style="color: #990000">]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">'test'</span>\r
+ENV<span style="color: #990000">[</span><span style="color: #FF0000">'RAILS_ROOT'</span><span style="color: #990000">]</span> <span style="color: #990000">||=</span> File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">'/../../../..'</span>\r
+\r
+<span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'test/unit'</span>\r
+<span style="font-weight: bold"><span style="color: #000080">require</span></span> File<span style="color: #990000">.</span>expand_path<span style="color: #990000">(</span>File<span style="color: #990000">.</span>join<span style="color: #990000">(</span>ENV<span style="color: #990000">[</span><span style="color: #FF0000">'RAILS_ROOT'</span><span style="color: #990000">],</span> <span style="color: #FF0000">'config/environment.rb'</span><span style="color: #990000">))</span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">def</span></span> load_schema\r
+  config <span style="color: #990000">=</span> YAML<span style="color: #990000">::</span><span style="font-weight: bold"><span style="color: #0000FF">load</span></span><span style="color: #990000">(</span>IO<span style="color: #990000">.</span>read<span style="color: #990000">(</span>File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">'/database.yml'</span><span style="color: #990000">))</span>\r
+  ActiveRecord<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>logger <span style="color: #990000">=</span> Logger<span style="color: #990000">.</span>new<span style="color: #990000">(</span>File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">"/debug.log"</span><span style="color: #990000">)</span>\r
+\r
+  db_adapter <span style="color: #990000">=</span> ENV<span style="color: #990000">[</span><span style="color: #FF0000">'DB'</span><span style="color: #990000">]</span>\r
+\r
+  <span style="font-style: italic"><span style="color: #9A1900"># no db passed, try one of these fine config-free DBs before bombing.</span></span>\r
+  db_adapter <span style="color: #990000">||=</span>\r
+    <span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>\r
+      <span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'rubygems'</span>\r
+      <span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'sqlite'</span>\r
+      <span style="color: #FF0000">'sqlite'</span>\r
+    <span style="font-weight: bold"><span style="color: #0000FF">rescue</span></span> MissingSourceFile\r
+      <span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>\r
+        <span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'sqlite3'</span>\r
+        <span style="color: #FF0000">'sqlite3'</span>\r
+      <span style="font-weight: bold"><span style="color: #0000FF">rescue</span></span> MissingSourceFile\r
+      <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+    <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> db_adapter<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #0000FF">nil</span></span><span style="color: #990000">?</span>\r
+    <span style="font-weight: bold"><span style="color: #0000FF">raise</span></span> <span style="color: #FF0000">"No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."</span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  ActiveRecord<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>establish_connection<span style="color: #990000">(</span>config<span style="color: #990000">[</span>db_adapter<span style="color: #990000">])</span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">load</span></span><span style="color: #990000">(</span>File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">"/schema.rb"</span><span style="color: #990000">)</span>\r
+  <span style="font-weight: bold"><span style="color: #000080">require</span></span> File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">'/../rails/init.rb'</span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>Now whenever you write a test that requires the database, you can call <em>load_schema</em>.</p></div>\r
+<h3 id="_run_the_plugin_tests">1.4. Run the plugin tests</h3>\r
+<div class="para"><p>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 <em>vendor/plugins/yaffle/test/yaffle_test.rb</em> with a sample test.  Replace the contents of that file with:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/test/yaffle_test.rb:</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">'/test_helper.rb'</span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> YaffleTest <span style="color: #990000">&lt;</span> Test<span style="color: #990000">::</span>Unit<span style="color: #990000">::</span>TestCase\r
+  load_schema\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Hickwall <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Wickwall <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_schema_has_loaded_correctly\r
+    assert_equal <span style="color: #990000">[],</span> Hickwall<span style="color: #990000">.</span>all\r
+    assert_equal <span style="color: #990000">[],</span> Wickwall<span style="color: #990000">.</span>all\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>To run this, go to the plugin directory and run <tt>rake</tt>:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>cd vendor/plugins/yaffle\r
+rake</tt></pre>\r
+</div></div>\r
+<div class="para"><p>You should see output like:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>/opt/local/bin/ruby -Ilib:lib "/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" "test/yaffle_test.rb"\r
+-- create_table(:hickwalls, {:force=&gt;true})\r
+   -&gt; 0.0220s\r
+-- create_table(:wickwalls, {:force=&gt;true})\r
+   -&gt; 0.0077s\r
+-- initialize_schema_migrations_table()\r
+   -&gt; 0.0007s\r
+-- assume_migrated_upto_version(0)\r
+   -&gt; 0.0007s\r
+Loaded suite /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader\r
+Started\r
+.\r
+Finished in 0.002236 seconds.\r
+\r
+1 test, 1 assertion, 0 failures, 0 errors</tt></pre>\r
+</div></div>\r
+<div class="para"><p>By default the setup above runs your tests with sqlite or sqlite3.  To run tests with one of the other connection strings specified in database.yml, pass the DB environment variable to rake:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>rake DB=sqlite\r
+rake DB=sqlite3\r
+rake DB=mysql\r
+rake DB=postgresql</tt></pre>\r
+</div></div>\r
+<div class="para"><p>Now you are ready to test-drive your plugin!</p></div>\r
+</div>\r
+<h2 id="_extending_core_classes">2. Extending core classes</h2>\r
+<div class="sectionbody">\r
+<div class="para"><p>This section will explain how to add a method to String that will be available anywhere in your rails app by:</p></div>\r
+<div class="ilist"><ul>\r
+<li>\r
+<p>\r
+Writing tests for the desired behavior\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Creating and requiring the correct files\r
+</p>\r
+</li>\r
+</ul></div>\r
+<h3 id="_creating_the_test">2.1. Creating the test</h3>\r
+<div class="para"><p>In this example you will add a method to String named <tt>to_squawk</tt>.  To begin, create a new test file with a few assertions:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/test/core_ext_test.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">'/test_helper.rb'</span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> CoreExtTest <span style="color: #990000">&lt;</span> Test<span style="color: #990000">::</span>Unit<span style="color: #990000">::</span>TestCase\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_to_squawk_prepends_the_word_squawk\r
+    assert_equal <span style="color: #FF0000">"squawk! Hello World"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"Hello World"</span><span style="color: #990000">.</span>to_squawk\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>Navigate to your plugin directory and run <tt>rake test</tt>:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>cd vendor/plugins/yaffle\r
+rake test</tt></pre>\r
+</div></div>\r
+<div class="para"><p>The test above should fail with the message:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt> 1) Error:\r
+test_to_squawk_prepends_the_word_squawk(CoreExtTest):\r
+NoMethodError: undefined method `to_squawk' for "Hello World":String\r
+    ./test/core_ext_test.rb:5:in `test_to_squawk_prepends_the_word_squawk'</tt></pre>\r
+</div></div>\r
+<div class="para"><p>Great - now you are ready to start development.</p></div>\r
+<h3 id="_organize_your_files">2.2. Organize your files</h3>\r
+<div class="para"><p>A common pattern in rails plugins is to set up the file structure like this:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>|-- lib\r
+|   |-- yaffle\r
+|   |   `-- core_ext.rb\r
+|   `-- yaffle.rb</tt></pre>\r
+</div></div>\r
+<div class="para"><p>The first thing we need to to is to require our <em>lib/yaffle.rb</em> file from <em>rails/init.rb</em>:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/rails/init.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'yaffle'</span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>Then in <em>lib/yaffle.rb</em> require <em>lib/core_ext.rb</em>:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/yaffle.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">"yaffle/core_ext"</span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>Finally, create the <em>core_ext.rb</em> file and add the <em>to_squawk</em> method:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/yaffle/core_ext.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt>String<span style="color: #990000">.</span>class_eval <span style="font-weight: bold"><span style="color: #0000FF">do</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> to_squawk\r
+    <span style="color: #FF0000">"squawk! #{self}"</span><span style="color: #990000">.</span>strip\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>To test that your method does what it says it does, run the unit tests with <tt>rake</tt> from your plugin directory.  To see this in action, fire up a console and start squawking:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>$ ./script/console\r
+&gt;&gt; "Hello World".to_squawk\r
+=&gt; "squawk! Hello World"</tt></pre>\r
+</div></div>\r
+<h3 id="_working_with_init_rb">2.3. Working with init.rb</h3>\r
+<div class="para"><p>When rails loads plugins it looks for the file named init.rb.  However, when the plugin is initialized, <em>init.rb</em> is invoked via <tt>eval</tt> (not <tt>require</tt>) so it has slightly different behavior.</p></div>\r
+<div class="para"><p>Under certain circumstances if you reopen classes or modules in <em>init.rb</em> you may inadvertently create a new class, rather than reopening an existing class.  A better alternative is to reopen the class in a different file, and require that file from <tt>init.rb</tt>, as shown above.</p></div>\r
+<div class="para"><p>If you must reopen a class in <tt>init.rb</tt> you can use <tt>module_eval</tt> or <tt>class_eval</tt> to avoid any issues:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/init.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt>Hash<span style="color: #990000">.</span>class_eval <span style="font-weight: bold"><span style="color: #0000FF">do</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> is_a_special_hash?\r
+    <span style="font-weight: bold"><span style="color: #0000FF">true</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>Another way is to explicitly define the top-level module space for all modules and classes, like <tt>::Hash</tt>:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/init.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> <span style="color: #990000">::</span>Hash\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> is_a_special_hash?\r
+    <span style="font-weight: bold"><span style="color: #0000FF">true</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+</div>\r
+<h2 id="_add_an_tt_acts_as_yaffle_tt_method_to_active_record">3. Add an <tt>acts_as_yaffle</tt> method to Active Record</h2>\r
+<div class="sectionbody">\r
+<div class="para"><p>A common pattern in plugins is to add a method called <em>acts_as_something</em> to models.  In this case, you want to write a method called <em>acts_as_yaffle</em> that adds a <em>squawk</em> method to your models.</p></div>\r
+<div class="para"><p>To begin, set up your files so that you have:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/test/acts_as_yaffle_test.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">'/test_helper.rb'</span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> ActsAsYaffleTest <span style="color: #990000">&lt;</span> Test<span style="color: #990000">::</span>Unit<span style="color: #990000">::</span>TestCase\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/yaffle.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'yaffle/acts_as_yaffle'</span>\r
+</tt></pre></div></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">module</span></span> Yaffle\r
+  <span style="font-style: italic"><span style="color: #9A1900"># your code will go here</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>Note that after requiring <em>acts_as_yaffle</em> you also have to include it into ActiveRecord::Base so that your plugin methods will be available to the rails models.</p></div>\r
+<div class="para"><p>One of the most common plugin patterns for <em>acts_as_yaffle</em> plugins is to structure your file like so:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">module</span></span> Yaffle\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> <span style="font-weight: bold"><span style="color: #0000FF">self</span></span><span style="color: #990000">.</span>included<span style="color: #990000">(</span>base<span style="color: #990000">)</span>\r
+    base<span style="color: #990000">.</span>send <span style="color: #990000">:</span>extend<span style="color: #990000">,</span> ClassMethods\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">module</span></span> ClassMethods\r
+    <span style="font-style: italic"><span style="color: #9A1900"># any method placed here will apply to classes, like Hickwall</span></span>\r
+    <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> acts_as_something\r
+      send <span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">include</span></span><span style="color: #990000">,</span> InstanceMethods\r
+    <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">module</span></span> InstanceMethods\r
+    <span style="font-style: italic"><span style="color: #9A1900"># any method placed here will apply to instaces, like @hickwall</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>With structure you can easily separate the methods that will be used for the class (like <tt>Hickwall.some_method</tt>) and the instance (like <tt>@hickwell.some_method</tt>).</p></div>\r
+<h3 id="_add_a_class_method">3.1. Add a class method</h3>\r
+<div class="para"><p>This plugin will expect that you've added a method to your model named <em>last_squawk</em>.  However, the plugin users might have already defined a method on their model named <em>last_squawk</em> that they use for something else.  This plugin will allow the name to be changed by adding a class method called <em>yaffle_text_field</em>.</p></div>\r
+<div class="para"><p>To start out, write a failing test that shows the behavior you'd like:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/test/acts_as_yaffle_test.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">'/test_helper.rb'</span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Hickwall <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base\r
+  acts_as_yaffle\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Wickwall <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base\r
+  acts_as_yaffle <span style="color: #990000">:</span>yaffle_text_field <span style="color: #990000">=&gt;</span> <span style="color: #990000">:</span>last_tweet\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> ActsAsYaffleTest <span style="color: #990000">&lt;</span> Test<span style="color: #990000">::</span>Unit<span style="color: #990000">::</span>TestCase\r
+  load_schema\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_a_hickwalls_yaffle_text_field_should_be_last_squawk\r
+    assert_equal <span style="color: #FF0000">"last_squawk"</span><span style="color: #990000">,</span> Hickwall<span style="color: #990000">.</span>yaffle_text_field\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_a_wickwalls_yaffle_text_field_should_be_last_tweet\r
+    assert_equal <span style="color: #FF0000">"last_tweet"</span><span style="color: #990000">,</span> Wickwall<span style="color: #990000">.</span>yaffle_text_field\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>To make these tests pass, you could modify your <tt>acts_as_yaffle</tt> file like so:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">module</span></span> Yaffle\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> <span style="font-weight: bold"><span style="color: #0000FF">self</span></span><span style="color: #990000">.</span>included<span style="color: #990000">(</span>base<span style="color: #990000">)</span>\r
+    base<span style="color: #990000">.</span>send <span style="color: #990000">:</span>extend<span style="color: #990000">,</span> ClassMethods\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">module</span></span> ClassMethods\r
+    <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> acts_as_yaffle<span style="color: #990000">(</span>options <span style="color: #990000">=</span> <span style="color: #FF0000">{}</span><span style="color: #990000">)</span>\r
+      cattr_accessor <span style="color: #990000">:</span>yaffle_text_field\r
+      <span style="font-weight: bold"><span style="color: #0000FF">self</span></span><span style="color: #990000">.</span>yaffle_text_field <span style="color: #990000">=</span> <span style="color: #990000">(</span>options<span style="color: #990000">[:</span>yaffle_text_field<span style="color: #990000">]</span> <span style="color: #990000">||</span> <span style="color: #990000">:</span>last_squawk<span style="color: #990000">).</span>to_s\r
+    <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+ActiveRecord<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>send <span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">include</span></span><span style="color: #990000">,</span> Yaffle\r
+</tt></pre></div></div>\r
+<h3 id="_add_an_instance_method">3.2. Add an instance method</h3>\r
+<div class="para"><p>This plugin will add a method named <em>squawk</em> to any Active Record objects that call <em>acts_as_yaffle</em>.  The <em>squawk</em> method will simply set the value of one of the fields in the database.</p></div>\r
+<div class="para"><p>To start out, write a failing test that shows the behavior you'd like:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/test/acts_as_yaffle_test.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">'/test_helper.rb'</span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Hickwall <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base\r
+  acts_as_yaffle\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Wickwall <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base\r
+  acts_as_yaffle <span style="color: #990000">:</span>yaffle_text_field <span style="color: #990000">=&gt;</span> <span style="color: #990000">:</span>last_tweet\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> ActsAsYaffleTest <span style="color: #990000">&lt;</span> Test<span style="color: #990000">::</span>Unit<span style="color: #990000">::</span>TestCase\r
+  load_schema\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_a_hickwalls_yaffle_text_field_should_be_last_squawk\r
+    assert_equal <span style="color: #FF0000">"last_squawk"</span><span style="color: #990000">,</span> Hickwall<span style="color: #990000">.</span>yaffle_text_field\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_a_wickwalls_yaffle_text_field_should_be_last_tweet\r
+    assert_equal <span style="color: #FF0000">"last_tweet"</span><span style="color: #990000">,</span> Wickwall<span style="color: #990000">.</span>yaffle_text_field\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_hickwalls_squawk_should_populate_last_squawk\r
+    hickwall <span style="color: #990000">=</span> Hickwall<span style="color: #990000">.</span>new\r
+    hickwall<span style="color: #990000">.</span>squawk<span style="color: #990000">(</span><span style="color: #FF0000">"Hello World"</span><span style="color: #990000">)</span>\r
+    assert_equal <span style="color: #FF0000">"squawk! Hello World"</span><span style="color: #990000">,</span> hickwall<span style="color: #990000">.</span>last_squawk\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_wickwalls_squawk_should_populate_last_tweeted_at\r
+    wickwall <span style="color: #990000">=</span> Wickwall<span style="color: #990000">.</span>new\r
+    wickwall<span style="color: #990000">.</span>squawk<span style="color: #990000">(</span><span style="color: #FF0000">"Hello World"</span><span style="color: #990000">)</span>\r
+    assert_equal <span style="color: #FF0000">"squawk! Hello World"</span><span style="color: #990000">,</span> wickwall<span style="color: #990000">.</span>last_tweet\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>Run this test to make sure the last two tests fail, then update <em>acts_as_yaffle.rb</em> to look like this:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">module</span></span> Yaffle\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> <span style="font-weight: bold"><span style="color: #0000FF">self</span></span><span style="color: #990000">.</span>included<span style="color: #990000">(</span>base<span style="color: #990000">)</span>\r
+    base<span style="color: #990000">.</span>send <span style="color: #990000">:</span>extend<span style="color: #990000">,</span> ClassMethods\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">module</span></span> ClassMethods\r
+    <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> acts_as_yaffle<span style="color: #990000">(</span>options <span style="color: #990000">=</span> <span style="color: #FF0000">{}</span><span style="color: #990000">)</span>\r
+      cattr_accessor <span style="color: #990000">:</span>yaffle_text_field\r
+      <span style="font-weight: bold"><span style="color: #0000FF">self</span></span><span style="color: #990000">.</span>yaffle_text_field <span style="color: #990000">=</span> <span style="color: #990000">(</span>options<span style="color: #990000">[:</span>yaffle_text_field<span style="color: #990000">]</span> <span style="color: #990000">||</span> <span style="color: #990000">:</span>last_squawk<span style="color: #990000">).</span>to_s\r
+      send <span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">include</span></span><span style="color: #990000">,</span> InstanceMethods\r
+    <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">module</span></span> InstanceMethods\r
+    <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> squawk<span style="color: #990000">(</span>string<span style="color: #990000">)</span>\r
+      write_attribute<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">self</span></span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #0000FF">class</span></span><span style="color: #990000">.</span>yaffle_text_field<span style="color: #990000">,</span> string<span style="color: #990000">.</span>to_squawk<span style="color: #990000">)</span>\r
+    <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+ActiveRecord<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>send <span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">include</span></span><span style="color: #990000">,</span> Yaffle\r
+</tt></pre></div></div>\r
+<div class="admonitionblock">\r
+<table><tr>\r
+<td class="icon">\r
+<img src="./images/icons/note.png" alt="Note" />\r
+</td>\r
+<td class="content">\r
+<div class="title">Editor's note:</div>The use of <tt>write_attribute</tt> to write to the field in model is just one example of how a plugin can interact with the model, and will not always be the right method to use.  For example, you could also use <tt>send("#{self.class.yaffle_text_field}=", string.to_squawk)</tt>.</td>\r
+</tr></table>\r
+</div>\r
+</div>\r
+<h2 id="_create_a_generator">4. Create a generator</h2>\r
+<div class="sectionbody">\r
+<div class="para"><p>Many plugins ship with generators.  When you created the plugin above, you specified the &#8212;with-generator option, so you already have the generator stubs in <em>vendor/plugins/yaffle/generators/yaffle</em>.</p></div>\r
+<div class="para"><p>Building generators is a complex topic unto itself and this section will cover one small aspect of generators:  creating a generator that adds a time-stamped migration.</p></div>\r
+<div class="para"><p>To create a generator you must:</p></div>\r
+<div class="ilist"><ul>\r
+<li>\r
+<p>\r
+Add your instructions to the <em>manifest</em> method of the generator\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Add any necessary template files to the templates directory\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Test the generator manually by running various combinations of <tt>script/generate</tt> and <tt>script/destroy</tt>\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Update the USAGE file to add helpful documentation for your generator\r
+</p>\r
+</li>\r
+</ul></div>\r
+<h3 id="_testing_generators">4.1. Testing generators</h3>\r
+<div class="para"><p>Many rails plugin authors do not test their generators, however testing generators is quite simple.  A typical generator test does the following:</p></div>\r
+<div class="ilist"><ul>\r
+<li>\r
+<p>\r
+Creates a new fake rails root directory that will serve as destination\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Runs the generator forward and backward, making whatever assertions are necessary\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Removes the fake rails root\r
+</p>\r
+</li>\r
+</ul></div>\r
+<div class="para"><p>For the generator in this section, the test could look something like this:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/test/yaffle_generator_test.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">'/test_helper.rb'</span>\r
+<span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'rails_generator'</span>\r
+<span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'rails_generator/scripts/generate'</span>\r
+<span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'rails_generator/scripts/destroy'</span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> GeneratorTest <span style="color: #990000">&lt;</span> Test<span style="color: #990000">::</span>Unit<span style="color: #990000">::</span>TestCase\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> fake_rails_root\r
+    File<span style="color: #990000">.</span>join<span style="color: #990000">(</span>File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">),</span> <span style="color: #FF0000">'rails_root'</span><span style="color: #990000">)</span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> file_list\r
+    Dir<span style="color: #990000">.</span>glob<span style="color: #990000">(</span>File<span style="color: #990000">.</span>join<span style="color: #990000">(</span>fake_rails_root<span style="color: #990000">,</span> <span style="color: #FF0000">"db"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"migrate"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"*"</span><span style="color: #990000">))</span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> setup\r
+    FileUtils<span style="color: #990000">.</span>mkdir_p<span style="color: #990000">(</span>fake_rails_root<span style="color: #990000">)</span>\r
+    <span style="color: #009900">@original_files</span> <span style="color: #990000">=</span> file_list\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> teardown\r
+    FileUtils<span style="color: #990000">.</span>rm_r<span style="color: #990000">(</span>fake_rails_root<span style="color: #990000">)</span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_generates_correct_file_name\r
+    Rails<span style="color: #990000">::</span>Generator<span style="color: #990000">::</span>Scripts<span style="color: #990000">::</span>Generate<span style="color: #990000">.</span>new<span style="color: #990000">.</span>run<span style="color: #990000">([</span><span style="color: #FF0000">"yaffle"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"bird"</span><span style="color: #990000">],</span> <span style="color: #990000">:</span>destination <span style="color: #990000">=&gt;</span> fake_rails_root<span style="color: #990000">)</span>\r
+    new_file <span style="color: #990000">=</span> <span style="color: #990000">(</span>file_list <span style="color: #990000">-</span> <span style="color: #009900">@original_files</span><span style="color: #990000">).</span>first\r
+    assert_match <span style="color: #FF6600">/add_yaffle_fields_to_bird/</span><span style="color: #990000">,</span> new_file\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>You can run <em>rake</em> from the plugin directory to see this fail.  Unless you are doing more advanced generator commands it typically suffices to just test the Generate script, and trust that rails will handle the Destroy and Update commands for you.</p></div>\r
+<h3 id="_adding_to_the_manifest">4.2. Adding to the manifest</h3>\r
+<div class="para"><p>This example will demonstrate how to use one of the built-in generator methods named <em>migration_template</em> to create a migration file.  To start, update your generator file to look like this:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> YaffleGenerator <span style="color: #990000">&lt;</span> Rails<span style="color: #990000">::</span>Generator<span style="color: #990000">::</span>NamedBase\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> manifest\r
+    record <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>m<span style="color: #990000">|</span>\r
+      m<span style="color: #990000">.</span>migration_template <span style="color: #FF0000">'migration:migration.rb'</span><span style="color: #990000">,</span> <span style="color: #FF0000">"db/migrate"</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span><span style="color: #990000">:</span>assigns <span style="color: #990000">=&gt;</span> yaffle_local_assigns<span style="color: #990000">,</span>\r
+        <span style="color: #990000">:</span>migration_file_name <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"add_yaffle_fields_to_#{custom_file_name}"</span>\r
+      <span style="color: #FF0000">}</span>\r
+    <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  private\r
+    <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> custom_file_name\r
+      custom_name <span style="color: #990000">=</span> class_name<span style="color: #990000">.</span>underscore<span style="color: #990000">.</span>downcase\r
+      custom_name <span style="color: #990000">=</span> custom_name<span style="color: #990000">.</span>pluralize <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> ActiveRecord<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>pluralize_table_names\r
+    <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+    <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> yaffle_local_assigns\r
+      returning<span style="color: #990000">(</span>assigns <span style="color: #990000">=</span> <span style="color: #FF0000">{}</span><span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span>\r
+        assigns<span style="color: #990000">[:</span>migration_action<span style="color: #990000">]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">"add"</span>\r
+        assigns<span style="color: #990000">[:</span>class_name<span style="color: #990000">]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">"add_yaffle_fields_to_#{custom_file_name}"</span>\r
+        assigns<span style="color: #990000">[:</span>table_name<span style="color: #990000">]</span> <span style="color: #990000">=</span> custom_file_name\r
+        assigns<span style="color: #990000">[:</span>attributes<span style="color: #990000">]</span> <span style="color: #990000">=</span> <span style="color: #990000">[</span>Rails<span style="color: #990000">::</span>Generator<span style="color: #990000">::</span>GeneratedAttribute<span style="color: #990000">.</span>new<span style="color: #990000">(</span><span style="color: #FF0000">"last_squawk"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"string"</span><span style="color: #990000">)]</span>\r
+      <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+    <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>The generator creates a new file in <em>db/migrate</em> with a timestamp and an <em>add_column</em> statement.  It reuses the built in rails <tt>migration_template</tt> method, and reuses the built-in rails migration template.</p></div>\r
+<div class="para"><p>It's courteous to check to see if table names are being pluralized whenever you create a generator that needs to be aware of table names.  This way people using your generator won't have to manually change the generated files if they've turned pluralization off.</p></div>\r
+<h3 id="_manually_test_the_generator">4.3. Manually test the generator</h3>\r
+<div class="para"><p>To run the generator, type the following at the command line:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>./script/generate yaffle bird</tt></pre>\r
+</div></div>\r
+<div class="para"><p>and you will see a new file:</p></div>\r
+<div class="para"><p><strong>db/migrate/20080529225649_add_yaffle_fields_to_birds.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> AddYaffleFieldsToBirds <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Migration\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> <span style="font-weight: bold"><span style="color: #0000FF">self</span></span><span style="color: #990000">.</span>up\r
+    add_column <span style="color: #990000">:</span>birds<span style="color: #990000">,</span> <span style="color: #990000">:</span>last_squawk<span style="color: #990000">,</span> <span style="color: #990000">:</span>string\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> <span style="font-weight: bold"><span style="color: #0000FF">self</span></span><span style="color: #990000">.</span>down\r
+    remove_column <span style="color: #990000">:</span>birds<span style="color: #990000">,</span> <span style="color: #990000">:</span>last_squawk\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<h3 id="_the_usage_file">4.4. The USAGE file</h3>\r
+<div class="para"><p>Rails ships with several built-in generators.  You can see all of the generators available to you by typing the following at the command line:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>script/generate</tt></pre>\r
+</div></div>\r
+<div class="para"><p>You should see something like this:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>Installed Generators\r
+  Plugins (vendor/plugins): yaffle\r
+  Builtin: controller, integration_test, mailer, migration, model, observer, plugin, resource, scaffold, session_migration</tt></pre>\r
+</div></div>\r
+<div class="para"><p>When you run <tt>script/generate yaffle</tt> you should see the contents of your <em>vendor/plugins/yaffle/generators/yaffle/USAGE</em> file.</p></div>\r
+<div class="para"><p>For this plugin, update the USAGE file looks like this:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>Description:\r
+    Creates a migration that adds yaffle squawk fields to the given model\r
+\r
+Example:\r
+    ./script/generate yaffle hickwall\r
+\r
+    This will create:\r
+        db/migrate/TIMESTAMP_add_yaffle_fields_to_hickwall</tt></pre>\r
+</div></div>\r
+</div>\r
+<h2 id="_add_a_custom_generator_command">5. Add a custom generator command</h2>\r
+<div class="sectionbody">\r
+<div class="para"><p>You may have noticed above that you can used one of the built-in rails migration commands <tt>migration_template</tt>.  If your plugin needs to add and remove lines of text from existing files you will need to write your own generator methods.</p></div>\r
+<div class="para"><p>This section describes how you you can create your own commands to add and remove a line of text from <em>routes.rb</em>.  This example creates a very simple method that adds or removes a text file.</p></div>\r
+<div class="para"><p>To start, add the following test method:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/test/generator_test.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_generates_definition\r
+  Rails<span style="color: #990000">::</span>Generator<span style="color: #990000">::</span>Scripts<span style="color: #990000">::</span>Generate<span style="color: #990000">.</span>new<span style="color: #990000">.</span>run<span style="color: #990000">([</span><span style="color: #FF0000">"yaffle"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"bird"</span><span style="color: #990000">],</span> <span style="color: #990000">:</span>destination <span style="color: #990000">=&gt;</span> fake_rails_root<span style="color: #990000">)</span>\r
+  definition <span style="color: #990000">=</span> File<span style="color: #990000">.</span>read<span style="color: #990000">(</span>File<span style="color: #990000">.</span>join<span style="color: #990000">(</span>fake_rails_root<span style="color: #990000">,</span> <span style="color: #FF0000">"definition.txt"</span><span style="color: #990000">))</span>\r
+  assert_match <span style="color: #FF6600">/Yaffle\:/</span><span style="color: #990000">,</span> definition\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>Run <tt>rake</tt> to watch the test fail, then make the test pass add the following:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/generators/yaffle/templates/definition.txt</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>Yaffle: A bird</tt></pre>\r
+</div></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/yaffle.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">"yaffle/commands"</span>\r
+</tt></pre></div></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/commands.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'rails_generator'</span>\r
+<span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'rails_generator/commands'</span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">module</span></span> Yaffle <span style="font-style: italic"><span style="color: #9A1900">#:nodoc:</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">module</span></span> Generator <span style="font-style: italic"><span style="color: #9A1900">#:nodoc:</span></span>\r
+    <span style="font-weight: bold"><span style="color: #0000FF">module</span></span> Commands <span style="font-style: italic"><span style="color: #9A1900">#:nodoc:</span></span>\r
+      <span style="font-weight: bold"><span style="color: #0000FF">module</span></span> Create\r
+        <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> yaffle_definition\r
+          file<span style="color: #990000">(</span><span style="color: #FF0000">"definition.txt"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"definition.txt"</span><span style="color: #990000">)</span>\r
+        <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+      <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+      <span style="font-weight: bold"><span style="color: #0000FF">module</span></span> Destroy\r
+        <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> yaffle_definition\r
+          file<span style="color: #990000">(</span><span style="color: #FF0000">"definition.txt"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"definition.txt"</span><span style="color: #990000">)</span>\r
+        <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+      <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+      <span style="font-weight: bold"><span style="color: #0000FF">module</span></span> List\r
+        <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> yaffle_definition\r
+          file<span style="color: #990000">(</span><span style="color: #FF0000">"definition.txt"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"definition.txt"</span><span style="color: #990000">)</span>\r
+        <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+      <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+      <span style="font-weight: bold"><span style="color: #0000FF">module</span></span> Update\r
+        <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> yaffle_definition\r
+          file<span style="color: #990000">(</span><span style="color: #FF0000">"definition.txt"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"definition.txt"</span><span style="color: #990000">)</span>\r
+        <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+      <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+    <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+Rails<span style="color: #990000">::</span>Generator<span style="color: #990000">::</span>Commands<span style="color: #990000">::</span>Create<span style="color: #990000">.</span>send   <span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">include</span></span><span style="color: #990000">,</span>  Yaffle<span style="color: #990000">::</span>Generator<span style="color: #990000">::</span>Commands<span style="color: #990000">::</span>Create\r
+Rails<span style="color: #990000">::</span>Generator<span style="color: #990000">::</span>Commands<span style="color: #990000">::</span>Destroy<span style="color: #990000">.</span>send  <span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">include</span></span><span style="color: #990000">,</span>  Yaffle<span style="color: #990000">::</span>Generator<span style="color: #990000">::</span>Commands<span style="color: #990000">::</span>Destroy\r
+Rails<span style="color: #990000">::</span>Generator<span style="color: #990000">::</span>Commands<span style="color: #990000">::</span>List<span style="color: #990000">.</span>send     <span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">include</span></span><span style="color: #990000">,</span>  Yaffle<span style="color: #990000">::</span>Generator<span style="color: #990000">::</span>Commands<span style="color: #990000">::</span>List\r
+Rails<span style="color: #990000">::</span>Generator<span style="color: #990000">::</span>Commands<span style="color: #990000">::</span>Update<span style="color: #990000">.</span>send   <span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">include</span></span><span style="color: #990000">,</span>  Yaffle<span style="color: #990000">::</span>Generator<span style="color: #990000">::</span>Commands<span style="color: #990000">::</span>Update\r
+</tt></pre></div></div>\r
+<div class="para"><p>Finally, call your new method in the manifest:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> YaffleGenerator <span style="color: #990000">&lt;</span> Rails<span style="color: #990000">::</span>Generator<span style="color: #990000">::</span>NamedBase\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> manifest\r
+    m<span style="color: #990000">.</span>yaffle_definition\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+</div>\r
+<h2 id="_add_a_model">6. Add a model</h2>\r
+<div class="sectionbody">\r
+<div class="para"><p>This section describes how to add a model named <em>Woodpecker</em> to your plugin that will behave the same as a model in your main app.  When storing models, controllers, views and helpers in your plugin, it's customary to keep them in directories that match the rails directories.  For this example, create a file structure like this:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>vendor/plugins/yaffle/\r
+|-- lib\r
+|   |-- app\r
+|   |   |-- controllers\r
+|   |   |-- helpers\r
+|   |   |-- models\r
+|   |   |   `-- woodpecker.rb\r
+|   |   `-- views\r
+|   |-- yaffle\r
+|   |   |-- acts_as_yaffle.rb\r
+|   |   |-- commands.rb\r
+|   |   `-- core_ext.rb\r
+|   `-- yaffle.rb</tt></pre>\r
+</div></div>\r
+<div class="para"><p>As always, start with a test:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/yaffle/woodpecker_test.rb:</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">'/test_helper.rb'</span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> WoodpeckerTest <span style="color: #990000">&lt;</span> Test<span style="color: #990000">::</span>Unit<span style="color: #990000">::</span>TestCase\r
+  load_schema\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_woodpecker\r
+    assert_kind_of Woodpecker<span style="color: #990000">,</span> Woodpecker<span style="color: #990000">.</span>new\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>This is just a simple test to make sure the class is being loaded correctly.  After watching it fail with <tt>rake</tt>, you can make it pass like so:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/yaffle.rb:</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="color: #990000">%</span>w<span style="color: #FF0000">{</span> models <span style="color: #FF0000">}</span><span style="color: #990000">.</span>each <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>dir<span style="color: #990000">|</span>\r
+  path <span style="color: #990000">=</span> File<span style="color: #990000">.</span>join<span style="color: #990000">(</span>File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">),</span> <span style="color: #FF0000">'app'</span><span style="color: #990000">,</span> dir<span style="color: #990000">)</span>\r
+  <span style="color: #009900">$LOAD_PATH</span> <span style="color: #990000">&lt;&lt;</span> path\r
+  ActiveSupport<span style="color: #990000">::</span>Dependencies<span style="color: #990000">.</span>load_paths <span style="color: #990000">&lt;&lt;</span> path\r
+  ActiveSupport<span style="color: #990000">::</span>Dependencies<span style="color: #990000">.</span>load_once_paths<span style="color: #990000">.</span>delete<span style="color: #990000">(</span>path<span style="color: #990000">)</span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>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 <em>load_once_paths</em> 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.</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/app/models/woodpecker.rb:</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Woodpecker <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>Finally, add the following to your plugin's <em>schema.rb</em>:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/test/schema.rb:</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt>ActiveRecord<span style="color: #990000">::</span>Schema<span style="color: #990000">.</span>define<span style="color: #990000">(:</span>version <span style="color: #990000">=&gt;</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span>\r
+  create_table <span style="color: #990000">:</span>woodpeckers<span style="color: #990000">,</span> <span style="color: #990000">:</span>force <span style="color: #990000">=&gt;</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>t<span style="color: #990000">|</span>\r
+    t<span style="color: #990000">.</span>string <span style="color: #990000">:</span>name\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>Now your test should be passing, and you should be able to use the Woodpecker model from within your rails app, and any changes made to it are reflected immediately when running in development mode.</p></div>\r
+</div>\r
+<h2 id="_add_a_controller">7. Add a controller</h2>\r
+<div class="sectionbody">\r
+<div class="para"><p>This section describes how to add a controller named <em>woodpeckers</em> to your plugin that will behave the same as a controller in your main app.  This is very similar to adding a model.</p></div>\r
+<div class="para"><p>You can test your plugin's controller as you would test any other controller:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/yaffle/woodpeckers_controller_test.rb:</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">'/test_helper.rb'</span>\r
+<span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'woodpeckers_controller'</span>\r
+<span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'action_controller/test_process'</span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> WoodpeckersController<span style="color: #990000">;</span> <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> rescue_action<span style="color: #990000">(</span>e<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">raise</span></span> e <span style="font-weight: bold"><span style="color: #0000FF">end</span></span><span style="color: #990000">;</span> <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> WoodpeckersControllerTest <span style="color: #990000">&lt;</span> Test<span style="color: #990000">::</span>Unit<span style="color: #990000">::</span>TestCase\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> setup\r
+    <span style="color: #009900">@controller</span> <span style="color: #990000">=</span> WoodpeckersController<span style="color: #990000">.</span>new\r
+    <span style="color: #009900">@request</span> <span style="color: #990000">=</span> ActionController<span style="color: #990000">::</span>TestRequest<span style="color: #990000">.</span>new\r
+    <span style="color: #009900">@response</span> <span style="color: #990000">=</span> ActionController<span style="color: #990000">::</span>TestResponse<span style="color: #990000">.</span>new\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_index\r
+    get <span style="color: #990000">:</span>index\r
+    assert_response <span style="color: #990000">:</span>success\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>This is just a simple test to make sure the controller is being loaded correctly.  After watching it fail with <tt>rake</tt>, you can make it pass like so:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/yaffle.rb:</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="color: #990000">%</span>w<span style="color: #FF0000">{</span> models controllers <span style="color: #FF0000">}</span><span style="color: #990000">.</span>each <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>dir<span style="color: #990000">|</span>\r
+  path <span style="color: #990000">=</span> File<span style="color: #990000">.</span>join<span style="color: #990000">(</span>File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">),</span> <span style="color: #FF0000">'app'</span><span style="color: #990000">,</span> dir<span style="color: #990000">)</span>\r
+  <span style="color: #009900">$LOAD_PATH</span> <span style="color: #990000">&lt;&lt;</span> path\r
+  ActiveSupport<span style="color: #990000">::</span>Dependencies<span style="color: #990000">.</span>load_paths <span style="color: #990000">&lt;&lt;</span> path\r
+  ActiveSupport<span style="color: #990000">::</span>Dependencies<span style="color: #990000">.</span>load_once_paths<span style="color: #990000">.</span>delete<span style="color: #990000">(</span>path<span style="color: #990000">)</span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/app/controllers/woodpeckers_controller.rb:</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> WoodpeckersController <span style="color: #990000">&lt;</span> ActionController<span style="color: #990000">::</span>Base\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> index\r
+    render <span style="color: #990000">:</span>text <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"Squawk!"</span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>Now your test should be passing, and you should be able to use the Woodpeckers controller in your app.  If you add a route for the woodpeckers controller you can start up your server and go to <a href="http://localhost:3000/woodpeckers">http://localhost:3000/woodpeckers</a> to see your controller in action.</p></div>\r
+</div>\r
+<h2 id="_add_a_helper">8. Add a helper</h2>\r
+<div class="sectionbody">\r
+<div class="para"><p>This section describes how to add a helper named <em>WoodpeckersHelper</em> to your plugin that will behave the same as a helper in your main app.  This is very similar to adding a model and a controller.</p></div>\r
+<div class="para"><p>You can test your plugin's helper as you would test any other helper:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/test/woodpeckers_helper_test.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">'/test_helper.rb'</span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">include</span></span> WoodpeckersHelper\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> WoodpeckersHelperTest <span style="color: #990000">&lt;</span> Test<span style="color: #990000">::</span>Unit<span style="color: #990000">::</span>TestCase\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_tweet\r
+    assert_equal <span style="color: #FF0000">"Tweet! Hello"</span><span style="color: #990000">,</span> tweet<span style="color: #990000">(</span><span style="color: #FF0000">"Hello"</span><span style="color: #990000">)</span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>This is just a simple test to make sure the helper is being loaded correctly.  After watching it fail with <tt>rake</tt>, you can make it pass like so:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/yaffle.rb:</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="color: #990000">%</span>w<span style="color: #FF0000">{</span> models controllers helpers <span style="color: #FF0000">}</span><span style="color: #990000">.</span>each <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>dir<span style="color: #990000">|</span>\r
+  path <span style="color: #990000">=</span> File<span style="color: #990000">.</span>join<span style="color: #990000">(</span>File<span style="color: #990000">.</span>dirname<span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">__FILE__</span></span><span style="color: #990000">),</span> <span style="color: #FF0000">'app'</span><span style="color: #990000">,</span> dir<span style="color: #990000">)</span>\r
+  <span style="color: #009900">$LOAD_PATH</span> <span style="color: #990000">&lt;&lt;</span> path\r
+  ActiveSupport<span style="color: #990000">::</span>Dependencies<span style="color: #990000">.</span>load_paths <span style="color: #990000">&lt;&lt;</span> path\r
+  ActiveSupport<span style="color: #990000">::</span>Dependencies<span style="color: #990000">.</span>load_once_paths<span style="color: #990000">.</span>delete<span style="color: #990000">(</span>path<span style="color: #990000">)</span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+ActionView<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>send <span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">include</span></span><span style="color: #990000">,</span> WoodpeckersHelper\r
+</tt></pre></div></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/app/helpers/woodpeckers_helper.rb:</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">module</span></span> WoodpeckersHelper\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> tweet<span style="color: #990000">(</span>text<span style="color: #990000">)</span>\r
+    <span style="color: #FF0000">"Tweet! #{text}"</span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>Now your test should be passing, and you should be able to use the Woodpeckers helper in your app.</p></div>\r
+</div>\r
+<h2 id="_add_a_custom_route">9. Add a Custom Route</h2>\r
+<div class="sectionbody">\r
+<div class="para"><p>Testing routes in plugins can be complex, especially if the controllers are also in the plugin itself.  Jamis Buck showed a great example of this in <a href="http://weblog.jamisbuck.org/2006/10/26/monkey-patching-rails-extending-routes-2">http://weblog.jamisbuck.org/2006/10/26/monkey-patching-rails-extending-routes-2</a>.</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/test/routing_test.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">"#{File.dirname(__FILE__)}/test_helper"</span>\r
+\r
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> RoutingTest <span style="color: #990000">&lt;</span> Test<span style="color: #990000">::</span>Unit<span style="color: #990000">::</span>TestCase\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> setup\r
+    ActionController<span style="color: #990000">::</span>Routing<span style="color: #990000">::</span>Routes<span style="color: #990000">.</span>draw <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>map<span style="color: #990000">|</span>\r
+      map<span style="color: #990000">.</span>yaffles\r
+    <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_yaffles_route\r
+    assert_recognition <span style="color: #990000">:</span>get<span style="color: #990000">,</span> <span style="color: #FF0000">"/yaffles"</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>controller <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"yaffles_controller"</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>action <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"index"</span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+\r
+  private\r
+\r
+    <span style="font-style: italic"><span style="color: #9A1900"># yes, I know about assert_recognizes, but it has proven problematic to</span></span>\r
+    <span style="font-style: italic"><span style="color: #9A1900"># use in these tests, since it uses RouteSet#recognize (which actually</span></span>\r
+    <span style="font-style: italic"><span style="color: #9A1900"># tries to instantiate the controller) and because it uses an awkward</span></span>\r
+    <span style="font-style: italic"><span style="color: #9A1900"># parameter order.</span></span>\r
+    <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> assert_recognition<span style="color: #990000">(</span>method<span style="color: #990000">,</span> path<span style="color: #990000">,</span> options<span style="color: #990000">)</span>\r
+      result <span style="color: #990000">=</span> ActionController<span style="color: #990000">::</span>Routing<span style="color: #990000">::</span>Routes<span style="color: #990000">.</span>recognize_path<span style="color: #990000">(</span>path<span style="color: #990000">,</span> <span style="color: #990000">:</span>method <span style="color: #990000">=&gt;</span> method<span style="color: #990000">)</span>\r
+      assert_equal options<span style="color: #990000">,</span> result\r
+    <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/init.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">"routing"</span>\r
+ActionController<span style="color: #990000">::</span>Routing<span style="color: #990000">::</span>RouteSet<span style="color: #990000">::</span>Mapper<span style="color: #990000">.</span>send <span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">include</span></span><span style="color: #990000">,</span> Yaffle<span style="color: #990000">::</span>Routing<span style="color: #990000">::</span>MapperExtensions\r
+</tt></pre></div></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/lib/routing.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">module</span></span> Yaffle <span style="font-style: italic"><span style="color: #9A1900">#:nodoc:</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">module</span></span> Routing <span style="font-style: italic"><span style="color: #9A1900">#:nodoc:</span></span>\r
+    <span style="font-weight: bold"><span style="color: #0000FF">module</span></span> MapperExtensions\r
+      <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> yaffles\r
+        <span style="color: #009900">@set</span><span style="color: #990000">.</span>add_route<span style="color: #990000">(</span><span style="color: #FF0000">"/yaffles"</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span><span style="color: #990000">:</span>controller <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"yaffles_controller"</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>action <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"index"</span><span style="color: #FF0000">}</span><span style="color: #990000">)</span>\r
+      <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+    <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p><strong>config/routes.rb</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt>ActionController<span style="color: #990000">::</span>Routing<span style="color: #990000">::</span>Routes<span style="color: #990000">.</span>draw <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>map<span style="color: #990000">|</span>\r
+  <span style="color: #990000">...</span>\r
+  map<span style="color: #990000">.</span>yaffles\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>You can also see if your routes work by running <tt>rake routes</tt> from your app directory.</p></div>\r
+</div>\r
+<h2 id="_odds_and_ends">10. Odds and ends</h2>\r
+<div class="sectionbody">\r
+<h3 id="_generate_rdoc_documentation">10.1. Generate RDoc Documentation</h3>\r
+<div class="para"><p>Once your plugin is stable, the tests pass on all database and you are ready to deploy do everyone else a favor and document it!  Luckily, writing documentation for your plugin is easy.</p></div>\r
+<div class="para"><p>The first step is to update the README file with detailed information about how to use your plugin.  A few key things to include are:</p></div>\r
+<div class="ilist"><ul>\r
+<li>\r
+<p>\r
+Your name.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+How to install.\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+How to add the functionality to the app (several examples of common use cases).\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+Warning, gotchas or tips that might help save users time.\r
+</p>\r
+</li>\r
+</ul></div>\r
+<div class="para"><p>Once your README is solid, go through and add rdoc comments to all of the methods that developers will use.</p></div>\r
+<div class="para"><p>Before you generate your documentation, be sure to go through and add nodoc comments to those modules and methods that are not important to your users.</p></div>\r
+<div class="para"><p>Once your comments are good to go, navigate to your plugin directory and run:</p></div>\r
+<div class="literalblock">\r
+<div class="content">\r
+<pre><tt>rake rdoc</tt></pre>\r
+</div></div>\r
+<h3 id="_write_custom_rake_tasks_in_your_plugin">10.2. Write custom Rake tasks in your plugin</h3>\r
+<div class="para"><p>When you created the plugin with the built-in rails generator, it generated a rake file for you in <em>vendor/plugins/yaffle/tasks/yaffle.rake</em>.  Any rake task you add here will be available to the app.</p></div>\r
+<div class="para"><p>Many plugin authors put all of their rake tasks into a common namespace that is the same as the plugin, like so:</p></div>\r
+<div class="para"><p><strong>vendor/plugins/yaffle/tasks/yaffle.rake</strong></p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt>namespace <span style="color: #990000">:</span>yaffle <span style="font-weight: bold"><span style="color: #0000FF">do</span></span>\r
+  desc <span style="color: #FF0000">"Prints out the word 'Yaffle'"</span>\r
+  task <span style="color: #990000">:</span>squawk <span style="color: #990000">=&gt;</span> <span style="color: #990000">:</span>environment <span style="font-weight: bold"><span style="color: #0000FF">do</span></span>\r
+    puts <span style="color: #FF0000">"squawk!"</span>\r
+  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>\r
+</tt></pre></div></div>\r
+<div class="para"><p>When you run <tt>rake -T</tt> from your plugin you will see:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>yaffle:squawk             # Prints out the word 'Yaffle'</tt></pre>\r
+</div></div>\r
+<div class="para"><p>You can add as many files as you want in the tasks directory, and if they end in .rake Rails will pick them up.</p></div>\r
+<h3 id="_store_plugins_in_alternate_locations">10.3. Store plugins in alternate locations</h3>\r
+<div class="para"><p>You can store plugins wherever you want - you just have to add those plugins to the plugins path in <em>environment.rb</em>.</p></div>\r
+<div class="para"><p>Since the plugin is only loaded after the plugin paths are defined, you can't redefine this in your plugins - but it may be good to now.</p></div>\r
+<div class="para"><p>You can even store plugins inside of other plugins for complete plugin madness!</p></div>\r
+<div class="listingblock">\r
+<div class="content"><!-- Generator: GNU source-highlight 2.9\r
+by Lorenzo Bettini\r
+http://www.lorenzobettini.it\r
+http://www.gnu.org/software/src-highlite -->\r
+<pre><tt>config<span style="color: #990000">.</span>plugin_paths <span style="color: #990000">&lt;&lt;</span> File<span style="color: #990000">.</span>join<span style="color: #990000">(</span>RAILS_ROOT<span style="color: #990000">,</span><span style="color: #FF0000">"vendor"</span><span style="color: #990000">,</span><span style="color: #FF0000">"plugins"</span><span style="color: #990000">,</span><span style="color: #FF0000">"yaffle"</span><span style="color: #990000">,</span><span style="color: #FF0000">"lib"</span><span style="color: #990000">,</span><span style="color: #FF0000">"plugins"</span><span style="color: #990000">)</span>\r
+</tt></pre></div></div>\r
+<h3 id="_create_your_own_plugin_loaders_and_plugin_locators">10.4. Create your own Plugin Loaders and Plugin Locators</h3>\r
+<div class="para"><p>If the built-in plugin behavior is inadequate, you can change almost every aspect of the location and loading process.  You can write your own plugin locators and plugin loaders, but that's beyond the scope of this tutorial.</p></div>\r
+<h3 id="_use_custom_plugin_generators">10.5. Use Custom Plugin Generators</h3>\r
+<div class="para"><p>If you are an RSpec fan, you can install the <tt>rspec_plugin_generator</tt> gem, which will generate the spec folder and database for you. See <a href="http://github.com/pat-maddox/rspec-plugin-generator/tree/master">http://github.com/pat-maddox/rspec-plugin-generator/tree/master</a>.</p></div>\r
+</div>\r
+<h2 id="_appendix">11. Appendix</h2>\r
+<div class="sectionbody">\r
+<h3 id="_references">11.1. References</h3>\r
+<div class="ilist"><ul>\r
+<li>\r
+<p>\r
+<a href="http://nubyonrails.com/articles/the-complete-guide-to-rails-plugins-part-i">http://nubyonrails.com/articles/the-complete-guide-to-rails-plugins-part-i</a>\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+<a href="http://nubyonrails.com/articles/2006/05/09/the-complete-guide-to-rails-plugins-part-ii">http://nubyonrails.com/articles/2006/05/09/the-complete-guide-to-rails-plugins-part-ii</a>\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+<a href="http://github.com/technoweenie/attachment_fu/tree/master">http://github.com/technoweenie/attachment_fu/tree/master</a>\r
+</p>\r
+</li>\r
+<li>\r
+<p>\r
+<a href="http://daddy.platte.name/2007/05/rails-plugins-keep-initrb-thin.html">http://daddy.platte.name/2007/05/rails-plugins-keep-initrb-thin.html</a>\r
+</p>\r
+</li>\r
+</ul></div>\r
+<h3 id="_final_plugin_directory_structure">11.2. Final plugin directory structure</h3>\r
+<div class="para"><p>The final plugin should have a directory structure that looks something like this:</p></div>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>  |-- MIT-LICENSE\r
+  |-- README\r
+  |-- Rakefile\r
+  |-- generators\r
+  |   `-- yaffle\r
+  |       |-- USAGE\r
+  |       |-- templates\r
+  |       |   `-- definition.txt\r
+  |       `-- yaffle_generator.rb\r
+  |-- init.rb\r
+  |-- install.rb\r
+  |-- lib\r
+  |   |-- acts_as_yaffle.rb\r
+  |   |-- commands.rb\r
+  |   |-- core_ext.rb\r
+  |   |-- routing.rb\r
+  |   `-- view_helpers.rb\r
+  |-- tasks\r
+  |   `-- yaffle_tasks.rake\r
+  |-- test\r
+  |   |-- acts_as_yaffle_test.rb\r
+  |   |-- core_ext_test.rb\r
+  |   |-- database.yml\r
+  |   |-- debug.log\r
+  |   |-- routing_test.rb\r
+  |   |-- schema.rb\r
+  |   |-- test_helper.rb\r
+  |   `-- view_helpers_test.rb\r
+  |-- uninstall.rb\r
+  `-- yaffle_plugin.sqlite3.db</tt></pre>\r
+</div></div>\r
+</div>\r
+
+               </div>
+       </div>
+</body>
+</html>