Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use ant to wrap html code in static template

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:

  1. Copy all HTML files to public/ directory
  2. Each HTML file in public/ directory should also have code from _template.html wrapped around the original content.

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>
like image 972
Philipp Avatar asked Dec 03 '25 07:12

Philipp


1 Answers

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 :)

like image 50
FailedDev Avatar answered Dec 05 '25 22:12

FailedDev