Permalink
Browse files

Add Sass compilation hook to contrib/hooks.py

  • Loading branch information...
1 parent ea6b3a9 commit 663cbd9f761434ecf9c1e6291e6797935d508ee2 @robatron robatron committed Feb 24, 2012
Showing with 27 additions and 0 deletions.
  1. +27 −0 wok/contrib/hooks.py
View
@@ -1,6 +1,8 @@
# vim: set fileencoding=utf8 :
"""Some hooks that might be useful."""
+import os
+import subprocess
from StringIO import StringIO
import logging
@@ -53,3 +55,28 @@ def __call__(self, page):
sio_destination = StringIO()
tree.write(sio_destination)
page.rendered = sio_destination.getvalue()
+
+
+def compile_sass(output_dir):
+ '''
+ Compile Sass files -> CSS in the output directory.
+
+ Any .scss or .sass files found in the output directory will be compiled
+ to CSS using Sass. The compiled version of the file will be created in the
+ same directory as the Sass file with the same name and an extension of
+ .css. For example, foo.scss -> foo.css.
+
+ Dependencies:
+
+ - Ruby
+ - Sass (http://sass-lang.com)
+ '''
+ for root, dirs, files in os.walk(output_dir):
+ for f in files:
+ fname, fext = os.path.splitext(f)
+ if fext == ".scss" or fext == ".sass":
+ abspath = os.path.abspath(root)
+ sass_src = "%s/%s"%(abspath, f)
+ sass_dest = "%s/%s.css"%(abspath, fname)
+ sass_arg = "%s:%s"%(sass_src, sass_dest)
+ subprocess.call(['sass', sass_arg])

0 comments on commit 663cbd9

Please sign in to comment.