You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Supun Kamburugamuva (JIRA)" <de...@velocity.apache.org> on 2007/07/14 18:38:04 UTC

[jira] Updated: (VELOCITY-529) Set a macro library programmatically for each individual page request

     [ https://issues.apache.org/jira/browse/VELOCITY-529?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Supun Kamburugamuva updated VELOCITY-529:
-----------------------------------------

    Attachment: template_macro_lib.patch

I have done an implementation for including macro libraries programmatically. But the implementation is different from what Will has previously suggested.  
In this implementation the getTemplate function of the RuntimeServices interface is overloaded to include macro libraries.
RuntimeServices.getTemplate(String templateName, List macroLibaryNames);

This call will build the template with the macros from macroLbraries argument.
 I have chosen this method instead of overloading Template.merge method for one reason (I have done an implementation of overloading merge and it seems like it is impossible to give a proper solution). If we include the macro libraries in the merge method we only see the Macro definitions at the merge time. But we are building the template AST before we see the macro definitions. At this point we don't know weather calls to macros defined in a library are actual macros or not, even worse we cannot guarantee that there will be macro definitions for the macro calls in the library. So we have to include the macro libraries before we build the AST for the Temaplate.
 I have attached a patch which contains the implementation. If this approach is not suitable I'm ready to re-implement using another method.   


> Set a macro library programmatically for each individual page request
> ---------------------------------------------------------------------
>
>                 Key: VELOCITY-529
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-529
>             Project: Velocity
>          Issue Type: New Feature
>            Reporter: Will Glass-Husain
>            Priority: Minor
>             Fix For: 1.6
>
>         Attachments: template_macro_lib.patch
>
>
> I'd like to see Velocity allow developers to specify one or more macro files programmatically when a page is processed.  The resulting behavior would be the same as if the user had used #parse to load the macro file at the top of the page.  (assuming VELOCITY-362 was fixed and this worked).
> Velocity currently allows a developer to specify a VMGlobal library which loads a common set of macros applied for all pages.  This is different because the macro file could be different for different pages.
> Probably the best way for this to work would be to use a structure similar to the event handlers which specifies a macro file name and attaches it to the context.  When the page is processed, Velocity would use the resource loaders to load both the page and the macro file.  (taking advantage of the resource caching mechanism for optimal performance).
> Why is this useful?  There may be cases where different parts of an application require different sets of macros.  In some cases, you may have many different parties developing different parts of the application.  (For example in my primary app, we have large amounts of users regularly uploading Velocity pages to separate accounts).  It's good practice to separate out modules from the main file.  If this could be specified programmatically then template writers could upload both a macro file as well as a set of templates that use them.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org