Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create a SiteMesh configuration file.
  2. Register the SiteMeshTask with Ant
  3. Define the <sitemesh <sitemesh/> node.
  4. Execute Ant

1. Creating the SiteMesh configuration file

The SiteMeshTask can be given a configuration file to tell SiteMesh how to decorate files. The power of this feature is that the configuration is then externalized from the buid build.xml file. In our first two examples, we're going to show how to use this form of the SiteMeshTask. Below is a very simple SiteMesh configuration file that applies the main.html decorator to all pages.<sitemesh>
<mapping

No Format

<sitemesh>
  <mapping path="/*" decorator="/decorators/main.html"/>

...


</sitemesh>

2. Registering SiteMeshTask with Ant

In order to use SiteMesh from within Ant, the first thing you will need to do is register the SiteMeshTask with Ant using the following <taskdef <taskdef/> declaration declaration.

No Format

<project name="my-ant-project">

...



  <taskdef name="sitemesh"

...

 
           classname="org.sitemesh.ant.SiteMeshTask"

...


           classpath="path/to/sitemesh-3.x.jar"/>

...



  ...

...



</project>

For more information on registering custom tasks within Ant, please see Writing Ant Tasks.

3. Define the <sitemesh<sitemesh/> node> node.

Now that we've created the SiteMesh configuration file and registered the SiteMeshTask with Ant, it's time to start using SiteMesh within our tasks.

...

Let's look at how to provide <sitemesh <sitemesh/> with  with a configuration file and tell it what directories to include or exclude.

In this example, we're going to process all of the files stored in "project/src" and place the decorated files into "project/build".

No Format

<project name="my-ant-project">

...




  <target name="my-target">

...


    <sitemesh srcdir="project/src"

...


              config="project/sitemesh.xml"

...


              destdir="project/build"

...


              includes="*/.html"

...


              excludes="decorators/*"/>

...


  </target>

...





</project>

The benefit to the above is that all configuration is externalized from the the build.xml file.

Using the sitemesh task with the sitemeshfileset

In the below example, multiple source folders are used by provided a sitemeshfileset. This provides greater control over what folders should be included or excluded, but still leverage a common destination folder and configuration file.

No Format

<project name="my-ant-project">

...



  <sitemesh destdir="site/documentation"

...


            config="config/sitemesh.xml">

...



    <sitemeshfileset dir="documentation">

...


      <include name="*/.html"/>

...


      <exclude name="private/*"/>

...


    </sitemeshfileset>

...



    <sitemeshfileset dir="presentation">

...


      <include name="*/.html"/>

...


    </sitemeshfileset>

...



  </sitemesh>

...



</project>
Using the sitemesh task with the sitemeshfileset with an associated decorator

In our finaly example, a decorator will be used on each sitemeshfileset.

No Format

<project name="my-ant-project">

...



  <target name="generate-with-custom-decorator"

...


description="Generate static content that's internal to the company.">

...


<sitemesh destdir="site/documentation">

...


<sitemeshfileset dir="documentation"

...


decorator="decorators/private.html">

...


<include name="private/*.html"/>

...


</sitemeshfileset>

...


</sitemesh>

...


</target>

...



</project>