Permalink
Browse files

add sass compiling signal receiver

  • Loading branch information...
jcarbaugh committed Apr 11, 2011
1 parent 3c0794b commit dfd6820a9f8eaa0e5ffac47dde62e5a0f4191e2b
Showing with 56 additions and 8 deletions.
  1. +1 −0 .gitignore
  2. +2 −2 mediasync/__init__.py
  3. +3 −2 mediasync/conf.py
  4. +20 −1 mediasync/signals.py
  5. +5 −0 mediasync/tests/media/css/3.scss
  6. +25 −3 mediasync/tests/tests.py
View
@@ -1,5 +1,6 @@
*.pyc
.project
.pydevproject
+.sass-cache/
build
mediasync_example
View
@@ -130,7 +130,7 @@ def sync(client=None, force=False, verbose=True):
continue
filedata, dirname = filedata
- content_type = mimetypes.guess_type(joinfile)[0] or 'application/octet-stream'
+ content_type = mimetypes.guess_type(joinfile)[0] or msettings['DEFAULT_MIMETYPE']
remote_path = joinfile
if dirname:
@@ -156,7 +156,7 @@ def sync(client=None, force=False, verbose=True):
filepath = os.path.join(dirpath, filename)
remote_path = "%s/%s" % (dirname, filename)
- content_type = mimetypes.guess_type(filepath)[0] or 'application/octet-stream'
+ content_type = mimetypes.guess_type(filepath)[0] or msettings['DEFAULT_MIMETYPE']
if not is_syncable_file(os.path.basename(filename)) or not os.path.isfile(filepath):
continue # hidden file or directory, do not upload
View
@@ -2,12 +2,13 @@
from mediasync.processors import slim
_settings = {
- 'CSS_PATH': "",
+ 'CSS_PATH': '',
+ 'DEFAULT_MIMETYPE': 'application/octet-stream',
'DOCTYPE': 'html5',
'EMULATE_COMBO': False,
'EXPIRATION_DAYS': 365,
'JOINED': {},
- 'JS_PATH': "",
+ 'JS_PATH': '',
'STATIC_ROOT': getattr(settings, 'STATIC_ROOT', None) or
getattr(settings, 'MEDIA_ROOT', None),
'STATIC_URL': getattr(settings, 'STATIC_URL', None) or
View
@@ -1,7 +1,10 @@
from django.core import management
from django.core.management.base import CommandError
from django.dispatch import Signal
-from mediasync import SyncException
+from mediasync import SyncException, listdir_recursive
+from mediasync.conf import msettings
+import os
+import subprocess
pre_sync = Signal()
post_sync = Signal()
@@ -11,3 +14,19 @@ def collectstatic_receiver(sender, **kwargs):
management.call_command('collectstatic')
except CommandError:
raise SyncException("collectstatic management command not found")
+
+def sass_receiver(sender, **kwargs):
+
+ sass_cmd = msettings.get("SASS_COMMAND", "sass")
+
+ root = msettings['STATIC_ROOT']
+
+ for filename in listdir_recursive(root):
+
+ if filename.lower().endswith('scss'):
+
+ sass_path = os.path.join(root, filename)
+ css_path = sass_path[:-4] + "css"
+
+ cmd = "%s %s %s" % (sass_cmd, sass_path, css_path)
+ subprocess.call(cmd.split(' '))
@@ -0,0 +1,5 @@
+a {
+ color: #ce4dd6;
+ &:hover { color: #ffb3ff; }
+ &:visited { color: #c458cb; }
+}
View
@@ -2,17 +2,18 @@
from django.core.exceptions import ImproperlyConfigured
from django.dispatch import receiver
from hashlib import md5
+import glob
import httplib
import itertools
import os
import re
import time
import unittest
-from mediasync import backends, JS_MIMETYPES
+from mediasync import backends, JS_MIMETYPES, listdir_recursive
from mediasync.backends import BaseClient
from mediasync.conf import msettings
-from mediasync.signals import pre_sync, post_sync
+from mediasync.signals import pre_sync, post_sync, sass_receiver
import mediasync
import mimetypes
@@ -103,6 +104,7 @@ def testDirectoryListing(self):
allowed_files = [
'css/1.css',
'css/2.css',
+ 'css/3.scss',
'img/black.png',
'js/1.js',
'js/2.js',
@@ -116,6 +118,7 @@ def testSync(self):
to_sync = {
'css/1.css': 'text/css',
'css/2.css': 'text/css',
+ 'css/3.scss': msettings['DEFAULT_MIMETYPE'],
'css/joined.css': 'text/css',
'img/black.png': 'image/png',
'js/1.js': 'application/javascript',
@@ -219,7 +222,7 @@ def testSync(self):
response.read()
# verify valid content type
- content_type = mimetypes.guess_type(path)[0] or 'application/octet-stream'
+ content_type = mimetypes.guess_type(path)[0] or msettings['DEFAULT_MIMETYPE']
self.assertEqual(response.getheader("Content-Type", None), content_type)
# check for valid expires headers
@@ -344,6 +347,13 @@ def setUp(self):
msettings['BACKEND'] = 'mediasync.tests.tests'
self.client = backends.client()
+ def tearDown(self):
+ root = msettings['STATIC_ROOT']
+ for filename in glob.glob(os.path.join(root, "*/*.scss")):
+ path = filename[:-4] + "css"
+ if os.path.exists(path):
+ os.unlink(path)
+
def testSyncSignals(self):
self.client.called_presync = False
@@ -363,5 +373,17 @@ def postsync_receiver(sender, **kwargs):
self.assertTrue(self.client.called_presync)
self.assertTrue(self.client.called_postsync)
+
+ def testSassReceiver(self):
+
+ pre_sync.connect(sass_receiver)
+
+ mediasync.sync(self.client, force=True, verbose=False)
+
+ root = msettings['STATIC_ROOT']
+
+ for sass_path in glob.glob(os.path.join(root, "*/*.scss")):
+ css_path = sass_path[:-4] + "css"
+ self.assertTrue(os.path.exists(css_path))

0 comments on commit dfd6820

Please sign in to comment.