?: Quasi Aspect Oriented Programming with Plugins...

If you've been programming for a while you've probably heard of Aspect Oriented Programming.

Now AOP is good, as it reduces complexity for developers and when combined with modules it also allows system administrators more freedom in what parts of the software they want to run.

As Ruby is a very dynamic language (Mixins, and all classes are open) and Rails already provides quite some hooks like before-, after, and validation- filters in models and controllers we are already half way there.

Now even better: the excellent plugins_plus plugin (http://svn.pluginaweek.org/trunk/plugins/rails/plugins_plus/) already almost does what we want. It allows one to put code in their default places inside the lib (like app/models) that is then merged with your application's code automatically (like Rails Engines).

What is missing is a way to output data from plugins into existing views and layouts. For this I made the BodyBuilderModule. (LogiLogi - Software Libre for the Web download | SourceForge.net) That module allows one to create hooks for places where content can be inserted in views.

In short it allows one to set body_parts (variables that can be included in views, like @pre_body) from controllers.

Together with the plugins_plus plugin this allows you to develop modules that mix in automatically at the level of Models, Controllers and (thanks to the body builder module) Views.

You can declare body-parts (variables like @left_body) inside a controller with:

body_parts :left, :pre # etc...

You should do this inside a plugin that is loaded before the plugins that will be adding to it. In case of Manta this is the [LogiLogi - Software Libre for the Web download | SourceForge.net MantaModulizer plugin].

Now in other plugins (and in the main app) you can add to the body-parts with:

left_body :my_method, :my_other_method

(for this 'body-part :left' must have been declared)

Then in view in your app you can include @left_body, and it will contain all that my_method, my_other_method, (and possibly more methods in different modules) have returned after you've called build_bodies as a before_filter.

You can get the modules here:

(an extension to the module class is needed to allow mixing in both class and normal methods...)

So now go forth and multiply your app's aspects...

If you think this module might be usefull for wider application I could pack it up as a plugin. Also if you have any comments on how it could be improved (in relation to yield for example) they're welcome...

greetings,

Wybo Wiersma