aop presentational items in Rails?

L

leon breedt

hi,

i was just wondering, does Rails offer, or plan to offer,
HTML::Mason-like AOP for templates?

the Masonic notion does not map directly to the Rails way of doing
things, i suspect,
i think the closest thing Rails has to a component in Mason
terminology is the template, and i'll use template below when i mean
"component" in HTML::Mason terms.

with HTML::Mason, you can define a "autohandler" for any particular
path. what this means is that the autohandler is a parent (for the
purposes of presentational output) for any template contained at or
below that path.

it has complete control of the output and can decide where the output
of any contained templates should go. you can obviously override it
selectively for components that you don't want this behaviour to apply
to.

the concept is very powerful though, as the wrapped component need
know nothing about how its being wrapped. this is also vastly superior
to include mechanisms, as it is completely DRYish :)

Mason examples:

/autohandler - gets invoked for all paths
/admin/autohandler - gets invoked for everything below /admin

there is of course also the Mason concept of "dhandler", or "default
handler", when nonexistent paths are attempted to be accessed, but
thats a whole different discussion.

the autohandler feature is something i would not be able to live
without though, as it has meant a vast reduction in LOC for my web
apps.

comments?

leon
 
N

Nicholas Van Weerdenburg

For those that know, would this be akin to Tiles in Struts (in a
somewhat different form)?

Thanks,
Nick
 
D

David Heinemeier Hansson

For those that know, would this be akin to Tiles in Struts (in a
somewhat different form)?

I looked at both SiteMesh and Tiles before doing layouts in Action
Pack. So yes, there was indeed inspiration, but mostly in the sense of
what _not_ to do. I think both approaches are over-engineered to the
point of being laborious and hard to understand. But I feel that about
many things, so...

Anyway, in my opinion, the benefit of SiteMesh and Tiles is the
inversion principle. Instead of having content templates reference
common layout (through include header/footer and the like), you make
the layout reference the content. That's where at least 80% of the
benefit is hidden to me. And layouts in Action Pack implements that for
5% of the effort (it's really just a string!).
--
David Heinemeier Hansson,
http://www.rubyonrails.org/ -- Web-application framework for Ruby
http://www.instiki.org/ -- A No-Step-Three Wiki in Ruby
http://www.basecamphq.com/ -- Web-based Project Management
http://www.loudthinking.com/ -- Broadcasting Brain
http://www.nextangle.com/ -- Development & Consulting Services
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top