diff --git a/hshassets/__init__.py b/hshassets/__init__.py
index 6a3d0df5bd62d7b9b533696dacf5760e7548aedb..b7b1ef4fb68eaa3192bf800d69512453eb534641 100644
--- a/hshassets/__init__.py
+++ b/hshassets/__init__.py
@@ -1 +1,3 @@
+import logging
+logger = logging.getLogger('hshassets')
default_app_config = "hshassets.apps.HshassetsConfig"
diff --git a/hshassets/app_settings/defaults.py b/hshassets/app_settings/defaults.py
index b45d1079ddab8c45ce09f534fa3ab2ea8f0670ff..6144f9d6d7af62e1c41d950dfbbc188e6c0fd6e2 100644
--- a/hshassets/app_settings/defaults.py
+++ b/hshassets/app_settings/defaults.py
@@ -14,3 +14,14 @@ PIWIK_SITE_ID = None
# 'f4' - light blue for faculty 4, "Wirtschaft und Informatik" - rgb(220, 50, 5)
# 'f5' - light blue for faculty 5, "Diakonie, Gesundheit und Soziales" - rgb(210, 60, 150)
COLOR_SCHEME = 'service'
+
+# need some dependecies already available in another app for your own scss stuff?
+# no problem - by default we already add the hshassets/assets/sass/lib for you
+# but you might define your own, just add your tuple like this:
+# ('app_name', ['path/relative/to/appname/assets', 'another/relative/to/appname/assets']),
+# NOTE: the app must be added to INSTALLED_APPS
+# TODO: if you provide a str instead of tuple this path might be treated absolute or rel to project root!
+# read utils.get_scss_include_paths() for further information
+SCSS_INCLUDE_PATHS = [
+ ('hshassets', ['sass/lib/']),
+]
\ No newline at end of file
diff --git a/hshassets/utils.py b/hshassets/utils.py
index 5941c144f8dbe1d5d43c4ced74ec3f409aa0705a..a186301c05c47655ad9549ac06dbad73e0be5027 100644
--- a/hshassets/utils.py
+++ b/hshassets/utils.py
@@ -1,6 +1,7 @@
from django.conf import settings
-from hshassets.app_settings import COLOR_SCHEME
+from hshassets import logger
+from hshassets.app_settings import COLOR_SCHEME, SCSS_INCLUDE_PATHS
from importlib import import_module
@@ -32,6 +33,26 @@ def get_asset_directories():
return asset_apps
+def get_scss_include_paths(asset_directories):
+ """ Get additional include_paths for the scss parser - to be able to load e.g. bulma without getting insane """
+ include_paths = []
+ for app_name, rel_paths in SCSS_INCLUDE_PATHS:
+ if app_name in asset_directories.keys():
+ app_meta = asset_directories[app_name]
+ for rel_path in rel_paths:
+ lib_path = os.path.join(app_meta['asset_path'], rel_path)
+ if os.path.exists(lib_path):
+ include_paths.append(lib_path)
+ else:
+ logger.warning('You specified an additional scss path which can not be found: {}'.format(lib_path))
+ else:
+ logger.warning(
+ 'You specified the app {} in "SCSS_INCLUDE_PATHS" that can not be found. Is it in INSTALLED_APPS?'
+ .format(app_name)
+ )
+ return include_paths
+
+
def insert_corporate_design_import(filepath):
content = ''
tmp_filename = '/sass/_cd_init.tmp.scss'
@@ -51,7 +72,7 @@ def remove_corporate_design_import(filepath):
os.remove(filepath)
-def build_scss(app_name, app_directories, verbose=True):
+def build_scss(app_name, app_directories, include_paths, verbose=True):
if verbose:
print('Building \033[36msass\033[0m for app "{}" ...'.format(app_name))
@@ -75,10 +96,11 @@ def build_scss(app_name, app_directories, verbose=True):
with open(style_file, 'r') as cdfile:
content = cdfile.read() + '\n\n' + content
- sass_path = app_directories['asset_path'] + '/sass'
+ # add this apps sass folder to the include paths
+ include_paths = [os.path.join(app_directories['asset_path'], 'sass')] + include_paths
- expanded_output = sass.compile(string=content, include_paths=[sass_path], output_style='expanded')
- compressed_output = sass.compile(string=content, include_paths=[sass_path], output_style='compressed')
+ expanded_output = sass.compile(string=content, include_paths=include_paths, output_style='expanded')
+ compressed_output = sass.compile(string=content, include_paths=include_paths, output_style='compressed')
with open(app_directories['static_path'] + '/styles.css', 'w') as outfile:
outfile.write(expanded_output)
@@ -176,18 +198,20 @@ def discover_app(file_path):
app_directories = current_app_directories
break
- return (app_name, app_directories)
+ return app_name, app_directories
def do_everything(verbose=False):
- for app_name, app_directories in get_asset_directories().items():
+ asset_directories = get_asset_directories()
+ include_paths = get_scss_include_paths(asset_directories)
+ for app_name, app_directories in asset_directories.items():
if os.path.isdir(app_directories['static_path']):
shutil.rmtree(app_directories['static_path'])
os.makedirs(app_directories['static_path'])
- build_scss(app_name, app_directories, verbose=verbose)
+ build_scss(app_name, app_directories, include_paths, verbose=verbose)
build_javascript(app_name, app_directories, verbose=verbose)
copy_images(app_name, app_directories, verbose=verbose)
copy_fonts(app_name, app_directories, verbose=verbose)