On Apr 5, 2007, at 12:43 AM, Pascal Fleury wrote: > On Thursday 05 April 2007 06:05:54 William Cox wrote: >> Tim, >> stuff based on components to be called later. things like bringing in >> js scripts and css files if certain components need them. heres an > > I used regular OO in Mason, i.e. for JavaScript, CSS and header > meta info, I > call something like SELF:javascript. In a component that calls other > subcomponents, that javascript method calls the same method on the > subcomponents. It makes a little replication of the call chain > code, but it's > manageable. > > This makes it essentially a "multi-pass" page builder, first pass > for header > metadata, then for javascript. For CSS, it is basically handled in > the meta, > so that I @import the appropriate files. > > The main component (my autohandler) implements empty defaults for > all these > methods, so that you need not add them in case there is no meta or > javascript > to add to the current page. > > That is an area where I was always struggling, and I think I have > not found > yet the proper idiom to do it in Mason. I was wondering also if I > could use > the buffers for this: call the components, and put the meta stuff > into the > meta buffer, the javascript into the javascript buffer, etc. Then, > the top > level component (an autohandler) would string these buffers > together into the > final page.
what i do is capture the request_comp ($m->fetch_next, actually) output during the %init section of autohandler. that allows the page components to influence global state (or set $m->notes) that can then be used by the autohandler. an abbreviated example: <%init> my $content = $m->scomp($m->fetch_next, %ARGS); $m->notes(content => $content); </%init> <html><head> <& SELF:head &> <% $m->notes('head_outro') %> </head><body> <& SELF:header &> <% $m->notes('content') %> <& SELF:footer &> </body></html> now methods head, header, footer, et al, are run _after_ the requested component, which has a chance to influence their behavior (noting which js/css files are needed, etc). typically i do that via other $m->notes, using helper methods defined in autohandler such as: <%method append_head_outro> <%args> $content => $m->content() </%args> % $m->notes('head_outro' => ($m->notes('head_outro') || '') . $content); </%method> so foo.html can look like <div>here is some central page content</div> %# this page requires prototype.js, so be sure it is included <&| SELF:append_head_outro &> <script src="<% $c->uri_for('/static/script/scriptaculous/ prototype.js') %>" type="text/javascript"></script> </&> ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Mason-users mailing list Mason-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mason-users