You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Gabriel Sidler <si...@teamup.ch> on 2002/02/05 21:54:18 UTC

Re: Building static web-pages with velocity

Peter,
did you have a look at DVSL?

http://jakarta.apache.org/velocity/dvsl/index.html

I believe it is pretty much doing what you are looking for,
including ant task, etc. 

The new jakarta-velocity-tools uses DVSL for the docs.
See http://cvs.apache.org/viewcvs/jakarta-velocity-tools/view/
for some simple examples. 'xdocs' is the source dir, 'docs'
is the destination dir and build.xml has a task 'docs' to 
process the files in xdocs.

Gabe





Peter Sojan wrote:
> 
> Hi all!
> 
> I already use Velocity extensively to generate dynamic pages. However,
> my current project also involves static content. I took a look at
> Anakia and, while being a great way for doing static ONLY things, I
> would rather like to integrate the static part with my dynamic
> part. That is: dynamic AND static pages are simply velocity templates,
> which share common information stored in a context. In the dynamic
> case the context is being filled by servlets, and in the static
> case by a "generator" class.
> 
> What I would need now, is a build system for my static pages. I would
> like to have something like an ant-task which I can parametrize with
> following information:
> 
> - input fileset which represent velocity templates
> - output fileset which represent the generated static pages
> (this could be done with an ANT filemapper !?)
> - a reference to the "generator" class which in turn gets invoked
>   for every input-template, fills context and merges to an output
>   file.
> (ideally the generator class only gets invoked when the template
> is newer than the corresponding output page)
> 
> Has anyone already done such a thing? Perhaps a new ant-task would be
> the solution, but I want to start writing one but perhaps such
> a thing already exists. Anyway, would such an approach be the "correct"
> way to do such things.
> 
> Thanx in advance,
> Peter
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
Gabriel Sidler
Software Engineer, Eivycom GmbH, Zurich, Switzerland

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: DVSL to generate *.vm files

Posted by "Charles N. Harvey III" <ch...@alloy.com>.
Can't you simply escape the velocity directives?


<table>
\#foreach ($i in [1, 2, 3, 4, 5])
<tr>
  <td>Row $i</td>
</tr>
\#end
</table>

Now, I'm no pro, but the user-guide.html says that this should render:

<table>
#foreach ($i in [1, 2, 3, 4, 5])
<tr>
  <td>Row $i</td>
</tr>
#end
</table>


I just tried it.  Works like a charm.  But that is for a template
called from a servlet, not a generated page from DVSL.  But it should
work exactly the same.  Give it a go and see if works the same for you.

Charlie


On 2/5/02 4:11 PM, "Gabriel Sidler" <si...@teamup.ch> wrote:

> I used DVSL to generate static files. Now I would
> like to use it to generate dynamic files. i.e. files
> that contain VTL statements.
> 
> First approach was to embed VTL statements into the source XML file:
> 
> <table>
> #foreach ($i in [1, 2, 3, 4, 5])
> <tr>
>   <td>Row $i</td>
> </tr>
> #end
> </table>
> 
> This doesn't work. The VTL directives are discarded and
> don't appear in the generated output files.
> 
> 
> Second approach was to define a tag <vel></vel> in the
> style file:
> 
> #match ( "vel" )
> $node.value()
> #end
> 
> and then wrap all VTL directives with this tag. Above example
> result in:
> 
> <table>
> <vel>#foreach ($i in [1, 2, 3, 4, 5])</vel>
> <tr>
>   <td>Current index is: $i</td>
> </tr>
> <vel>#end</vel>
> </table>
> 
> This works and produces the desired output:
> 
> <table>
> #foreach ($i in [1, 2, 3, 4, 5])
> <tr>
>   <td>Current index is: $i</td>
> </tr>
> #end
> </table>
> 
> 
> Is the second described approach the best we can do?
> Any more elegant solutions?

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DVSL to generate *.vm files

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 2/5/02 4:11 PM, "Gabriel Sidler" <si...@teamup.ch> wrote:

> I used DVSL to generate static files. Now I would
> like to use it to generate dynamic files. i.e. files
> that contain VTL statements.
> 
> First approach was to embed VTL statements into the source XML file:
> 
> <table>
> #foreach ($i in [1, 2, 3, 4, 5])
> <tr>
>   <td>Row $i</td>
> </tr>
> #end
> </table>
> 
> This doesn't work. The VTL directives are discarded and
> don't appear in the generated output files.
> 
> 
> Second approach was to define a tag <vel></vel> in the
> style file:
> 
> #match ( "vel" )
> $node.value()
> #end
> 
> and then wrap all VTL directives with this tag. Above example
> result in:
> 
> <table>
> <vel>#foreach ($i in [1, 2, 3, 4, 5])</vel>
> <tr>
>   <td>Current index is: $i</td>
> </tr>
> <vel>#end</vel>
> </table>
> 
> This works and produces the desired output:
> 
> <table>
> #foreach ($i in [1, 2, 3, 4, 5])
> <tr>
>   <td>Current index is: $i</td>
> </tr>
> #end
> </table>
> 
> 
> Is the second described approach the best we can do?
> Any more elegant solutions?

This is the classic problem...  Generating VTL with VTL.

You have the same problem in XML, right?  Where you use entities to get
around it?

I like the solution you came up with.

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"Now what do we do?"


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


DVSL to generate *.vm files

Posted by Gabriel Sidler <si...@teamup.ch>.
I used DVSL to generate static files. Now I would
like to use it to generate dynamic files. i.e. files
that contain VTL statements.

First approach was to embed VTL statements into the source XML file:

<table>
#foreach ($i in [1, 2, 3, 4, 5])
  <tr>
    <td>Row $i</td>
  </tr>
#end
</table>

This doesn't work. The VTL directives are discarded and
don't appear in the generated output files.


Second approach was to define a tag <vel></vel> in the
style file:

#match ( "vel" )
  $node.value()
#end

and then wrap all VTL directives with this tag. Above example
result in:

<table>
<vel>#foreach ($i in [1, 2, 3, 4, 5])</vel>
  <tr>
    <td>Current index is: $i</td>
  </tr>
<vel>#end</vel>
</table>

This works and produces the desired output:

<table>
#foreach ($i in [1, 2, 3, 4, 5])
  <tr>
    <td>Current index is: $i</td>
  </tr>
#end
</table>


Is the second described approach the best we can do?
Any more elegant solutions?

Gabe





--
Gabriel Sidler
Software Engineer, Eivycom GmbH, Zurich, Switzerland

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>