-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcompiler.py
39 lines (30 loc) · 1.23 KB
/
compiler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from pipeline.compilers import CompilerBase
from django.utils.encoding import smart_str
from django.conf import settings
import scss
import os
def add_to_scss_path(path):
load_paths = scss.config.LOAD_PATHS.split(
',') # split it up so we can a path check.
if path not in load_paths:
load_paths.append(path)
scss.config.LOAD_PATHS = ','.join(load_paths)
class CompassCompiler(CompilerBase):
output_extension = 'css'
def match_file(self, filename):
return filename.endswith(('.scss', '.sass'))
def compile_file(self, content, path, force=False, outdated=False):
add_to_scss_path(os.path.dirname(
path)) # add the current path of the parsed
# file to enable the local @import
if force or outdated:
self.save_file(path, scss.Scss(scss_opts={
'compress': False,
'debug_info': settings.DEBUG,
}).compile(None, content))
def save_file(self, path, content):
return open(path, 'w').write(smart_str(content))
# setup scss load path
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
scss_path = os.path.join(root, 'pipeline_compass', 'compass')
add_to_scss_path(scss_path)