Hi,
I am opening this discussion to all, since I would like to
hear other peoples opinion.
For the kind of translation templates I am trying to build I will
need to be able to limit the scope of macros defined on a template
to that template only. In my case I may have multiple people
writing templates and using the same Velocity runtime but each one
will be using its own set of unrelated macros.
I do not mean by this that I do not want the avility to have global
libraries of macros. But that I also need to be able to define
macros whose scope is limited to the template.
In other words, each template must have its own local dictionary
of macros that gets consulted before the global dictionary.
If you need more info about usage escenarios, let me know.
Jose Alberto
-----Original Message-----
From: Geir Magnusson Jr. [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 05, 2000 1:52 PM
To: Jose Alberto Fernandez
Subject: RE: quick note on recent changes
-----Original Message-----
From: Jose Alberto Fernandez [SMTP:[EMAIL PROTECTED]]
Sent: Tuesday, December 05, 2000 4:35 PM
To: 'Geir Magnusson Jr.'
Subject: RE: quick note on recent changes
I was not thinking on NameSpaces, but now that you bring this in, let me
ask.
Are the macros defined in a template, local to that template? Or are they
global to the Runtime?
This is really something I need since different unrelated people will be
writing the templates.
I think is is quite understandable, that we need to be able to isolate them.
Currently it's a global soup. I was thinking about namespaces and such. I
guess the conclusion was that for the first go-round, I wouldn't put them
in. Some of the thinking came from the idea that in a common runtime
environment, like servlets, there should be some coordination between
writers. But of course there are exceptions to that. Let me know what you
are wanting to do - maybe we can work something out. Always interested in
actual use cases.
On my original question, I found I can do what I wanted by just declaring my
macros
with the format I want, within another macro definintion that I will never
call. The innner macros
get register fine, and all the white space around the macro definitions
never gets rendered.
Coool,
Coool! I don't understand the problem still though.
Oh! I see. Yes, if there is whitespace when you are defining your macros,
it will render if they macros are in the template. You can have the macros
load at engine start time, by using the properties :
velocimacro.library.global=VM_global_library.vm
velocimacro.library.local=VM_local_library.vm
Of course, you can change the filenames to whatever you want. The point /
hope / idea here is that the global libraray is a collection of useful VMs
that we can package with the velocity distribution, and the local is a
collection of your application or site-local VMs. And whitespace crap
around the VMs doesn't get rendered, of course.
Maybe I'll add
velocimacro.library.1.name =
velocimacro.library.2.name =
etc. Will be at home after this : [EMAIL PROTECTED]
geir
Jose Alberto
-----Original Message-----
From: Geir Magnusson Jr. [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 05, 2000 11:32 AM
To: Jose Alberto Fernandez
Subject: RE: quick note on recent changes
LIke namespaces... I think that would get panned. The general philosophy
(which I support) is to keep the number of directives to the bare minimum,
and the notion of namespace is prollie right out.
The idea is to keep the template language as simple as possible for the
designer crowd.
However, I have a helper class that you can use in Java to invoke macros
right from java code, something like
boolean invokeVM( strVMName, strParms[], context, writer)
which returns true if it found and executed the VM, and false if not.
We can add methods there where you can dump macros, or simply just reload
via the usual template pattern. Would that help?
geir
-----Original Message-----
From: Jose Alberto Fernandez [SMTP:[EMAIL PROTECTED]]
Sent: Tuesday, December 05, 2000 2:27 PM
To: 'Geir Magnusson Jr.'
Cc: '[EMAIL PROTECTED]'
Subject: RE: quick note on recent changes
Well, that is good to know.
Here is an idea for another directive.
Notice that in the kind of problem I am trying to atack with Velocity
the library of macros will be escentially different for each template
hence, the global library is not really an option.
I would like to have a way to define part of "library zone" on the template.
In such a zone, you just load the macros defined there but the rest
of the space formating does not count. For example:
-----------
#macrozone
#macro(a)
...
#end
## Nicely formated comments with blank lines
## separating the different macro definintions, etc
#macro(b $x)
... $x ...
#end
#end##End of macro zone
This is the start of the actual template
#a()
#b(123)
End of template
------------
Of course I could load the macro zone using #parse(file.mac)
or have a #loadlib(file.mac) directive. But the point is that
spacing there will not count.
Can I achive this by defining my macros inside a macro I never use?
-----------
#macro(zone)
#macro(a)
...
#end
## Nicely formated comments with blank lines
## separating the different macro definintions, etc
#macro(b $x)
... $x ...
#end
#end##End of macro zone
This is the start of the actual template
#a()
#b(123)
End of template
------------
I will try it.
Jose Alberto
> -----Original Message-----
> From: Geir Magnusson Jr. [ <mailto:[EMAIL PROTECTED]>]
> Sent: Monday, December 04, 2000 8:44 PM
> To: Jose Alberto Fernandez
> Subject: Re: quick note on recent changes
>
>
> OOOHhhhhhhhhhh.
>
> I get it.
>
> You are putting the macro def after the use. :)
>
> Ah.
>
> That's actually wrong, but it works for some subtle reasons I
> won't bore
> you with.
>
> Yes, that's not documented and it should be.
>
> Yes, i have a fix coming :)
>
> Thanks for helping me find it! I had two reports, but
> couldn't make it
> happen, because everyone *knows* :) that you must define before use :)
>
> The way its supposed to be is that you define all your macro's first,
> either in a global library that sucked in at startup, or at the top of
> each template.
>
> I do have a fix coming to solve that, so you can #macro()
> anywhere. It
> will be a performance hit,
> but if you are caching, it will be fine.
>
> Thanks for the help!
>
> more inline ->
>
> Jose Alberto Fernandez wrote:
> >
> > Yes, is still happening.
> >
> > BTW, I have gotten some other very wierd errors.
> > For example assume this input file:
> > ----------
> > <something>
> > #mymacro
> > <morestuff>$msg.SomeValue</morestuff>
> > </something>
> >
> > #macro(mymacro)
> > <otherstuff>$msg.OtherProp</otherstuff>
> > #myOtherMacro($msg.Value)
> > #end
> > ----------
> >
> > The code above expands fine. However if I move the content
> > of the macro in place (cut & paste). I get errors of
> > parameters wrong for myOtherMacro.
>
> What do you mean? I don't understand.
>
> > --------
> > <something>
> > <otherstuff>$msg.OtherProp</otherstuff>
> > #myOtherMacro($msg.Value)
> > <morestuff>$msg.SomeValue</morestuff>
> > </something>
> > ----------
> >
> > When I put the thing back the way it was it started working again.
> > Of course, my real life example is more complicated but
> > that is the just of what I did. I have no idea why it happened.
> > Lets see if tomorrow I can send you something,
>
> Cool.
>
>
> >
> > Jose Alberto
> >
> > > -----Original Message-----
> > > From: Geir Magnusson Jr. [ <mailto:[EMAIL PROTECTED]>]
> > > Sent: Monday, December 04, 2000 7:45 PM
> > > To: Jose Alberto Fernandez
> > > Subject: Re: quick note on recent changes
> > >
> > >
> > >
> > > Can you make the zero arg VM problem repeat? I am now on
> a windows98
> > > box, and I can't get it to happen.
> > >
> > > geir
> > >
> > >
> > > --
> > > Geir Magnusson Jr.
> [EMAIL PROTECTED]
> > > Dakota tribal wisdom: "when you discover you are riding a
> dead horse,
> > > the best strategy is to dismount."
> > >
>
> --
> Geir Magnusson Jr. [EMAIL PROTECTED]
> Dakota tribal wisdom: "when you discover you are riding a dead horse,
> the best strategy is to dismount."
>