From 7f24653e7a39da9eb85b282e929d0712b2f1c9b7 Mon Sep 17 00:00:00 2001 From: Jeff Dean Date: Wed, 12 Nov 2008 01:48:02 -0500 Subject: Plugins guide: Cleanup the intro --- railties/doc/guides/html/creating_plugins.html | 112 +++++++++++-------------- 1 file changed, 48 insertions(+), 64 deletions(-) (limited to 'railties/doc/guides/html/creating_plugins.html') diff --git a/railties/doc/guides/html/creating_plugins.html b/railties/doc/guides/html/creating_plugins.html index 4c5f72c4d2..32bcab1359 100644 --- a/railties/doc/guides/html/creating_plugins.html +++ b/railties/doc/guides/html/creating_plugins.html @@ -267,113 +267,96 @@ ul#navMain {

The Basics of Creating Rails Plugins

-

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.

-

In this tutorial you will learn how to create a plugin that includes:

+

A Rails plugin is either an extension or a modification of the core framework. Plugins provide:

  • -Core Extensions - extending String with a to_squawk method: +a way for developers to share bleeding-edge ideas without hurting the stable code base

    -
    -
    -
    # Anywhere
    -"hello!".to_squawk # => "squawk! hello!"
    -
  • -An acts_as_yaffle method for ActiveRecord models that adds a squawk method: +a segmented architecture so that units of code can be fixed or updated on their own release schedule

    -
    -
    -
    class Hickwall < ActiveRecord::Base
    -  acts_as_yaffle :yaffle_text_field => :last_sang_at
    -end
    -
    -Hickwall.new.squawk("Hello World")
    -
  • -A view helper that will print out squawking info: +an outlet for the core developers so that they don’t have to include every cool new feature under the sun

    -
    -
    -
    squawk_info_for(@hickwall)
    -
  • +
+

After reading this guide you should be familiar with:

+
  • -A generator that creates a migration to add squawk columns to a model: +Creating a plugin from scratch

    -
    -
    -
    script/generate yaffle hickwall
    -
  • -A custom generator command: +Writing and running tests for the plugin

    -
    -
    -
    class YaffleGenerator < Rails::Generator::NamedBase
    -  def manifest
    -    m.yaffle_definition
    -  end
    -end
    -
  • -A custom route method: +Storing models, views, controllers, helpers and even other plugins in your plugins +

    +
  • +
  • +

    +Writing generators +

    +
  • +
  • +

    +Writing custom Rake tasks in your plugin +

    +
  • +
  • +

    +Generating RDoc documentation for your plugin +

    +
  • +
  • +

    +Avoiding common pitfalls with init.rb

    -
    -
    -
    ActionController::Routing::Routes.draw do |map|
    -  map.yaffles
    -end
    -
-

In addition you'll learn how to:

+

This guide describes how to build a test-driven plugin that will:

  • -test your plugins. +Extend core ruby classes like Hash and String +

    +
  • +
  • +

    +Add methods to ActiveRecord::Base in the tradition of the acts_as plugins +

    +
  • +
  • +

    +Add a view helper that can be used in erb templates

  • -work with init.rb, how to store model, views, controllers, helpers and even other plugins in your plugins. +Add a new generator that will generate a migration

  • -create documentation for your plugin. +Add a custom generator command

  • -write custom Rake tasks in your plugin. +A custom route method that can be used in routes.rb

+

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.

1. Preparation

@@ -590,7 +573,7 @@ Finished in 0.002236 seconds. 1 test, 1 assertion, 0 failures, 0 errors -

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:

+

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:

rake DB=sqlite
@@ -598,6 +581,7 @@ rake DB=sqlite3
 rake DB=mysql
 rake DB=postgresql
+

Now you are ready to test-drive your plugin!

2. Add a to_squawk method to String

-- cgit v1.2.3