# ?: Quasi Aspect Oriented Programming with Plugins

**URL:** <https://www.ruby-forum.com/t/quasi-aspect-oriented-programming-with-plugins/91302>\
**Category:** Rails\
**Created:** [April 6, 2007, 2:11pm UTC](https://www.ruby-forum.com/t/quasi-aspect-oriented-programming-with-plugins/91302 "2007-04-06T14:11:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wybo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/cc9497/32.png) [@wybo](https://www.ruby-forum.com/u/wybo)\
**Post date:** [April 6, 2007, 2:11pm UTC](https://www.ruby-forum.com/t/quasi-aspect-oriented-programming-with-plugins/91302/1 "2007-04-06T14:11:31Z")

</div>

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/](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](http://logilogi.svn.sourceforge.net/viewvc/logilogi/trunk/lib/modules/body_builder_module.rb?view=markup))  
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](http://logilogi.svn.sourceforge.net/viewvc/logilogi/trunk/vendor/plugins/manta_modulizer/)  
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:

> **[LogiLogi - Software Libre for the Web](https://sourceforge.net/projects/logilogi/)**
>
> Download LogiLogi - Software Libre for the Web for free. LogiLogi is a system to share and discuss ideas in an integrated and cumulative way. Openness and quality are it's core aims.

> **[LogiLogi - Software Libre for the Web](https://sourceforge.net/projects/logilogi/)**
>
> Download LogiLogi - Software Libre for the Web for free. LogiLogi is a system to share and discuss ideas in an integrated and cumulative way. Openness and quality are it's core aims.

(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 W.

–

:🧑‍🎓

- History, Informatiekunde (computer linguistics, IR, webtech) and  
Philosophy
- Member of the Center for Metahistory Groningen  
([Faculty of Arts | About us | University of Groningen](http://www.rug.nl/let/cmg))

::Free Software and Open Source Developer:

- [http://www.LogiLogi.org](http://www.LogiLogi.org), Cumulative, shared commenting, publication  
and  
idea sharing: Where insight comes together…
- ComLinToo, a computational linguistics toolset written in Perl
- Lake ([LogiLogi.org](http://LogiLogi.org) Make), a make-replacement using makefiles in pure  
C++

::Being:

- In the world, wavy hair, go figure  
([http://nl.logilogi.org/HomE/WyboWiersma](http://nl.logilogi.org/HomE/WyboWiersma))
