You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Rob Harvey <oz...@gmail.com> on 2005/11/18 00:46:37 UTC
Any use for an optional template copy task?
Hi,
I wrote a Task recently that alters files as they are copied to
different directories. I used it to create a website and it serves we
quite well - I imagine it would be useful for other applications where
more complex copying operations are required.
It basically works like this:
<taskdef name="tcopy" classname="TemplateCopy" classpath="."/>
<tcopy templatefile="${tfile}" outdir="${outdir}" srcdir="${srcdir}">
<include name="**/*.tmpl"/>
</tcopy>
<tcopy templatefile="${jsfile}" outdir="${outdir}"
srcdir="${srcdir}" ext=".js">
<include name="rolling.tmjs"/>
</tcopy>
What it is saying is, for every file in the include list, make a token
replacement copy of the file "templatefile" to "outdir" with the
appropriate extension. So if srcdir contained 10 *.tmpl files, then 10
files (with the default *.html extension) will end up in the outdir
location, where the values in the *.tmpl files are inserted into the
base "templatefile".
In other words, I have one templatefile that contains generic
information plus some tokens:
<html>
<head>
<title>@TITLE@</title>
</head>
<body>
<h1>Some general info</h1>
@CONTENT@
</body>
</html>
and then some others - let's say "welcome.tmpl" - that contain only
token, value pairs:
@TITLE@
Welcome page
@CONTENT@
<p>Welcome to my page</p>
Then the resulting page would be "welcome.html" in the outdir directory.
Is there any interest in including this with optional tasks?
-rob
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: Any use for an optional template copy task?
Posted by Rob Harvey <oz...@gmail.com>.
I believe so, because you have to manage files quite closely in the
build.xml file (e.g. you add a new file in your project and have to
insert a new line in the build.xml file). In fact, the task uses
filtersets but manages how they are called.
It wasn't obvious to me but there may be a simple way to do this
without my task - although I did try several things before I wrote it.
-rob
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: Any use for an optional template copy task?
Posted by Martijn Kruithof <jk...@apache.org>.
Rob Harvey wrote:
>Hi,
>I wrote a Task recently that alters files as they are copied to
>different directories. I used it to create a website and it serves we
>quite well - I imagine it would be useful for other applications where
>more complex copying operations are required.
>It basically works like this:
> <taskdef name="tcopy" classname="TemplateCopy" classpath="."/>
> <tcopy templatefile="${tfile}" outdir="${outdir}" srcdir="${srcdir}">
> <include name="**/*.tmpl"/>
> </tcopy>
> <tcopy templatefile="${jsfile}" outdir="${outdir}"
>srcdir="${srcdir}" ext=".js">
> <include name="rolling.tmjs"/>
> </tcopy>
>
>What it is saying is, for every file in the include list, make a token
>replacement copy of the file "templatefile" to "outdir" with the
>appropriate extension. So if srcdir contained 10 *.tmpl files, then 10
>files (with the default *.html extension) will end up in the outdir
>location, where the values in the *.tmpl files are inserted into the
>base "templatefile".
>
>In other words, I have one templatefile that contains generic
>information plus some tokens:
> <html>
> <head>
> <title>@TITLE@</title>
> </head>
> <body>
> <h1>Some general info</h1>
> @CONTENT@
> </body>
> </html>
>
>and then some others - let's say "welcome.tmpl" - that contain only
>token, value pairs:
>
>@TITLE@
> Welcome page
>@CONTENT@
> <p>Welcome to my page</p>
>
>Then the resulting page would be "welcome.html" in the outdir directory.
>
>Is there any interest in including this with optional tasks?
>
> -rob
>
>
What would be the added value over the current copy task with the use of
a filterset?
Martijn
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org