Jan-Jaap Driessen avatar Jan-Jaap Driessen committed dac5207

Rename scss to sass. Add minification to lesscss.

Comments (0)

Files changed (3)

fanstatic/compiler.py

         return os.path.join(directory, '%s%s.%s' % (base, suffix, cls.target_extension))
 
 
-class SCSS(Compiler):
+class SASS(Compiler):
     source_extension = 'scss'
     target_extension = 'css'
 
     def __call__(cls, path, mode=None):
         # From the sass command line utility:
         # -t, --style NAME   Output style. Can be nested (default), compact, compressed, or expanded.
+        options = ''
         if mode == DEBUG:
-            options = '-t expanded'
+            options += '-t expanded'
         elif mode == MINIFIED:
-            options = '-t compressed'
-        else:
-            options = ''
+            options += '-t compressed'
 
-        cmd = 'sass %s %s %s' % (options, path, cls.target_path(path, mode=mode))
-        p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        cmd = ['sass', options, path, cls.target_path(path, mode=mode)]
+        p = subprocess.Popen(' '.join(cmd), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         p.wait()
         if p.returncode != 0:
             raise CompilerException(p.stderr.read())
 
     @classmethod
     def __call__(cls, path, mode=None):
-        cmd = 'coffee --bare --compile --print %s' % path
+        cmd = ['coffee', '--bare', '--compile', '--print', path]
         
-        p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        p = subprocess.Popen(' '.join(cmd), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         p.wait()
         if p.returncode != 0:
             raise CompilerException(p.stderr.read())
     source_extension = 'less'
     target_extension = 'css'
 
+    minified = True
+
     @staticmethod
     def available():
         try:
 
     @classmethod
     def __call__(cls, path, mode=None):
-        cmd = 'lessc %s' % path
-        
-        # XXX To output minified CSS, simply pass the -x option.
+        cmd = ['lessc', path]
+        if mode == MINIFIED:
+            # To output minified CSS, simply pass the -x option.
+            cmd.insert(1, '-x')
 
-        p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        p = subprocess.Popen(' '.join(cmd), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         p.wait()
         if p.returncode != 0:
             raise CompilerException(p.stderr.read())

fanstatic/test_compiler.py

 from fanstatic import Minifier, Compiler
 from fanstatic.core import UnknownResourceExtensionError, ConfigurationError
 from fanstatic.core import ProcessorNotFoundError
-from fanstatic.compiler import CoffeeScript, SCSS, LessCSS
+from fanstatic.compiler import CoffeeScript, SASS, LessCSS
 from fanstatic.compiler import CompilerException
 import fanstatic.registry
 
 
     compiler = LessCSS()
     compiler(str(style))
-    assert open(compiler.target_path(str(style))).read() == '''\
+    assert tmpdir.join('style.css').read() == '''\
 #header {
   color: #4d926f;
 }
   color: #4d926f;
 }
 '''
+    compiler(str(style), mode=MINIFIED)
+    assert tmpdir.join('style-min.css').read() == '''\
+#header{color:#4d926f;}
+h2{color:#4d926f;}
+'''
+
     with_syntax_error = tmpdir.join('error.less')
     with_syntax_error.write('.frop {')
     # If the input is invalid, should raise a compiler error.
         compiler(str(with_syntax_error))
 
 
-@pytest.mark.skipif('not SCSS.available()')
+@pytest.mark.skipif('not SASS.available()')
 def test_scsscompiler(tmpdir):
     # from http://sass-lang.com/tutorial.html :
     style = tmpdir.join('style.scss')
   }
 }''')
 
-    compiler = SCSS()
+    compiler = SASS()
     compiler(str(style))
     assert tmpdir.join('style.css').read() == '''\
 #navbar {
             'serf = fanstatic:make_serf',
             ],
         'fanstatic.compilers': [
-            'scss = fanstatic.compiler:SCSS',
+            'sass = fanstatic.compiler:SASS',
             'lesscss = fanstatic.compiler:LessCSS',
             'coffeescript = fanstatic.compiler:CoffeeScript',
             ],
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.