Skip to content

Instantly share code, notes, and snippets.

@MadeByPi
Created August 22, 2013 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MadeByPi/6308243 to your computer and use it in GitHub Desktop.
Save MadeByPi/6308243 to your computer and use it in GitHub Desktop.
Example Ant build task to check for SASS debug info in CSS files, and fail a build if it finds some.
<?xml version="1.0" encoding="UTF-8"?>
<project name="sass-debug-info-check" default="default" basedir="./">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${basedir}/tools/ant-contrib/ant-contrib-0.3.jar"/>
</classpath>
</taskdef>
<!-- Provide a css-check.properties file to override the default property settings...
cssDir = ${basedir}../path/to/your/built/site/files
cssIncludes = **/*.css
-->
<property file='${basedir}/css-check.properties'/>
<property name='cssDir' value='${basedir}'/>
<property name='cssIncludes' value='**/*.css'/>
<target name="default" depends="checkCSSForSASSDebugInfo">
<echo>checkCSSForSASSDebugInfo - All is well, there's no naughty SASS action here!</echo>
</target>
<target name="checkCSSForSASSDebugInfo">
<echo>Testing all files matching ${cssIncludes} within ${cssDir}</echo>
<!-- select all css files to be checked -->
<fileset id="cssToCheck" dir="${cssDir}" includes="${cssIncludes}">
<!-- checking for occurances of the string "@media -sass-debug-info" in our css... -->
<contains text="@media -sass-debug-info"/>
</fileset>
<!-- convert matches to a string for logging, seperate with a newline pathsep -->
<pathconvert pathsep="&#10;" property="badCSSMatches" refid="cssToCheck"/>
<!-- set haveBadCSS property true when badCSSMatches length > 0 -->
<condition property="haveBadCSS">
<length string="${badCSSMatches}" trim="true" when="greater" length="0" />
</condition>
<!-- if haveBadCSS - log the offending files and fail the build -->
<if>
<equals arg1="${haveBadCSS}" arg2="true" />
<then>
<echo level="error">Found SASS debug info in the following files:</echo>
<echo level="error">${badCSSMatches}</echo>
<fail message="Found SASS debug info in the CSS!" />
</then>
<else>
<echo>No SASS debug info found in the tested CSS files.</echo>
</else>
</if>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment