From b0c0af961799afba1baf218c548edd9551453f7a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 4 Mar 2022 12:40:06 -0800 Subject: [PATCH 1/2] Adds custom compile management command --- bookwyrm/management/commands/compilethemes.py | 32 +++++++++++++++++++ bookwyrm/settings.py | 4 --- bookwyrm/templates/layout.html | 4 +-- bw-dev | 2 +- 4 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 bookwyrm/management/commands/compilethemes.py diff --git a/bookwyrm/management/commands/compilethemes.py b/bookwyrm/management/commands/compilethemes.py new file mode 100644 index 00000000..0f83adeb --- /dev/null +++ b/bookwyrm/management/commands/compilethemes.py @@ -0,0 +1,32 @@ +""" Compile themes """ +import os +from django.contrib.staticfiles.utils import get_files +from django.contrib.staticfiles.storage import StaticFilesStorage +from django.core.files.base import ContentFile +from django.core.management.base import BaseCommand + +import sass +from sass_processor.processor import SassProcessor + +# pylint: disable=line-too-long +class Command(BaseCommand): + """Compile themes""" + + help = "Compile theme scss files" + + # pylint: disable=no-self-use,unused-argument + def handle(self, *args, **options): + """compile themes""" + storage = StaticFilesStorage() + theme_files = list(get_files(storage, location="css/themes")) + theme_files = [t for t in theme_files if t[-5:] == '.scss'] + for filename in theme_files: + path = storage.path(filename) + content = sass.compile( + filename=path, + include_paths=SassProcessor.include_paths, + ) + basename, _ = os.path.splitext(path) + destination_filename = basename + '.css' + print(f"saving f{destination_filename}") + storage.save(destination_filename, ContentFile(content)) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index d698a34d..7d04a046 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -189,10 +189,6 @@ STATICFILES_FINDERS = [ SASS_PROCESSOR_INCLUDE_FILE_PATTERN = r"^.+\.[s]{0,1}(?:a|c)ss$" -SASS_PROCESSOR_INCLUDE_DIRS = [ - os.path.join(BASE_DIR, ".css-config-sample"), -] - # minify css is production but not dev if not DEBUG: SASS_OUTPUT_STYLE = "compressed" diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index a57063cb..dc18643a 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -1,14 +1,14 @@ {% load layout %} +{% load sass_tags %} {% load i18n %} {% load static %} -{% load sass_tags %} {% block title %}BookWyrm{% endblock %} - {{ site.name }} - + diff --git a/bw-dev b/bw-dev index 89cc8d8c..41971bb8 100755 --- a/bw-dev +++ b/bw-dev @@ -154,7 +154,7 @@ case "$CMD" in --config dev-tools/.stylelintrc.js ;; compilescss) - runweb python manage.py compilescss + runweb python manage.py compilethemes runweb python manage.py collectstatic --no-input ;; collectstatic_watch) From f26106fffdde86221c34dcdae9f0ef5a42d7b2cc Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 4 Mar 2022 12:42:43 -0800 Subject: [PATCH 2/2] Python formatting --- bookwyrm/management/commands/compilethemes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/management/commands/compilethemes.py b/bookwyrm/management/commands/compilethemes.py index 0f83adeb..e3fba632 100644 --- a/bookwyrm/management/commands/compilethemes.py +++ b/bookwyrm/management/commands/compilethemes.py @@ -19,7 +19,7 @@ class Command(BaseCommand): """compile themes""" storage = StaticFilesStorage() theme_files = list(get_files(storage, location="css/themes")) - theme_files = [t for t in theme_files if t[-5:] == '.scss'] + theme_files = [t for t in theme_files if t[-5:] == ".scss"] for filename in theme_files: path = storage.path(filename) content = sass.compile( @@ -27,6 +27,6 @@ class Command(BaseCommand): include_paths=SassProcessor.include_paths, ) basename, _ = os.path.splitext(path) - destination_filename = basename + '.css' + destination_filename = basename + ".css" print(f"saving f{destination_filename}") storage.save(destination_filename, ContentFile(content))