From 53a0866720e4735b5437eedd886e4d3b95dc5977 Mon Sep 17 00:00:00 2001 From: Vincent PICOT Date: Tue, 16 Apr 2019 18:50:22 -0400 Subject: [PATCH 1/2] FIX Check os to edit path for saas library Replace \\ from into / if windows (Python convert back automatically to windows path) --- bootstrap_customizer/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bootstrap_customizer/utils.py b/bootstrap_customizer/utils.py index 0a26f88..b8c6171 100644 --- a/bootstrap_customizer/utils.py +++ b/bootstrap_customizer/utils.py @@ -2,6 +2,7 @@ import logging import os import sass +from sys import platform from django.conf import settings from django.contrib.staticfiles import finders from django.template.loader import render_to_string @@ -51,6 +52,8 @@ def generate_above_the_fold_css(theme): """ context = get_scss_template_context(theme) scss_string = render_to_string('bootstrap_customizer/bootstrap_above_the_fold.scss', context) + if platform == "win32" or platform == "cygwin": + scss_string = scss_string.replace("\\", "/") return sass.compile(string=scss_string, output_style='compressed') @@ -61,6 +64,8 @@ def generate_below_the_fold_css(theme): """ context = get_scss_template_context(theme) scss_string = render_to_string('bootstrap_customizer/bootstrap_below_the_fold.scss', context) + if platform == "win32" or platform == "cygwin": + scss_string = scss_string.replace("\\", "/") return sass.compile(string=scss_string, output_style='compressed') @@ -72,6 +77,8 @@ def generate_full_css(theme): sass_variables = convert_fields_to_scss_variables(theme) variable_section = '\n'.join('{}: {};'.format(key, value) for key, value in sass_variables.items()) bootstrap_import_section = '@import "{}";'.format(finders.find('bootstrap/scss/bootstrap.scss')) + if platform == "win32" or platform == "cygwin": + bootstrap_import_section = bootstrap_import_section.replace("\\", "/") scss_string = '\n\n'.join([variable_section, bootstrap_import_section]) return sass.compile(string=scss_string, output_style='compressed') From f879b9f37abbad350a38bfd542ffc0aeba7a7f98 Mon Sep 17 00:00:00 2001 From: Vincent PICOT Date: Wed, 17 Apr 2019 00:45:09 -0400 Subject: [PATCH 2/2] Make the code a bit DRYer --- bootstrap_customizer/utils.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/bootstrap_customizer/utils.py b/bootstrap_customizer/utils.py index b8c6171..ada1f80 100644 --- a/bootstrap_customizer/utils.py +++ b/bootstrap_customizer/utils.py @@ -8,12 +8,20 @@ from django.template.loader import render_to_string +# Constants for OS path separator +POSIX_PATH_SEPARATOR = '/' +WINDOWS_PATH_SEPARATOR = '\\' + # Disable cssutils logging cssutils.log.setLevel(logging.FATAL) # Configure cssutils parsers to output minified CSS cssutils.ser.prefs.useMinified() +def is_windows_environment(): + return platform == 'win32' or platform == 'cygwin' + + def convert_fields_to_scss_variables(theme): """ Converts the relevant fields from the supplied theme into a @@ -52,8 +60,8 @@ def generate_above_the_fold_css(theme): """ context = get_scss_template_context(theme) scss_string = render_to_string('bootstrap_customizer/bootstrap_above_the_fold.scss', context) - if platform == "win32" or platform == "cygwin": - scss_string = scss_string.replace("\\", "/") + if is_windows_environment(): + scss_string = scss_string.replace(WINDOWS_PATH_SEPARATOR, POSIX_PATH_SEPARATOR) return sass.compile(string=scss_string, output_style='compressed') @@ -64,8 +72,8 @@ def generate_below_the_fold_css(theme): """ context = get_scss_template_context(theme) scss_string = render_to_string('bootstrap_customizer/bootstrap_below_the_fold.scss', context) - if platform == "win32" or platform == "cygwin": - scss_string = scss_string.replace("\\", "/") + if is_windows_environment(): + scss_string = scss_string.replace(WINDOWS_PATH_SEPARATOR, POSIX_PATH_SEPARATOR) return sass.compile(string=scss_string, output_style='compressed') @@ -77,8 +85,8 @@ def generate_full_css(theme): sass_variables = convert_fields_to_scss_variables(theme) variable_section = '\n'.join('{}: {};'.format(key, value) for key, value in sass_variables.items()) bootstrap_import_section = '@import "{}";'.format(finders.find('bootstrap/scss/bootstrap.scss')) - if platform == "win32" or platform == "cygwin": - bootstrap_import_section = bootstrap_import_section.replace("\\", "/") + if is_windows_environment(): + bootstrap_import_section = bootstrap_import_section.replace(WINDOWS_PATH_SEPARATOR, POSIX_PATH_SEPARATOR) scss_string = '\n\n'.join([variable_section, bootstrap_import_section]) return sass.compile(string=scss_string, output_style='compressed')