Re: [xwiki-users] Macro within code macro

2009-05-05 Thread Lewis Denizen
Thanks Vincent/Thomas,

Just like Thomas mentioned, my intention was to execute a macro within
another macro so that I could "generate" the arguments for a macro on the
fly.  We're using XWiki as a knowledge base/support tool at work, and we
encounter situations like this where we'd like to dynamically generate some
"text" as input for a macro.

The {{date}} macro is one example, but I was hoping to extend this to
extract other information for usage in other macros as well.  Also, since we
depend on a (proprietary) Java API for calculating business dates, it's
easier for us to extract this info from a standardized Java macro than from
velocity or groovy.

Currently, we're only trying to utilize it with the {{code}} macro for
generating pretty copy/paste-able SQL and scripts, but we'd like to create a
completely new macro to execute SQLs/scripts on our production servers right
from the wiki (something similar to the SQL plugin for XWiki 1.x).  Hope
this gives some background to the issue.

Again, thanks for the immediate feedback on this!

On Tue, May 5, 2009 at 7:46 PM, Vincent Massol  wrote:

>
> On May 5, 2009, at 12:32 PM, Thomas Mortagne wrote:
>
> > On Tue, May 5, 2009 at 12:01, Vincent Massol 
> > wrote:
> >>
> >> On May 5, 2009, at 11:57 AM, Lewis Denizen wrote:
> >>
> >>> Thanks Vincent.  One more question - is it possible to execute an
> >>> XWiki 2.0
> >>> macro from Velocity context?
> >>
> >> yes the velocity macro does this:
> >> 1) executes velocity on the full macro content which is considered as
> >> text
> >> 2) run the wiki parser on the result
> >
> > I think it's not exactly what Lewis asked. His problem is that he want
> > to execute a macro inside code macro so for that he need velocity to
> > generate the result of the macro in the code macro content and not
> > just the macro itself.
> >
> > There is no easy way to do that in velocity, this means access the
> > parser as component execute it on {{date-macro date="-1b"
> > format="MMdd"/}}, execute transformations (other components) on it
> > and re-render the XDOM. And all that just to print a date if i
> > understood well your use case.
>
> Well first we'd need to know why Lewis needs to do that!
> I think we can rephrase the question as: how to pretty print a
> generated text.
>
> The general answer I think is:
>
> {{velocity}}
> ## Compute the content here
> #set ($content = "")
>
> {{code language="java"}}
> $content
> {{/code}}
> {{/velocity}}
>
> As Thomas said though, if you want to execute wiki syntax from
> velocity you can probably do something like:
>
> #set ($mydoc = $xwiki.getDocument("dummy"))
> $mydoc.setContent("{{mymacro/}}")
> #set ($content = $mydoc.getRenderedContent())
>
> Note that the current document in the xwiki context would still be the
> current document and not "dummy" so any macro that uses the current
> document would not use "dummy".
>
> I'd like to know more about the use case.
>
> Thanks
> -Vincent
>
> >>> On Tue, May 5, 2009 at 4:46 PM, Vincent Massol 
> >>> wrote:
> >>>
>  Hi Lewis,
> 
>  On May 5, 2009, at 9:11 AM, Lewis Denizen wrote:
> 
> > Hi xwiki-users,
> >
> > Just wondering if it's possible to add a macro inside a code
> > macro?
> > What I
> > want to do is something like this:
> >
> > {{code language="sql"}}
> > select *
> > from xyz
> > where from_date = '{{date-macro date="-1b" format="MMdd"/}}'
> > --
> > The
> > date-macro returns the last business date in MMdd format
> > {{/code}}
> 
>  If by adding you mean execution it, then no it's not possible since
>  it's not the goal of the code macro. The code macro is supposed to
>  render its content as is without any interpretation (only syntax
>  coloring).
> 
>  However if what you want is to execute some stuff you can use this
>  trick:
> 
>  {{velocity}}
>  {{code}}
>  ...
>  Some velocity code here that will be executed, including a velocity
>  macro
>  ...
>  {{/code}}
>  {{/velocity}}
> 
>  Thanks
>  -Vincent
> ___
> users mailing list
> users@xwiki.org
> http://lists.xwiki.org/mailman/listinfo/users
>
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] Macro within code macro

2009-05-05 Thread Vincent Massol

On May 5, 2009, at 12:32 PM, Thomas Mortagne wrote:

> On Tue, May 5, 2009 at 12:01, Vincent Massol   
> wrote:
>>
>> On May 5, 2009, at 11:57 AM, Lewis Denizen wrote:
>>
>>> Thanks Vincent.  One more question - is it possible to execute an
>>> XWiki 2.0
>>> macro from Velocity context?
>>
>> yes the velocity macro does this:
>> 1) executes velocity on the full macro content which is considered as
>> text
>> 2) run the wiki parser on the result
>
> I think it's not exactly what Lewis asked. His problem is that he want
> to execute a macro inside code macro so for that he need velocity to
> generate the result of the macro in the code macro content and not
> just the macro itself.
>
> There is no easy way to do that in velocity, this means access the
> parser as component execute it on {{date-macro date="-1b"
> format="MMdd"/}}, execute transformations (other components) on it
> and re-render the XDOM. And all that just to print a date if i
> understood well your use case.

Well first we'd need to know why Lewis needs to do that!
I think we can rephrase the question as: how to pretty print a  
generated text.

The general answer I think is:

{{velocity}}
## Compute the content here
#set ($content = "")

{{code language="java"}}
$content
{{/code}}
{{/velocity}}

As Thomas said though, if you want to execute wiki syntax from  
velocity you can probably do something like:

#set ($mydoc = $xwiki.getDocument("dummy"))
$mydoc.setContent("{{mymacro/}}")
#set ($content = $mydoc.getRenderedContent())

Note that the current document in the xwiki context would still be the  
current document and not "dummy" so any macro that uses the current  
document would not use "dummy".

I'd like to know more about the use case.

Thanks
-Vincent

>>> On Tue, May 5, 2009 at 4:46 PM, Vincent Massol 
>>> wrote:
>>>
 Hi Lewis,

 On May 5, 2009, at 9:11 AM, Lewis Denizen wrote:

> Hi xwiki-users,
>
> Just wondering if it's possible to add a macro inside a code  
> macro?
> What I
> want to do is something like this:
>
> {{code language="sql"}}
> select *
> from xyz
> where from_date = '{{date-macro date="-1b" format="MMdd"/}}'  
> --
> The
> date-macro returns the last business date in MMdd format
> {{/code}}

 If by adding you mean execution it, then no it's not possible since
 it's not the goal of the code macro. The code macro is supposed to
 render its content as is without any interpretation (only syntax
 coloring).

 However if what you want is to execute some stuff you can use this
 trick:

 {{velocity}}
 {{code}}
 ...
 Some velocity code here that will be executed, including a velocity
 macro
 ...
 {{/code}}
 {{/velocity}}

 Thanks
 -Vincent
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] Macro within code macro

2009-05-05 Thread Thomas Mortagne
On Tue, May 5, 2009 at 12:01, Vincent Massol  wrote:
>
> On May 5, 2009, at 11:57 AM, Lewis Denizen wrote:
>
>> Thanks Vincent.  One more question - is it possible to execute an
>> XWiki 2.0
>> macro from Velocity context?
>
> yes the velocity macro does this:
> 1) executes velocity on the full macro content which is considered as
> text
> 2) run the wiki parser on the result

I think it's not exactly what Lewis asked. His problem is that he want
to execute a macro inside code macro so for that he need velocity to
generate the result of the macro in the code macro content and not
just the macro itself.

There is no easy way to do that in velocity, this means access the
parser as component execute it on {{date-macro date="-1b"
format="MMdd"/}}, execute transformations (other components) on it
and re-render the XDOM. And all that just to print a date if i
understood well your use case.


>
> -Vincent
>
>> On Tue, May 5, 2009 at 4:46 PM, Vincent Massol 
>> wrote:
>>
>>> Hi Lewis,
>>>
>>> On May 5, 2009, at 9:11 AM, Lewis Denizen wrote:
>>>
 Hi xwiki-users,

 Just wondering if it's possible to add a macro inside a code macro?
 What I
 want to do is something like this:

 {{code language="sql"}}
 select *
 from xyz
 where from_date = '{{date-macro date="-1b" format="MMdd"/}}' --
 The
 date-macro returns the last business date in MMdd format
 {{/code}}
>>>
>>> If by adding you mean execution it, then no it's not possible since
>>> it's not the goal of the code macro. The code macro is supposed to
>>> render its content as is without any interpretation (only syntax
>>> coloring).
>>>
>>> However if what you want is to execute some stuff you can use this
>>> trick:
>>>
>>> {{velocity}}
>>> {{code}}
>>> ...
>>> Some velocity code here that will be executed, including a velocity
>>> macro
>>> ...
>>> {{/code}}
>>> {{/velocity}}
>>>
>>> Thanks
>>> -Vincent
> ___
> users mailing list
> users@xwiki.org
> http://lists.xwiki.org/mailman/listinfo/users
>



-- 
Thomas Mortagne
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] Macro within code macro

2009-05-05 Thread Vincent Massol

On May 5, 2009, at 11:57 AM, Lewis Denizen wrote:

> Thanks Vincent.  One more question - is it possible to execute an  
> XWiki 2.0
> macro from Velocity context?

yes the velocity macro does this:
1) executes velocity on the full macro content which is considered as  
text
2) run the wiki parser on the result

-Vincent

> On Tue, May 5, 2009 at 4:46 PM, Vincent Massol   
> wrote:
>
>> Hi Lewis,
>>
>> On May 5, 2009, at 9:11 AM, Lewis Denizen wrote:
>>
>>> Hi xwiki-users,
>>>
>>> Just wondering if it's possible to add a macro inside a code macro?
>>> What I
>>> want to do is something like this:
>>>
>>> {{code language="sql"}}
>>> select *
>>> from xyz
>>> where from_date = '{{date-macro date="-1b" format="MMdd"/}}' --
>>> The
>>> date-macro returns the last business date in MMdd format
>>> {{/code}}
>>
>> If by adding you mean execution it, then no it's not possible since
>> it's not the goal of the code macro. The code macro is supposed to
>> render its content as is without any interpretation (only syntax
>> coloring).
>>
>> However if what you want is to execute some stuff you can use this
>> trick:
>>
>> {{velocity}}
>> {{code}}
>> ...
>> Some velocity code here that will be executed, including a velocity
>> macro
>> ...
>> {{/code}}
>> {{/velocity}}
>>
>> Thanks
>> -Vincent
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] Macro within code macro

2009-05-05 Thread Lewis Denizen
Thanks Vincent.  One more question - is it possible to execute an XWiki 2.0
macro from Velocity context?

On Tue, May 5, 2009 at 4:46 PM, Vincent Massol  wrote:

> Hi Lewis,
>
> On May 5, 2009, at 9:11 AM, Lewis Denizen wrote:
>
> > Hi xwiki-users,
> >
> > Just wondering if it's possible to add a macro inside a code macro?
> > What I
> > want to do is something like this:
> >
> > {{code language="sql"}}
> > select *
> > from xyz
> > where from_date = '{{date-macro date="-1b" format="MMdd"/}}' --
> > The
> > date-macro returns the last business date in MMdd format
> > {{/code}}
>
> If by adding you mean execution it, then no it's not possible since
> it's not the goal of the code macro. The code macro is supposed to
> render its content as is without any interpretation (only syntax
> coloring).
>
> However if what you want is to execute some stuff you can use this
> trick:
>
> {{velocity}}
> {{code}}
> ...
> Some velocity code here that will be executed, including a velocity
> macro
> ...
> {{/code}}
> {{/velocity}}
>
> Thanks
> -Vincent
>
> ___
> users mailing list
> users@xwiki.org
> http://lists.xwiki.org/mailman/listinfo/users
>
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] Macro within code macro

2009-05-05 Thread Vincent Massol
Hi Lewis,

On May 5, 2009, at 9:11 AM, Lewis Denizen wrote:

> Hi xwiki-users,
>
> Just wondering if it's possible to add a macro inside a code macro?   
> What I
> want to do is something like this:
>
> {{code language="sql"}}
> select *
> from xyz
> where from_date = '{{date-macro date="-1b" format="MMdd"/}}' --  
> The
> date-macro returns the last business date in MMdd format
> {{/code}}

If by adding you mean execution it, then no it's not possible since  
it's not the goal of the code macro. The code macro is supposed to  
render its content as is without any interpretation (only syntax  
coloring).

However if what you want is to execute some stuff you can use this  
trick:

{{velocity}}
{{code}}
...
Some velocity code here that will be executed, including a velocity  
macro
...
{{/code}}
{{/velocity}}

Thanks
-Vincent

___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


[xwiki-users] Macro within code macro

2009-05-05 Thread Lewis Denizen
Hi xwiki-users,

Just wondering if it's possible to add a macro inside a code macro?  What I
want to do is something like this:

{{code language="sql"}}
select *
from xyz
where from_date = '{{date-macro date="-1b" format="MMdd"/}}' -- The
date-macro returns the last business date in MMdd format
{{/code}}

Thanks in advance!
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users