pythonlibsass

Python-libsass doesn't recognize sass syntax?


I am trying to compile sass with python-libsass package, am I doing something wrong? It seems that I am using the correct sass syntax but still getting wierd errors, it wants semicolons at the end of each line, very strange:

> pip install libsass
> Successfully installed libsass-0.13.3
...
>>> sass.compile(string='$a: 1\n$b: 2')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\anaconda\lib\site-packages\sass.py", line 640, in compile
    raise CompileError(v)
sass.CompileError: Error: Invalid CSS after "$b": expected 1 selector or at-rule, was ": 2"
        on line 2 of stdin
>> $b: 2
   ^

Solution

  • As far as I know you need the semicolon after each line in saas.

    Take a look at the docs

    So, in your example it should be:

    sass.compile(string='$a: 1;\n$b: 2;')
    

    UPDATE: If you actually want to see some output from the compiler you need to use the SASS properties that you set.

    Take this example:

    print sass.compile(string='$primary_color: blue;\n a { b { color: $primary_color; } }')
    

    will print out:

    a b {
      color: blue; }
    

    See how the variable $primary_color has been compiled to blue in resulting CSS