Created
May 18, 2012 08:33
-
-
Save gbakernet/2723993 to your computer and use it in GitHub Desktop.
Sass Macros for Ant
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
<?xml version="1.0"?> | |
<!-- | |
# Sass Macros for Ant | |
# http://github.com/gbakernet | |
# Authored 2012 Glenn Baker; Licensed MIT */ | |
<sass> Usage - Compile sass files | |
* jarpath - is path to jruby-complete.jar and gem-sass.jar | |
* src - input | |
* dest - output | |
eg. <scss jarpath="${pathToJars}" src="${input}" dest="${output}" /> | |
<scss> Usage - Compile scss files | |
/ Same as <sass> | |
<installsass> Usage - Create gem-sass.jar from a "gem install sass" | |
* jarpath - is path to jruby-complete.jar | |
eg. <scssjar jarpath="${pathToJars}" /> | |
Inspiration from these posts | |
- http://stackoverflow.com/questions/1751479/sass-implementation-for-java | |
- http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar | |
--> | |
<project name="sassmacros" basedir="."> | |
<macrodef name="sass"> | |
<attribute name="src"/> | |
<attribute name="dest"/> | |
<attribute name="jarpath"/> | |
<attribute name="type" default="sass" /> | |
<sequential> | |
<echo message="Compiling scss/sass files..." /> | |
<path id="JRuby"> | |
<fileset file="@{jarpath}/jruby-complete-1.6.7.2.jar"/> | |
<fileset file="@{jarpath}/gem-sass.jar"/> | |
</path> | |
<property name="scss" value="@{src}/**/[^_]*.@{type}" /> | |
<property name="scss.build" value="@{dest}" /> | |
<script language="ruby" classpathref="JRuby"> | |
<![CDATA[ | |
require 'rubygems' | |
require 'sass' | |
require 'sass/exec' | |
files = Dir.glob($project.getProperty('scss')) | |
Dir.mkdir($project.getProperty('scss.build')) unless File.exists?($project.getProperty('scss.build')) | |
files.each do | |
| file | | |
puts '[SCSS] Compiling ' + File.basename(file, ".*") + '.scss' | |
opts = Sass::Exec::Sass.new(["-t", "compressed", file, File.join($project.getProperty('scss.build'), File.basename(file, ".*") + ".css")]) | |
opts.parse | |
end | |
]]> | |
</script> | |
<echo message="Done compiling files!" /> | |
</sequential> | |
</macrodef> | |
<macrodef name="scss"> | |
<attribute name="src"/> | |
<attribute name="dest"/> | |
<attribute name="jarpath"/> | |
<attribute name="type" default="scss" /> | |
<sequential> | |
<sass jarpath="@{jarpath}" src="@{src}" dest="@{dest}" type="scss" /> | |
</sequential> | |
</macrodef> | |
<macrodef name="installsass"> | |
<attribute name="jarpath"/> | |
<sequential> | |
<delete dir="@{jarpath}/sass-tmp"/> | |
<echo message="Warning: ruby gems may require HTTP_PROXY environment variable" /> | |
<echo message="Fetching SASS Gem" /> | |
<java dir="@{jarpath}" fork="true" failonerror="true" jar="@{jarpath}/jruby-complete-1.6.7.2.jar"> | |
<arg value="-S"/> | |
<arg value="gem"/> | |
<arg value="install"/> | |
<arg value="-i"/> | |
<arg path="@{jarpath}/sass-tmp/sass"/> | |
<arg value="sass"/> | |
<arg value="--no-rdoc"/> | |
<arg value="--no-ri"/> | |
</java> | |
<jar destfile="@{jarpath}/sass-tmp/gem-sass.jar" basedir="@{jarpath}/sass-tmp/sass" /> | |
<copy | |
file="@{jarpath}/sass-tmp/gem-sass.jar" | |
tofile="@{jarpath}/gem-sass.jar" overwrite="yes"/> | |
<echo message="Created lib/gem-sass.jar" /> | |
<delete dir="@{jarpath}/sass-tmp"/> | |
</sequential> | |
</macrodef> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Massively useful. Thanks for sharing this.