From 79c769351d46ac587aba5a4b68146dcf48b793f7 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Tue, 2 May 2017 00:31:21 +0200 Subject: [PATCH] Add simple way to compile scss files --- README.md | 4 +- core/management/commands/compilestatic.py | 72 +++++++++++++++++++++++ sith/settings.py | 2 +- 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 core/management/commands/compilestatic.py diff --git a/README.md b/README.md index efa83cea..3b0c2b1d 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,8 @@ The development is done with sqlite, but it is advised to set a more robust DBMS ### Collecting statics for production: ``` -./manage.py collectstatic --ignore=.scss -./manage.py compilescss +./manage.py collectstatic +./manage.py compilestatic ``` ### Misc about development diff --git a/core/management/commands/compilestatic.py b/core/management/commands/compilestatic.py new file mode 100644 index 00000000..a4fd89df --- /dev/null +++ b/core/management/commands/compilestatic.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +# -*- coding:utf-8 -* +# +# Copyright 2016,2017 +# - Sli +# +# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM, +# http://ae.utbm.fr. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License a published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple +# Place - Suite 330, Boston, MA 02111-1307, USA. +# +# + +import os +import sass +from django.core.management.base import BaseCommand + +class Command(BaseCommand): + help = "Comile scss files from static folder" + + def compilescss(self, folder): + to_compile = [] + for file in os.listdir(folder): + file = os.path.join(folder, file) + if os.path.isdir(file): + self.compilescss(file) + else: + path, ext = os.path.splitext(file) + if ext == ".scss": + to_compile.append(file) + + for f in to_compile: + print("compilling %s" % f) + with open(f, "r") as oldfile: + with open(f.replace('.scss', '.css'), "w") as newfile: + newfile.write(sass.compile(string=oldfile.read())) + + def removescss(self, folder): + to_remove = [] + for file in os.listdir(folder): + file = os.path.join(folder, file) + if os.path.isdir(file): + self.removescss(file) + else: + path, ext = os.path.splitext(file) + if ext == ".scss": + to_remove.append(file) + for f in to_remove: + print("removing %s" % f) + os.remove(f) + + def handle(self, *args, **options): + + if 'static' in os.listdir(): + print("---- Compilling scss files ---") + self.compilescss('static') + print("---- Removing scss files ----") + self.removescss('static') + else: + print("No static folder avaliable, please use collectstatic before compilling scss") \ No newline at end of file diff --git a/sith/settings.py b/sith/settings.py index 93e06ceb..d4eb721d 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -188,7 +188,7 @@ SASS_PRECISION = 8 SASS_OUTPUT_STYLE = 'compact' -SASS_TEMPLATE_EXTS = ['.html','.jinja'] +SASS_TEMPLATE_EXTS = ['.jinja'] WSGI_APPLICATION = 'sith.wsgi.application'