I have several HTML files located in different places (in a common root), like this:
index.html
moduleA/list.html
moduleA/add.html
moduleB/list.html
moduleB/add.html
...
Additionally I have one file called _template.html, that contains HTML code and a placeholder #CONTENT#.
What I need:
I use ANT to copy the files, but I cannot figure out how to wrap the template-code around the code... My ANT script looks like this:
<project default="build">
<target name="build">
<copy todir="${dir.intermediate}/temp">
<fileset dir="${dir.source}" includes="**/*.html"/>
</copy>
</target>
</project>
Example:
index.html
<div>This is the index-page</div>
_template.html
<html>
<head><title>Page-Title</title></head>
<body>
#CONTENT#
</body>
</html>
Should generate output file:
<html>
<head><title>Page-Title</title></head>
<body>
<div>This is the index-page</div>
</body>
</html>
That's perfectly possible with pure ant tasks :
First use loadfile to load the "replacement" string into a property :
<loadfile property="replacement" srcFile="index.html"/>
Then after copying your template somehwere, where the final file will be do this :
<replaceregexp file="${my.final.file}"
match="#CONTENT#"
replace="${replacement}"
/>
That's it your file should now be the desired one :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With