Skip to content

Instantly share code, notes, and snippets.

@ericf
Created March 5, 2011 18:03
Show Gist options
  • Save ericf/856553 to your computer and use it in GitHub Desktop.
Save ericf/856553 to your computer and use it in GitHub Desktop.
Hooking Ant up with CSSembed
<?xml version="1.0" encoding="UTF-8"?>
<project name="cssembed" default="build_css">
<!-- dirs -->
<property name="libdir" value="${basedir}/lib" />
<property name="sourcedir" value="${basedir}/source" />
<property name="outputdir" value="${basedir}/build" />
<!-- ant utils -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${libdir}/ant-contrib-1.0b3.jar" />
</classpath>
</taskdef>
<!-- macros -->
<macrodef name="cssembed-datauri">
<attribute name="cssfile" />
<attribute name="destdir" />
<attribute name="destfile.suffix" default="datauri" />
<sequential>
<var name="cssembed-destfile" unset="true" />
<pathconvert property="cssembed-destfile">
<path path="@{cssfile}" />
<chainedmapper>
<mapper type="flatten" />
<mapper type="glob" from="*.css" to="*-@{destfile.suffix}.css" />
</chainedmapper>
</pathconvert>
<java classname="net.nczonline.web.cssembed.CSSEmbed" classpath="${libdir}/cssembed-0.3.3.jar">
<arg line="--charset" />
<arg line="UTF-8" />
<arg line="-o" />
<arg file="@{destdir}${cssembed-destfile}" />
<arg file="@{cssfile}" />
</java>
</sequential>
</macrodef>
<macrodef name="cssembed-mhtml">
<attribute name="cssfile" />
<attribute name="destdir" />
<attribute name="mhtmlroot" />
<attribute name="destfile.suffix" default="mhtml" />
<sequential>
<var name="cssembed-destfile" unset="true" />
<pathconvert property="cssembed-destfile">
<path path="@{cssfile}" />
<chainedmapper>
<mapper type="flatten" />
<mapper type="glob" from="*.css" to="*-@{destfile.suffix}.css" />
</chainedmapper>
</pathconvert>
<java classname="net.nczonline.web.cssembed.CSSEmbed" classpath="${libdir}/cssembed-0.3.3.jar">
<arg line="--charset" />
<arg line="UTF-8" />
<arg line="--mhtml" />
<arg line="--mhtmlroot" />
<arg line="@{mhtmlroot}" />
<arg line="-o" />
<arg file="@{destdir}${cssembed-destfile}" />
<arg file="@{cssfile}" />
</java>
</sequential>
</macrodef>
<macrodef name="cssembed">
<attribute name="cssfile" />
<attribute name="destdir" />
<attribute name="mhtmlroot" />
<sequential>
<cssembed-datauri cssfile="@{cssfile}" destdir="@{destdir}" />
<cssembed-mhtml cssfile="@{cssfile}" destdir="@{destdir}" mhtmlroot="@{mhtmlroot}" />
</sequential>
</macrodef>
<!-- targets -->
<target name="build_css">
<for param="cssfile">
<path>
<fileset dir="${sourcedir}/css/" includes="*.css" />
</path>
<sequential>
<copy file="@{cssfile}" todir="${deployment.dir}/css/" overwrite="true" preservelastmodified="true" />
<cssembed
cssfile="@{cssfile}"
destdir="${deployment.dir}/css/"
mhtmlroot="${deployment.url}/css/" />
</sequential>
</for>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment