parlement 0.10 → 0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +11 -0
- data/MEMORY +9 -1
- data/README +5 -4
- data/app/controllers/account_controller.rb +10 -13
- data/app/controllers/application.rb +4 -5
- data/app/controllers/elt_controller.rb +9 -7
- data/app/controllers/person_controller.rb +1 -3
- data/app/controllers/subscriber_controller.rb +10 -10
- data/app/helpers/elt_helper.rb +2 -0
- data/app/models/elt.rb +28 -19
- data/app/models/mail.rb +26 -14
- data/app/models/mail_notify.rb +5 -4
- data/app/models/person.rb +11 -2
- data/app/views/account/_login.rhtml +3 -3
- data/app/views/account/_show.rhtml +12 -14
- data/app/views/elt/_choice.rhtml +3 -3
- data/app/views/elt/_elt.rhtml +4 -4
- data/app/views/elt/_list.rhtml +2 -2
- data/app/views/elt/_listByDate.rhtml +1 -1
- data/app/views/elt/_listByVote.rhtml +1 -1
- data/app/views/elt/new.rhtml +3 -3
- data/app/views/elt/show.rhtml +2 -2
- data/app/views/layouts/top.rhtml +6 -0
- data/app/views/mail_notify/publish.text.html.rhtml +1 -1
- data/app/views/person/_listElts.rhtml +5 -3
- data/app/views/person/show.rhtml +1 -2
- data/config/boot.rb +5 -4
- data/config/environment.rb +6 -4
- data/config/routes.rb +3 -2
- data/db/development_structure.sql +15 -4
- data/db/migrate/006_last_activity.rb +10 -0
- data/db/schema.rb +67 -49
- data/public/dispatch.fcgi +1 -0
- data/public/javascripts/controls.js +41 -23
- data/public/javascripts/dragdrop.js +317 -99
- data/public/javascripts/effects.js +301 -166
- data/public/javascripts/prototype.js +932 -402
- data/public/stylesheets/default.css +3 -2
- data/test/unit/elt_test.rb +13 -0
- data/test/unit/mail_test.rb +3 -1
- data/vendor/plugins/engines/CHANGELOG +203 -99
- data/vendor/plugins/engines/MIT-LICENSE +1 -1
- data/vendor/plugins/engines/README +32 -384
- data/vendor/plugins/engines/Rakefile +14 -0
- data/vendor/plugins/engines/UPGRADING +93 -0
- data/vendor/plugins/engines/about.yml +7 -0
- data/vendor/plugins/engines/generators/plugin_migration/USAGE +45 -0
- data/vendor/plugins/engines/generators/plugin_migration/plugin_migration_generator.rb +79 -0
- data/vendor/plugins/engines/generators/plugin_migration/templates/plugin_migration.erb +13 -0
- data/vendor/plugins/engines/init.rb +34 -47
- data/vendor/plugins/engines/install.rb +32 -0
- data/vendor/plugins/engines/lib/engines/{ruby_extensions.rb → deprecated_config_support.rb} +135 -113
- data/vendor/plugins/engines/lib/engines/plugin.rb +214 -0
- data/vendor/plugins/engines/lib/engines/plugin_list.rb +31 -0
- data/vendor/plugins/engines/lib/engines/plugin_migrator.rb +60 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/active_record.rb +19 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/dependencies.rb +143 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/migrations.rb +155 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/public_asset_helpers.rb +116 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/rails.rb +20 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/rails_initializer.rb +86 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/routing.rb +77 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/templates.rb +140 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions.rb +6 -0
- data/vendor/plugins/engines/lib/engines/testing.rb +88 -0
- data/vendor/plugins/engines/lib/engines.rb +281 -425
- data/vendor/plugins/engines/tasks/engines.rake +108 -137
- metadata +218 -250
- data/db/ROOT/perso.txt +0 -214
- data/public/images/indicator.gif +0 -0
- data/public/images/orange_by_darren_Hester_350o.jpg +0 -0
- data/public/images/smile.png +0 -0
- data/vendor/plugins/engines/generators/engine/USAGE +0 -26
- data/vendor/plugins/engines/generators/engine/engine_generator.rb +0 -199
- data/vendor/plugins/engines/generators/engine/templates/README +0 -85
- data/vendor/plugins/engines/generators/engine/templates/init_engine.erb +0 -15
- data/vendor/plugins/engines/generators/engine/templates/install.erb +0 -4
- data/vendor/plugins/engines/generators/engine/templates/lib/engine.erb +0 -6
- data/vendor/plugins/engines/generators/engine/templates/licenses/GPL +0 -18
- data/vendor/plugins/engines/generators/engine/templates/licenses/LGPL +0 -19
- data/vendor/plugins/engines/generators/engine/templates/licenses/MIT +0 -22
- data/vendor/plugins/engines/generators/engine/templates/licenses/None +0 -1
- data/vendor/plugins/engines/generators/engine/templates/public/javascripts/engine.js +0 -0
- data/vendor/plugins/engines/generators/engine/templates/public/stylesheets/engine.css +0 -0
- data/vendor/plugins/engines/generators/engine/templates/tasks/engine.rake +0 -0
- data/vendor/plugins/engines/generators/engine/templates/test/test_helper.erb +0 -17
- data/vendor/plugins/engines/lib/bundles/require_resource.rb +0 -124
- data/vendor/plugins/engines/lib/bundles.rb +0 -77
- data/vendor/plugins/engines/lib/engines/action_mailer_extensions.rb +0 -140
- data/vendor/plugins/engines/lib/engines/action_view_extensions.rb +0 -141
- data/vendor/plugins/engines/lib/engines/active_record_extensions.rb +0 -21
- data/vendor/plugins/engines/lib/engines/dependencies_extensions.rb +0 -129
- data/vendor/plugins/engines/lib/engines/migration_extensions.rb +0 -53
- data/vendor/plugins/engines/lib/engines/routing_extensions.rb +0 -28
- data/vendor/plugins/engines/lib/engines/testing_extensions.rb +0 -327
- data/vendor/plugins/engines/tasks/deprecated_engines.rake +0 -7
- data/vendor/plugins/engines/test/action_view_extensions_test.rb +0 -9
- data/vendor/plugins/engines/test/ruby_extensions_test.rb +0 -115
- data/vendor/plugins/guid/README.TXT +0 -29
- data/vendor/plugins/guid/init.rb +0 -30
- data/vendor/plugins/guid/lib/usesguid.rb +0 -37
- data/vendor/plugins/guid/lib/uuid22.rb +0 -43
- data/vendor/plugins/guid/lib/uuidtools.rb +0 -572
- data/vendor/plugins/responds_to_parent/MIT-LICENSE +0 -20
- data/vendor/plugins/responds_to_parent/README +0 -42
- data/vendor/plugins/responds_to_parent/Rakefile +0 -22
- data/vendor/plugins/responds_to_parent/init.rb +0 -1
- data/vendor/plugins/responds_to_parent/lib/responds_to_parent.rb +0 -46
- data/vendor/plugins/responds_to_parent/test/responds_to_parent_test.rb +0 -115
@@ -1,414 +1,62 @@
|
|
1
|
-
|
1
|
+
The engines plugin enhances Rails' own plugin framework, making it simple to share controllers, helpers, models, public assets, routes and migrations in plugins.
|
2
2
|
|
3
|
-
|
3
|
+
For more information, see http://rails-engines.org
|
4
4
|
|
5
|
-
|
5
|
+
= Using the plugin
|
6
6
|
|
7
|
-
|
8
|
-
existing application without affecting *any* of your existing code. The could also be described as mini-applications, or vertical application slices - top-to-bottom units which provide full MVC coverage for a certain, specific application function.
|
7
|
+
With engines 1.2, no extra configuration in environment.rb is required. Having the plugin installed will automatically enable sharing of code within <tt>plugin/app/</tt> directories. Developers should be aware that the <tt>config.plugins</tt> parameter can be used to control plugin load order, if this is important for your application.
|
9
8
|
|
10
|
-
|
11
|
-
* controllers to manage user accounts;
|
12
|
-
* helpers for you to interact with account information from other
|
13
|
-
parts of your application;
|
14
|
-
* the model objects and schemas to create the required tables;
|
15
|
-
* stylesheets and javascript files to enhance the views;
|
16
|
-
* and any other library files required.
|
9
|
+
=== config.plugins
|
17
10
|
|
18
|
-
|
11
|
+
With Rails 1.2, the <tt>config.plugins</tt> list can be used to specify the order in which plugins are loaded. It's recommended (although not required) that you load the engines plugin first, and any other plugins later. The engines plugin enhances Rails' processing of <tt>config.plugins</tt> for occasions where you only care about the order of a small selection of your application's plugins. For instance, if you want to load +engines+ first, and anything else afterwards, then
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
= Edge Engines
|
25
|
-
|
26
|
-
If you are using Edge Rails (an SVN copy of Rails, rather than an 'official' release), there are several MASSIVELY IMPORTANT issues that you need to bear in mind.
|
27
|
-
|
28
|
-
Firstly, you are using an unstable version of Rails, so it is possible that things will break. We work hard to keep the Engines plugin up to speed with the changes in Rails at the bleeding edge, but sometimes significant parts of Rails change it WILL cause problems. This is the price of using the bleeding edge. Since edge is synonymous for unstable, the version of the Engines plugin which is compatible with Edge Rails is kept separate from the official release. Please ensure that you have used SVN to get your engines plugin from
|
29
|
-
|
30
|
-
http://svn.rails-engines.org/engines/trunk
|
31
|
-
|
32
|
-
The normal 'script/plugin install engines' will NOT get you this version.
|
33
|
-
|
34
|
-
Secondly, you NEED to tell the engines plugin if you expect it to perform with Edge behaviour. This is done by adding the following lines at the *very top* of environment.rb (yes, the VERY TOP)
|
35
|
-
|
36
|
-
module Engines
|
37
|
-
CONFIG = {:edge => true}
|
38
|
-
end
|
39
|
-
|
40
|
-
This will set the plugin to work with Edge Rails, rather than expecting an official release.
|
41
|
-
|
42
|
-
If you are having problems, please try and contribute a bug report if you can so we can improve the plugin and keep up to speed with Rails' bleeding edge. Your input is *absolutely crucial* to this. If you're not comfortable with tracking down bugs in Rails' and Engines' internal code, there is a test application available at
|
43
|
-
|
44
|
-
http://svn.rails-engines.org/applications/engines_test
|
13
|
+
config.plugins = ["engines", "*"]
|
45
14
|
|
46
|
-
|
47
|
-
|
48
|
-
Finally, please don't forget about our website and mailing lists. More information here:
|
49
|
-
|
50
|
-
http://rails-engines.org
|
15
|
+
will ensure that engines is loaded first, and everything else (in whatever order Rails chooses) afterwards.
|
51
16
|
|
17
|
+
== Better plugins
|
52
18
|
|
19
|
+
In addition to the regular set of plugin-supported files (lib, init.rb, tasks, generators, tests), plugins can carry the following when the engines plugin is also installed.
|
53
20
|
|
54
21
|
|
22
|
+
=== Controllers, Helpers, and Views
|
55
23
|
|
24
|
+
Include these files in an <tt>app</tt> directory just like you would in a normal Rails application. If you need to override a method, view or partial, create the corresponding file in your main <tt>app</tt> directory and it will be used instead.
|
56
25
|
|
26
|
+
* Controllers & Helpers: See Engines::RailsExtensions::Dependencies for more information.
|
27
|
+
* Views: See Engines::RailsExtensions::Templates for more information.
|
57
28
|
|
58
|
-
|
29
|
+
=== Models
|
59
30
|
|
60
|
-
|
31
|
+
Model code can similarly be placed in an <tt>app/models/</tt> directory. Unfortunately, it's not possible to automatically override methods within a model; if your application needs to change the way a model behaves, consider creating a subclass, or replacing the model entirely within your application's <tt>app/models/</tt> directory. See Engines::RailsExtensions::Dependencies for more information.
|
61
32
|
|
33
|
+
=== Routes
|
62
34
|
|
63
|
-
|
64
|
-
The Engines plugin comes with its own logger, which is invaluable when debugging. To use it,
|
65
|
-
simply call
|
66
|
-
|
67
|
-
Engines.create_logger
|
68
|
-
|
69
|
-
Two optional arguments may be passed to this method:
|
70
|
-
|
71
|
-
Engines.create_logger(<io>)
|
72
|
-
|
73
|
-
Would set the outputter to the logger to the given IO object <io>. For example, this could be STDERR or STDOUT (the default). The second argument is the logger level:
|
74
|
-
|
75
|
-
Engines.create_logger(STDOUT, Logger::INFO)
|
76
|
-
|
77
|
-
The logger can be accessed using either of the following:
|
35
|
+
Include your route declarations in a <tt>routes.rb</tt> file at the root of your plugins, e.g.:
|
78
36
|
|
79
|
-
|
80
|
-
|
37
|
+
connect "/my/url", :controller => "some_controller"
|
38
|
+
my_named_route "do_stuff", :controller => "blah", :action => "stuff"
|
39
|
+
# etc.
|
81
40
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
=== Engines.config(:root)
|
41
|
+
You can then load these files into your application by declaring their inclusion in the application's <tt>config/routes.rb</tt>:
|
86
42
|
|
87
|
-
|
43
|
+
map.from_plugin :plugin_name
|
88
44
|
|
89
|
-
|
45
|
+
See Engines::RailsExtensions::Routing for more information.
|
90
46
|
|
91
|
-
|
92
|
-
=== Rake Tasks
|
47
|
+
=== Migrations
|
93
48
|
|
94
|
-
|
49
|
+
Migrations record the changes in your database as your application evolves. With engines 1.2, migrations from plugins can also join in this evolution as first-class entities. To add migrations to a plugin, include a <tt>db/migrate/</tt> folder and add migrations there as normal. These migrations can then be integrated into the main flow of database evolution by running the plugin_migration generator:
|
95
50
|
|
96
|
-
|
97
|
-
rake engines:info
|
98
|
-
|
99
|
-
# migrate engines' database schemas in a controlled way
|
100
|
-
rake db:migrate:engines
|
51
|
+
script/generate plugin_migration
|
101
52
|
|
102
|
-
|
103
|
-
rake doc:engines
|
104
|
-
|
105
|
-
There are more, but you'll have to discover them yourself...
|
106
|
-
|
107
|
-
|
108
|
-
== More information
|
109
|
-
|
110
|
-
For more information about what you can do with the Engines plugin, you'll need to generate the documentation (rake plugindoc), or go to http://rails-engines.org. Good luck!
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
= Quickstart
|
120
|
-
|
121
|
-
=== Gentlemen, Start your Engines!
|
122
|
-
|
123
|
-
|
124
|
-
Here's an *example* of how you might go about using Rails Engines. Please bear in mind that actual Engines may differ from this, but these are the steps you will *typically* have to take. Refer to individual Engine documentation for specific installation instructions. Anyway, on with the show:
|
125
|
-
|
126
|
-
1. Install the Rails Engines plugin into your plugins directory. You'll probably need to accept the SSL certificate here for the OpenSVN servers. For example:
|
127
|
-
|
128
|
-
$ script/plugin install engines
|
129
|
-
|
130
|
-
or
|
131
|
-
|
132
|
-
$ svn co http://svn.rails-engines.org/plugins/engines <MY_RAILS_APP>/vendor/plugins/engines
|
133
|
-
|
134
|
-
2. Install your engine into the plugins directory in a similar way.
|
135
|
-
|
136
|
-
3. Create the RDoc for the engines plugin and for your engines so you know what's going on:
|
137
|
-
|
138
|
-
$ rake doc:plugins
|
139
|
-
$ rake doc:engines
|
140
|
-
|
141
|
-
4. Initialize any database schema provided. The Engine may provide Rake tasks to do this for you. Beware that accepting an Engine schema might affect any existing database tables you have installed! You are STRONGLY recommended to inspect the <tt>db/schema.rb</tt> file to see exactly what running it might change.
|
142
|
-
|
143
|
-
5. Add configuration to <tt>environment.rb</tt>:
|
144
|
-
e.g.
|
145
|
-
|
146
|
-
# Add your application configuration here
|
147
|
-
module MyEngine
|
148
|
-
config :top_speed, "MegaTurboFast"
|
149
|
-
end
|
150
|
-
|
151
|
-
Engines.start :my_engine
|
152
|
-
|
153
|
-
6. Run your server!
|
154
|
-
|
155
|
-
$ script/server
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
= Building an Engine
|
161
|
-
|
162
|
-
Here's a sample rails application with a detailed listing of an example engines as a concrete example:
|
163
|
-
|
164
|
-
RAILS_ROOT
|
165
|
-
|- app
|
166
|
-
|- lib
|
167
|
-
|- config
|
168
|
-
|- <... other directories ...>
|
169
|
-
|- vendor
|
170
|
-
|-plugins
|
171
|
-
|- engines <-- the engines plugin
|
172
|
-
|- some_other_plugin
|
173
|
-
|- my_engine <-- our example engine
|
174
|
-
|- init_engine.rb
|
175
|
-
|- app
|
176
|
-
| |- controllers
|
177
|
-
| |- models
|
178
|
-
| |- helpers
|
179
|
-
| |- views
|
180
|
-
|- db
|
181
|
-
|- tasks
|
182
|
-
|- lib
|
183
|
-
|- public
|
184
|
-
| |- javascripts
|
185
|
-
| |- stylesheets
|
186
|
-
|- test
|
187
|
-
|
188
|
-
|
189
|
-
The internal structure of an engine mirrors the familiar core of a Rails application, with most of the engine within the <tt>app</tt> subdirectory. Within <tt>app</tt>, the controllers, views and model objects behave just as you might expect if there in the top-level <tt>app</tt> directory.
|
190
|
-
|
191
|
-
When you call <tt>Engines.start :my_engine</tt> in <tt>environment.rb</tt> a few important bits of black magic voodoo happen:
|
192
|
-
* the engine's controllers, views and models are mixed in to your running Rails application;
|
193
|
-
* files in the <tt>lib</tt> directory of your engine (and subdirectories) are made available
|
194
|
-
to the rest of your system
|
195
|
-
* any directory structure in the folder <tt>public/</tt> within your engine is made available to the webserver
|
196
|
-
* the file <tt>init_engine.rb</tt> is loaded from within the engine - just like a plugin. The reason why engines need an init_engine.rb rather than an init.rb is because Rails' default plugin system might try and load an engine before the Engines plugin has been loaded, resulting in all manner of badness. Instead, Rails' skips over any engine plugins, and the Engines plugin handles initializing your Engines plugins when you 'start' each engine.
|
197
|
-
|
198
|
-
From within <tt>init_engine.rb</tt> you should load any libraries from your <tt>lib</tt> directory that your engine might need to function. You can also perform any configuration required.
|
199
|
-
|
200
|
-
=== Loading all Engines
|
201
|
-
|
202
|
-
Calling either Engines.start (with no arguments) or Engines.start_all will load all engines available. Please note that your plugin can only be *automatically* detected as an engine by the presence of an 'init_engine.rb' file, or if the engine is in a directory named <something>_engine, or <something>_bundle. If neither of these conditions hold, then your engine will not be loaded by Engines.start() (with no arguments) or Engines.start_all().
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
= Configuring Engines
|
211
|
-
|
212
|
-
Often your engine will require a number of configuration parameters set, some of which should be alterable by the user to reflect their particular needs. For example, a Login System might need a unique Salt value set to encrypt user passwords. This value should be unique to each application.
|
213
|
-
|
214
|
-
Engines provides a simple mechanism to handle this, and it's already been hinted at above. Within any module, a new method is now available: <tt>config</tt>. This method creates a special <tt>CONFIG</tt> Hash object within the Module it is called, and can be used to store your parameters. For a user to set these parameters, they should reopen the module (before the corresponding Engines.start call), as follows:
|
215
|
-
|
216
|
-
module MyModule
|
217
|
-
config :some_option, "really_important_value"
|
218
|
-
end
|
219
|
-
Engines.start :my_engine
|
220
|
-
|
221
|
-
Because this config value has been set before the Engine is started, subsequent attempts to set this config value will be ignored and the user-specified value used instead. Of course, there are situations where you *really* want to set the config value, even if it already exists. In such cases the config call can be changed to:
|
222
|
-
|
223
|
-
config :some_option, "no_THIS_really_important_value", :force
|
224
|
-
|
225
|
-
The additional parameter will force the new value to be used. For more information, see Module#config.
|
226
|
-
|
227
|
-
|
228
|
-
|
53
|
+
This will produce a migration in your application. Running this migration (via <tt>rake db:migrate</tt>, as normal) will migrate the database according to the latest migrations in each plugin. See Engines::RailsExtensions::Migrations for more information.
|
229
54
|
|
230
|
-
= Tweaking Engines
|
231
55
|
|
232
|
-
|
56
|
+
=== More powerful Rake tasks
|
233
57
|
|
58
|
+
The engines plugin enhances and adds to the suite of default rake tasks for working with plugins. The <tt>doc:plugins</tt> task now includes controllers, helpers and models under <tt>app</tt>, and anything other code found under the plugin's <tt>code_paths</tt> attribute. New testing tasks have been added to run unit, functional and integration tests from plugins, whilst making it easier to load fixtures from plugins. See Engines::Testing for more details about testing, and run
|
234
59
|
|
235
|
-
|
236
|
-
These are the simplest - just drop your customised view (or partial) into you <tt>/app/views</tt> directory in the corresponding location for the engine, and your view will be used in preference to the engine view. For example, if we have a ItemController with an action 'show', it will (normally) expect to find its view as <tt>report/show.rhtml</tt> in the <tt>views</tt> directory. The view is found in the engine at <tt>/vendor/engines/my_engine/app/views/report/show.rhtml</tt>. However, if you create the file <tt>/app/views/report/show.rhtml</tt>, that file will be used instead! The same goes for partials.
|
237
|
-
|
238
|
-
|
239
|
-
=== Controller Tweaks
|
240
|
-
You can override controller behaviour by replacing individual controller methods with your custom behaviour. Lets say that our ItemController's 'show' method isn't up to scratch, but the rest of it behaves just fine. To override the single method, create <tt>/app/controllers/item_controller.rb</tt>, just as if it were going to be a new controller in a regular Rails application. then, implement your show method as you would like it to happen.
|
241
|
-
|
242
|
-
... and that's it. Your custom code will be mixed in to the engine controller, replacing its old method with your custom code.
|
243
|
-
|
244
|
-
|
245
|
-
=== Model/Lib Tweaks
|
246
|
-
Alas, tweaking model objects isn't quite so easy (yet). If you need to change the behaviour of model objects, you'll need to copy the model file from the engine into <tt>/app/models</tt> and edit the methods yourself. Library code can be overridden in a similar way.
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
= Public Files
|
257
|
-
|
258
|
-
If the Engine includes a <tt>public</tt> directory, its contents will be mirrored into <tt>RAILS_ROOT/public/engine_files/<engine_name>/</tt> so that these files can be served by your webserver to browsers and users over the internet.
|
259
|
-
|
260
|
-
Engines also provides two convenience methods for loading stylesheets and javascript files in your layouts: <tt>engine_stylesheet</tt> and <tt>engine_javascript</tt>.
|
261
|
-
|
262
|
-
=== Engine Stylesheets
|
263
|
-
|
264
|
-
<%= engine_stylesheet "my_engine" %>
|
265
|
-
|
266
|
-
will include <tt>RAILS_ROOT/public/<engine_files>/my_engine/stylesheets/my_engine.css</tt> in your layout. If you have more than one stylesheet, you can include them in the same call:
|
267
|
-
|
268
|
-
<%= engine_stylesheet "my_engine", "stylesheet_2", "another_one" %>
|
269
|
-
|
270
|
-
will give you:
|
271
|
-
|
272
|
-
<link href="/engine_files/my_engine/stylesheets/my_engine.css" media="screen" rel="Stylesheet" type="text/css" />
|
273
|
-
<link href="/engine_files/my_engine/stylesheets/stylesheet_2.css" media="screen" rel="Stylesheet" type="text/css" />
|
274
|
-
<link href="/engine_files/my_engine/stylesheets/another_one.css" media="screen" rel="Stylesheet" type="text/css" />
|
275
|
-
|
276
|
-
in your rendered layout.
|
277
|
-
|
278
|
-
=== Engine Javascripts
|
279
|
-
|
280
|
-
The <tt>engine_javascript</tt> command works in exactly the same way as above.
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
= Databases and Engines
|
291
|
-
|
292
|
-
Engine schema information can be handled using similar mechanisms to your normal application schemas.
|
293
|
-
|
294
|
-
== CAVEAT EMPTOR!
|
295
|
-
|
296
|
-
I.E. Big Huge Warning In Flashing Lights.
|
297
|
-
|
298
|
-
PLEASE, PLEASE, PLEASE bear in mind that if you are letting someone
|
299
|
-
ELSE have a say in what tables you are using, you're basically opening
|
300
|
-
your application schema open to potential HAVOC. I cannot stress how
|
301
|
-
serious this is. It is YOUR responsibility to ensure that you trust
|
302
|
-
the schema and migration information, and that it's not going to drop
|
303
|
-
your whole database. You need to inspect these things. YOU do. If you
|
304
|
-
run these voodoo commands and your database essplodes because you
|
305
|
-
didn't double double double check what was going on, your embarassment
|
306
|
-
will be infinite. And your project will be skroo'd if the migration
|
307
|
-
is irreversible.
|
308
|
-
|
309
|
-
That said, if you are working in a team and you all trust each other,
|
310
|
-
which is hopefully true, this can be quite useful.
|
311
|
-
|
312
|
-
|
313
|
-
== Migrating Engines
|
314
|
-
|
315
|
-
To migrate all engines to the latest version:
|
316
|
-
|
317
|
-
rake db:migrate:engines
|
318
|
-
|
319
|
-
To migrate a single engine, for example the login engine:
|
320
|
-
|
321
|
-
rake db:migrate:engines ENGINE=login (or login_engine)
|
322
|
-
|
323
|
-
To migrate a single engine to a specific revision:
|
324
|
-
|
325
|
-
rake db:migrate:engines ENGINE=login VERSION=4
|
326
|
-
|
327
|
-
This:
|
328
|
-
|
329
|
-
rake db:migrate:engines VERSION=1
|
330
|
-
|
331
|
-
... will not work, because we felt it was too dangerous to allow ALL
|
332
|
-
engines to be migrated to a specific version, since such versions
|
333
|
-
might be incompatible.
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
= Testing Engines
|
342
|
-
|
343
|
-
The Engines plugin comes with mechanisms to help test Engines within a developer's own application. The testing extensions enable developers to load fixtures into specific
|
344
|
-
tables irrespective of the name of the fixtures file. This work is heavily based on
|
345
|
-
patches made by Duane Johnson (canadaduane), viewable at
|
346
|
-
http://dev.rubyonrails.org/ticket/1911
|
347
|
-
|
348
|
-
Engine developers should supply fixture files in the <engine>/test/fixtures directory
|
349
|
-
as normal. Within their tests, they should load the fixtures using the 'fixture' command
|
350
|
-
(rather than the normal 'fixtures' command). For example:
|
351
|
-
|
352
|
-
class UserTest < Test::Unit::TestCase
|
353
|
-
fixture :users, :table_name => LoginEngine.config(:user_table), :class_name => "User"
|
354
|
-
|
355
|
-
...
|
356
|
-
|
357
|
-
This will ensure that the fixtures/users.yml file will get loaded into the correct
|
358
|
-
table, and will use the correct model object class.
|
359
|
-
|
360
|
-
Your engine should provide a test_helper.rb file in <engine>/test, the contents of which should include the following:
|
361
|
-
|
362
|
-
# Load the default rails test helper - this will load the environment.
|
363
|
-
require File.dirname(__FILE__) + '/../../../../test/test_helper'
|
364
|
-
|
365
|
-
# ensure that the Engines testing enhancements are loaded and will override Rails own
|
366
|
-
# code where needed. This line is very important!
|
367
|
-
require File.join(Engines.config(:root), "engines", "lib", "testing_extensions")
|
368
|
-
|
369
|
-
# Load the schema - if migrations have been performed, this will be up to date.
|
370
|
-
load(File.dirname(__FILE__) + "/../db/schema.rb")
|
371
|
-
|
372
|
-
# set up the fixtures location to use your engine's fixtures
|
373
|
-
Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
|
374
|
-
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
|
375
|
-
|
376
|
-
== Loading Fixtures
|
377
|
-
|
378
|
-
An additional helpful task for loading fixture data is also provided (thanks to Joe Van Dyk):
|
379
|
-
|
380
|
-
rake db:fixtures:engines:load
|
381
|
-
rake db:fixtures:engines:load PLUGIN=login_engine
|
60
|
+
rake -T
|
382
61
|
|
383
|
-
|
384
|
-
|
385
|
-
=== Important Caveat
|
386
|
-
Unlike the new 'fixture' directive described above, this task currently relies on you ensuring that the table name to load fixtures into is the same as the name of the fixtures file you are trying to load. If you are using defaults, this should be fine. If you have changed table names, you will need to rename your fixtures files (and possibly update your tests to reflect this too).
|
387
|
-
|
388
|
-
You should also note that fixtures typically tend to depend on test configuration information (such as test salt values), so not all data will be usable in fixture form.
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
= LICENCE
|
393
|
-
|
394
|
-
Copyright (c) 2006, James Adam
|
395
|
-
|
396
|
-
The MIT License
|
397
|
-
|
398
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
399
|
-
of this software and associated documentation files (the "Software"), to deal
|
400
|
-
in the Software without restriction, including without limitation the rights
|
401
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
402
|
-
copies of the Software, and to permit persons to whom the Software is
|
403
|
-
furnished to do so, subject to the following conditions:
|
404
|
-
|
405
|
-
The above copyright notice and this permission notice shall be included in
|
406
|
-
all copies or substantial portions of the Software.
|
407
|
-
|
408
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
409
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
410
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
411
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
412
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
413
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
414
|
-
THE SOFTWARE.
|
62
|
+
to see the set of rake tasks available.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
|
4
|
+
task :default => :doc
|
5
|
+
|
6
|
+
desc 'Generate documentation for the engines plugin.'
|
7
|
+
Rake::RDocTask.new(:doc) do |doc|
|
8
|
+
doc.rdoc_dir = 'doc'
|
9
|
+
doc.title = 'Engines'
|
10
|
+
doc.main = "README"
|
11
|
+
doc.rdoc_files.include("README", "UPGRADING", "CHANGELOG", "MIT-LICENSE")
|
12
|
+
doc.rdoc_files.include('lib/**/*.rb')
|
13
|
+
doc.options << '--line-numbers' << '--inline-source'
|
14
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
= Upgrading from Engines 1.1.x to Engines 1.2.x
|
2
|
+
|
3
|
+
|
4
|
+
The 1.2 release of the engines plugin represents a significant rewrite of the internals. Now less intrusive into the core frameworks, it's even simpler for plugin developers to make more flexible plugins than Rails typically allows.
|
5
|
+
|
6
|
+
However, as a consequence of change, you may need to make some adjustments to your application to get the most benefit. These are outlined below:
|
7
|
+
|
8
|
+
|
9
|
+
== In your application
|
10
|
+
|
11
|
+
The following changes will affect code in applications which use the engines plugin
|
12
|
+
|
13
|
+
=== Change the engine_schema table to plugin_schema
|
14
|
+
|
15
|
+
Because the engines plugin now works universally for any Rails plugin, the table used to store migration information has been renamed appropriately. We can also play nicely with other plugin_migration implementations by supporting this convention.
|
16
|
+
|
17
|
+
|
18
|
+
=== Rename RAILS_ROOT/public/engine_files to RAILS_ROOT/public/plugin_assets
|
19
|
+
|
20
|
+
Similarly, any plugin can now share stylesheets, images and so on via an assets folder, so the destination within the main public directory has been renamed to reflect this. You can simply delete the RAILS_ROOT/public/engine_files directory; the new one will be generated the next time your application starts.
|
21
|
+
|
22
|
+
|
23
|
+
=== The engine_image, engine_stylesheet and engine_javascript helpers have been replaced with enhanced versions of the normal Rails asset helpers
|
24
|
+
|
25
|
+
Now, it's simple to include an image from any plugin, by adding a plugin key to the helper's options hash:
|
26
|
+
|
27
|
+
image_tag "image.png", :plugin => "my_plugin"
|
28
|
+
|
29
|
+
A similar convention exists for stylesheets and javascript files. Additionally, the old behaviour of automatically including assets which match the "engine"'s name has been dropped - only the files you explicitly request are included.
|
30
|
+
|
31
|
+
|
32
|
+
=== Engines.start is replaced with config.plugins
|
33
|
+
|
34
|
+
Rails' native configuration object now includes an array for specifying which plugins are loaded, and in what order. The engines plugin enhances this feature with a "*" wildcard, so that you can load any order-sensitive plugins, and then the rest in any order.
|
35
|
+
|
36
|
+
config.plugins = ["engines", "some_plugin", "another_plugin", "*"]
|
37
|
+
|
38
|
+
It's worth noting that the engines plugin no longer needs to be specifically loaded first, so most people can happily ignore the config.plugins array without any problems.
|
39
|
+
|
40
|
+
|
41
|
+
=== The "config" method for "engine"-style configuration is no longer loaded by default.
|
42
|
+
|
43
|
+
See below.
|
44
|
+
|
45
|
+
|
46
|
+
=== Any "engines" type rake tasks are now "plugin" tasks.
|
47
|
+
|
48
|
+
The following rake tasks are now provided by the engines plugin for operating on your application's plugins (whenever a task can operate on a single plugin, this can be controlled by specifying PLUGIN=<name> on the commandline):
|
49
|
+
|
50
|
+
db:fixtures:plugins:load # load fixtures from plugins.
|
51
|
+
|
52
|
+
test:plugins:units # Run tests from within <plugins>/test/units
|
53
|
+
test:plugins:functional # Run tests from within <plugins>/test/functional
|
54
|
+
test:plugins:integration # Run tests from within <plugins>/test/integration
|
55
|
+
test:plugins # Run all tests from within <plugins>/test/*
|
56
|
+
|
57
|
+
doc:plugins # Run full rdoc against all source files within all plugins
|
58
|
+
doc:plugins:<plugin> # Run full rdoc against all source files within the given plugin
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
== In your "engine"-style plugins
|
63
|
+
|
64
|
+
If you have developed or are using plugins that leverage engines enhancements, you need to be aware of the following changes in engines 1.2.
|
65
|
+
|
66
|
+
=== init_engine.rb is no longer required
|
67
|
+
|
68
|
+
Please now create init.rb files, just as you'd find in "normal" plugins. Remember - there's no such thing as "an engine" anymore.
|
69
|
+
|
70
|
+
|
71
|
+
=== The "fixture" method for loading tests from arbitrary files
|
72
|
+
|
73
|
+
Supporting this was just too difficult, and it seems like the combination of Rails' own lack of enhancements regarding this feature, along with the mind-shift against static fixtures, meant that it simply was too much work to continue to support.
|
74
|
+
|
75
|
+
The only reason this mechanism originally existed was to support plugins which couldn't predict the names of the tables that models might be stored in. This is now a discouraged behaviour.
|
76
|
+
|
77
|
+
|
78
|
+
=== Engines.current.version has changed its behaviour slightly.
|
79
|
+
|
80
|
+
The engines plugin used to provide a simple way to store version information about plugins. This has now been superceded by including that information in an about.yml file, which any plugin can use.
|
81
|
+
|
82
|
+
|
83
|
+
=== The "config" method is not included, by default.
|
84
|
+
|
85
|
+
Where previously developers could use the "config" method to define configuration, this is now deprecated in favour of using mattr_accessor directly in the Module. However, if you still *need* to use the config method, it is included but must be explicitly required, probably near the top of environment.rb:
|
86
|
+
|
87
|
+
require File.join(RAILS_ROOT, "vendor", "plugins", "engines",
|
88
|
+
"lib", "engines", "deprecated_config_support")
|
89
|
+
|
90
|
+
|
91
|
+
=== Public assets should now be stored in a subdirectory of your plugin called "assets", rather than "public".
|
92
|
+
|
93
|
+
This clarifies the nature of this directory; it is not made public itself, but rather is a container for files which should be made accessible from the web.
|
@@ -0,0 +1,7 @@
|
|
1
|
+
author: James Adam
|
2
|
+
email: james.adam@gmail.com
|
3
|
+
homepage: http://www.rails-engines.org
|
4
|
+
summary: Enhances the plugin mechanism to perform more flexible sharing
|
5
|
+
description: The Rails Engines plugin allows the sharing of almost any type of code or asset that you could use in a Rails application, including controllers, models, stylesheets, and views.
|
6
|
+
license: MIT
|
7
|
+
version: 1.2.0
|
@@ -0,0 +1,45 @@
|
|
1
|
+
Description:
|
2
|
+
The plugin migration generator assists in working with schema additions
|
3
|
+
required by plugins. Instead of running migrations from plugins directly,
|
4
|
+
the generator creates a regular Rails migration which will be responsible
|
5
|
+
for migrating the plugins from their current version to the latest version
|
6
|
+
installed.
|
7
|
+
|
8
|
+
This is important because the set of application migrations remains an
|
9
|
+
accurate record of the state of the database, even as plugins are installed
|
10
|
+
and removed during the development process.
|
11
|
+
|
12
|
+
Example:
|
13
|
+
./script/generate plugin_migration [<plugin_name> <another_plugin_name> ...]
|
14
|
+
|
15
|
+
This will generate:
|
16
|
+
|
17
|
+
RAILS_ROOT
|
18
|
+
|- db
|
19
|
+
|-migrate
|
20
|
+
|- xxx_plugin_migrations.rb
|
21
|
+
|
22
|
+
which contains the migrations for the given plugin(s).
|
23
|
+
|
24
|
+
|
25
|
+
Advanced Usage:
|
26
|
+
|
27
|
+
There may be situations where you need *complete* control over the migrations
|
28
|
+
of plugins in your application, migrating a certainly plugin down to X, and
|
29
|
+
another plugin up to Y, where neither X or Y are the latest migrations for those
|
30
|
+
plugins.
|
31
|
+
|
32
|
+
For those unfortunate few, I have two pieces of advice:
|
33
|
+
|
34
|
+
1. Why? This is a code smell [http://c2.com/xp/CodeSmell.html].
|
35
|
+
|
36
|
+
2. Well, OK. Don't panic. You can completely control plugin migrations by
|
37
|
+
creating your own migrations. To manually migrate a plugin to a specific
|
38
|
+
version, simply use
|
39
|
+
|
40
|
+
Rails.plugins[:your_plugin_name].migrate(version)
|
41
|
+
|
42
|
+
where version is the integer of the migration this plugin should end
|
43
|
+
up at.
|
44
|
+
|
45
|
+
With great power comes great responsibility. Use this wisely.
|