Download NetBeans!

20071112 Monday November 12, 2007

Processing HTML Files via Groovy's Extensions to Ant

Gpp is Groovy's Ant pre processor tool. I'm using its GppCopy task to replace instances of ${ant.something} with real header content. In the end, I'm using it to replace variables in HTML files with conditional content defined as Ant properties, which is all based on how Velocity does it. So, I have <h1>${ant.header}</h1> in my original HTML file, which becomes <h1>my customized header</h1> via the Ant scripts below:

<project name="Groovy Processor" default="all" basedir=".">
    
    <property name="header" value="my customized header"/>
    <property name="footer" value="my customized footer"/>
    
    <property name="html.files" value="/home/geertjan/some_folder_with_html_files"/>
    
    <target name="gppInit" description="gppInit">
        <typedef 
            classpath="lib/groovytools-ant-1.0.0.jar"
            resource="groovytools/ant/gpp/typedef.properties" />
        <taskdef 
            classpath="lib/groovytools-ant-1.0.0.jar"
            resource="groovytools/ant/gpp/taskdef.properties" />
    </target>
    
    <target name="gppcopy" description="gppcopy" depends="gppInit">
        <gppcopy verbose="true" overwrite="true" todir="dist/ijc">
            <fileset dir="${html.files}"/>
            <mapper type="glob" from="*.html" to="*.html" />
        </gppcopy>
    </target>
    
</project>

The manual for all of this is here. You can download the necessary JAR here and you need to have the groovy-all-1.x.jar on Ant's classpath, which you can do via the Ant section in the IDE's Options window.

The <gppcopy> task is cool, because it works the same as the standard <copy> task, except that you can leverage the Groovy Template Engine from within it. So, now I can convert my files (HTML or otherwise) directly from within NetBeans IDE.

In other news. Check this out if you're interested in the NetBeans Platform, especially if you're German speaking.

Nov 12 2007, 10:45:22 AM PST Permalink