mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 17:41:08 +00:00
Merge pull request #2527 from chdorner/fix/compile-scss
Disable sass processer when not in debug mode
This commit is contained in:
commit
66dc070a26
7 changed files with 62 additions and 2 deletions
48
bookwyrm/management/commands/compile_themes.py
Normal file
48
bookwyrm/management/commands/compile_themes.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
""" Our own command to all scss themes """
|
||||
import glob
|
||||
import os
|
||||
|
||||
import sass
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from sass_processor.apps import APPS_INCLUDE_DIRS
|
||||
from sass_processor.processor import SassProcessor
|
||||
from sass_processor.utils import get_custom_functions
|
||||
|
||||
from bookwyrm import settings
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""command-line options"""
|
||||
|
||||
help = "SCSS compile all BookWyrm themes"
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def handle(self, *args, **options):
|
||||
"""compile"""
|
||||
themes_dir = os.path.join(
|
||||
settings.BASE_DIR, "bookwyrm", "static", "css", "themes", "*.scss"
|
||||
)
|
||||
for theme_scss in glob.glob(themes_dir):
|
||||
basename, _ = os.path.splitext(theme_scss)
|
||||
theme_css = f"{basename}.css"
|
||||
self.compile_sass(theme_scss, theme_css)
|
||||
|
||||
def compile_sass(self, sass_path, css_path):
|
||||
compile_kwargs = {
|
||||
"filename": sass_path,
|
||||
"include_paths": SassProcessor.include_paths + APPS_INCLUDE_DIRS,
|
||||
"custom_functions": get_custom_functions(),
|
||||
"precision": getattr(settings, "SASS_PRECISION", 8),
|
||||
"output_style": getattr(
|
||||
settings,
|
||||
"SASS_OUTPUT_STYLE",
|
||||
"nested" if settings.DEBUG else "compressed",
|
||||
),
|
||||
}
|
||||
|
||||
content = sass.compile(**compile_kwargs)
|
||||
with open(css_path, "w") as f:
|
||||
f.write(content)
|
||||
self.stdout.write("Compiled SASS/SCSS file: '{0}'\n".format(sass_path))
|
|
@ -193,7 +193,8 @@ STATICFILES_FINDERS = [
|
|||
]
|
||||
|
||||
SASS_PROCESSOR_INCLUDE_FILE_PATTERN = r"^.+\.[s]{0,1}(?:a|c)ss$"
|
||||
SASS_PROCESSOR_ENABLED = True
|
||||
# when debug is disabled, make sure to compile themes once with `./bw-dev compile_themes`
|
||||
SASS_PROCESSOR_ENABLED = DEBUG
|
||||
|
||||
# minify css is production but not dev
|
||||
if not DEBUG:
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
{% trans "Copy the theme file into the <code>bookwyrm/static/css/themes</code> directory on your server from the command line." %}
|
||||
</li>
|
||||
<li>
|
||||
{% trans "Run <code>./bw-dev collectstatic</code>." %}
|
||||
{% trans "Run <code>./bw-dev compile_themes</code> and <code>./bw-dev collectstatic</code>." %}
|
||||
</li>
|
||||
<li>
|
||||
{% trans "Add the file name using the form below to make it available in the application interface." %}
|
||||
|
|
7
bw-dev
7
bw-dev
|
@ -92,6 +92,7 @@ case "$CMD" in
|
|||
migrate
|
||||
migrate django_celery_beat
|
||||
initdb
|
||||
runweb python manage.py compile_themes
|
||||
runweb python manage.py collectstatic --no-input
|
||||
admin_code
|
||||
;;
|
||||
|
@ -122,6 +123,9 @@ case "$CMD" in
|
|||
prod_error
|
||||
runweb pytest -n 3 --cov-report term-missing "$@"
|
||||
;;
|
||||
compile_themes)
|
||||
runweb python manage.py compile_themes
|
||||
;;
|
||||
collectstatic)
|
||||
runweb python manage.py collectstatic --no-input
|
||||
;;
|
||||
|
@ -203,6 +207,7 @@ case "$CMD" in
|
|||
docker-compose build
|
||||
# ./update.sh
|
||||
runweb python manage.py migrate
|
||||
runweb python manage.py compile_themes
|
||||
runweb python manage.py collectstatic --no-input
|
||||
docker-compose up -d
|
||||
docker-compose restart web
|
||||
|
@ -256,6 +261,7 @@ case "$CMD" in
|
|||
migrate
|
||||
migrate django_celery_beat
|
||||
initdb
|
||||
runweb python manage.py compile_themes
|
||||
runweb python manage.py collectstatic --no-input
|
||||
admin_code
|
||||
;;
|
||||
|
@ -283,6 +289,7 @@ case "$CMD" in
|
|||
echo " dbshell"
|
||||
echo " restart_celery"
|
||||
echo " pytest [path]"
|
||||
echo " compile_themes"
|
||||
echo " collectstatic"
|
||||
echo " makemessages"
|
||||
echo " compilemessages [locale]"
|
||||
|
|
|
@ -14,6 +14,7 @@ dbshell \
|
|||
restart_celery \
|
||||
pytest \
|
||||
pytest_coverage_report \
|
||||
compile_themes \
|
||||
collectstatic \
|
||||
makemessages \
|
||||
compilemessages \
|
||||
|
@ -54,6 +55,7 @@ __bw_complete "$commands" "shell" "open the Python shell withi
|
|||
__bw_complete "$commands" "dbshell" "open the database shell within the web container"
|
||||
__bw_complete "$commands" "restart_celery" "restart the celery container"
|
||||
__bw_complete "$commands" "pytest" "run unit tests"
|
||||
__bw_complete "$commands" "compile_themes" "compile themes css files"
|
||||
__bw_complete "$commands" "collectstatic" "copy changed static files into the installation"
|
||||
__bw_complete "$commands" "makemessages" "extract all localizable messages from the code"
|
||||
__bw_complete "$commands" "compilemessages" "compile .po localization files to .mo"
|
||||
|
|
|
@ -11,6 +11,7 @@ dbshell
|
|||
restart_celery
|
||||
pytest
|
||||
pytest_coverage_report
|
||||
compile_themes
|
||||
collectstatic
|
||||
makemessages
|
||||
compilemessages
|
||||
|
|
|
@ -13,6 +13,7 @@ dbshell
|
|||
restart_celery
|
||||
pytest
|
||||
pytest_coverage_report
|
||||
compile_themes
|
||||
collectstatic
|
||||
makemessages
|
||||
compilemessages
|
||||
|
|
Loading…
Reference in a new issue