Plugin Examples | 85
README
It is helpful to provide a short explanation here of the plugin??™s purpose, usage,
and any special instructions. A hook can be included in install.rb (described earlier)
to print this file upon plugin installation.
test/
This folder contains the plugin??™s tests. These tests are run using Rake, without
loading Rails. Any tests written in this folder must stand alone??”they must either
mock out any required Rails functionality or actually load the Rails framework.
We will explore both of these options later.
uninstall.rb (not shown)
This is the uninstall hook, run when a plugin is removed by tools such as
script/plugin or RaPT. Unless you have a very pressing need, the use of this file
is discouraged. Like install.rb, uninstall.rb is not always used??”many people simply
delete the plugin directory without thought.
Of course, you should feel free to add any folders required by your plugin. Use
File.dirname(_ _FILE_ _) in init.rb to refer to your plugin??™s directory as installed.
None of these files are specifically required; for example, a simple plugin may do all
of its work in init.rb.
You can generate a plugin skeleton with a built-in Rails generator:
$ script/generate plugin my_plugin
This generates a skeleton in vendor/plugins/my_plugin with sample files, a fill-in-theblanks
MIT license, and instructions.
Plugin Examples
To illustrate the flexibility and design of a typical Rails plugin, we will examine some
of the plugins available from the rubyonrails.
Pages:
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137