-
Notifications
You must be signed in to change notification settings - Fork 66
/
apps.py
35 lines (29 loc) · 1.29 KB
/
apps.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
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import re
import os
from django.apps import apps, AppConfig
from django.conf import settings
from django.core.files.storage import get_storage_class
APPS_INCLUDE_DIRS = []
class SassProcessorConfig(AppConfig):
name = 'sass_processor'
verbose_name = "Sass Processor"
_storage = get_storage_class(import_path=settings.STATICFILES_STORAGE)()
_auto_include = getattr(settings, 'SASS_PROCESSOR_AUTO_INCLUDE', True)
_pattern = re.compile(getattr(settings, 'SASS_PROCESSOR_INCLUDE_FILE_PATTERN', r'^_.+\.(scss|sass)$'))
def ready(self):
if self._auto_include:
app_configs = apps.get_app_configs()
for app_config in app_configs:
static_dir = os.path.join(app_config.path, self._storage.base_url.strip(os.path.sep))
if os.path.isdir(static_dir):
self.traverse_tree(static_dir)
@classmethod
def traverse_tree(cls, static_dir):
"""traverse the static folders an look for at least one file ending in .scss/.sass"""
for root, dirs, files in os.walk(static_dir):
for filename in files:
if cls._pattern.match(filename):
APPS_INCLUDE_DIRS.append(static_dir)
return