Created
March 5, 2012 14:36
-
-
Save 0gust1/1978559 to your computer and use it in GitHub Desktop.
Ant CSS builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
These two following tasks are intended to be called via Maven. If you want to call these from Ant directly | |
you will have to manage dependencies (especially for the css_process task): | |
args4j-2.0.9.jar | |
commons-io-1.4.jar | |
commons-lang-2.3.jar | |
commons-math-1.1.jar | |
google-collections-1.0.jar | |
smartsprites-0.2.8.jar | |
--> | |
<target name="CSS_builder" description="generate a CSS file, based on a directory full of *.png files"> | |
<property name="css.dir" value="${basedir}/webapp/fwkstores/styles"/> | |
<property name="css.icons.subdir" value="icones"/> | |
<property name="icons.file.prefix" value="built-stcom"/> | |
<property name="css.icons.dir" value="${css.dir}/${css.icons.subdir}"/> | |
<echo message="Deleting previous built CSS file" /> | |
<delete file="${css.dir}/${icons.file.prefix}_icons.css" failonerror="false" /> | |
<echo>...Copy the base CSS template : contained in icons.css.tpl</echo> | |
<copy file="${css.dir}/icons.css.tpl" tofile="${css.dir}/${icons.file.prefix}_icons.css"></copy> | |
<echo file="${css.dir}/${icons.file.prefix}_icons.css" append="true"> | |
/** sprite: ${icons.file.prefix}_sprite; sprite-image: url('sprites/fwkstores_sprite.png'); sprite-layout: vertical */ | |
</echo> | |
<echo>...Build a corresponding CSS file out of a directory of png files</echo> | |
<for param="file"> | |
<path> | |
<fileset dir="${css.dir}/${css.icons.subdir}" casesensitive="yes"> | |
<include name="*.png"/> | |
</fileset> | |
</path> | |
<sequential> | |
<!--base filename--> | |
<basename property="filename.@{file}" file="@{file}" suffix=".png"/> | |
<!-- | |
Pattern to implement : | |
.icon-{filename}{background-image:url(icones/filename.png)} | |
.icon-{filename}{background: url(icones/application_lightning.png) no-repeat top left;} | |
--> | |
<echo>Treating ${filename.@{file}}... </echo> | |
<!--Echo one CSS rule by png file, generating SmartSprite compatible comments--> | |
<echo file="${css.dir}/${icons.file.prefix}_icons.css" append="true"> | |
.icon-${filename.@{file}}{ | |
background-repeat:no-repeat; | |
background-position:top left; | |
background-image:url(${css.icons.subdir}/${filename.@{file}}.png);/** sprite-ref: ${icons.file.prefix}_sprite; */ | |
}${line.separator} | |
</echo> | |
</sequential> | |
</for> | |
</target> | |
<target name="CSS_process" description="Generate a CSS sprite PNG file, defined by comments in a CSS file. Uses the smartsprite library" depends="CSS_builder"> | |
<property name="smartsprites.basedir" value="${basedir}/build"/> | |
<echo message="Deleting previous built PNG file" /> | |
<delete file="${css.dir}/sprites/fwkstores_sprite.png" failonerror="false" /> | |
<echo>SmartSprite base directory : ${smartsprites.basedir}</echo> | |
<available file="${smartsprites.basedir}/smartsprites.properties" property="smartsprites.properties.available" /> | |
<fail unless="smartsprites.properties.available"> | |
Please provide SmartSprite parameters in a 'smartsprites.properties' file. | |
</fail> | |
<property file="${smartsprites.basedir}/smartsprites.properties" /> | |
<taskdef resource="smartsprites.xml"> | |
<classpath> | |
<fileset dir="${smartsprites.basedir}"> | |
<include name="*.jar" /> | |
</fileset> | |
</classpath> | |
</taskdef> | |
<!-- | |
The simplest way to invoke SmartSprites is to provide a directory | |
in the rootdir parameter. SmartSprites will attempt to process all | |
files with 'css' extension from that directory. | |
<smartsprites rootdir="${root.dir.path}" | |
documentrootdir="${document.root.dir.path}" | |
outputdir="${output.dir.path}" | |
cssfileencoding="${css.file.encoding}" | |
cssfilesuffix="${css.file.suffix}" | |
loglevel="${log.level}" | |
spritepngdepth="${sprite.png.depth}" | |
spritepngie6="${sprite.png.ie6}" /> | |
--> | |
<!-- | |
Alternatively, instead of rootdir, you can provide individual CSS | |
files for processing using one or more nested <fileset> elements. | |
This type of invocation gives more fine-grained control over which | |
CSS files are processed. | |
For a description of how processing of individual CSS files relates | |
to rootdir and outputdir, please see the documentation on: | |
http://smartsprites.osinski.name/ | |
--> | |
<smartsprites documentrootdir="${document.root.dir.path}" | |
cssfileencoding="${css.file.encoding}" | |
cssfilesuffix="${css.file.suffix}" | |
loglevel="${log.level}" | |
spritepngdepth="${sprite.png.depth}" | |
spritepngie6="${sprite.png.ie6}"> | |
<fileset file="${css.dir}/${icons.file.prefix}_icons.css"/> | |
</smartsprites> | |
</target> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment