From fb05e52ad0e7e120d66c422e8dbc2179dc092881 Mon Sep 17 00:00:00 2001 From: Nicolas PASCAL Date: Thu, 31 Oct 2019 11:40:37 +0100 Subject: [PATCH 1/7] Feature sass_src: custom_functions for lists sass --- sass_processor/processor.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/sass_processor/processor.py b/sass_processor/processor.py index 9099df3..8303282 100644 --- a/sass_processor/processor.py +++ b/sass_processor/processor.py @@ -79,8 +79,28 @@ def __call__(self, path): # otherwise compile the SASS/SCSS file into .css and store it filename_map = filename.replace(ext, '.css.map') + + # 1 fake custom_function in list for only master source scss + custom_function_docfunclist = {} + for custom_function in get_custom_functions() : + #check if tuple index out of range + if 'docfunclist' in custom_function.name: + custom_function_docfunclist.update({ custom_function.name :custom_function() }) + filename_scss = filename.replace(ext, '__replace_sass_cfunc_list.scss') + with open(filename, "rt") as fin: + with open(filename_scss , "wt") as fout: + for line in fin: + linem = None + for key , value in custom_function_docfunclist.items(): + if key in line: + linem = line.replace('{}{}'.format(key, '()'), value) + if linem: + fout.write(linem) + else: + fout.write(line) + compile_kwargs = { - 'filename': filename, + 'filename': filename_scss, 'source_map_filename': filename_map, 'include_paths': self.include_paths + APPS_INCLUDE_DIRS, 'custom_functions': get_custom_functions(), @@ -89,6 +109,7 @@ def __call__(self, path): compile_kwargs['precision'] = self.sass_precision if self.sass_output_style: compile_kwargs['output_style'] = self.sass_output_style + content, sourcemap = sass.compile(**compile_kwargs) content, sourcemap = force_bytes(content), force_bytes(sourcemap) @@ -131,10 +152,15 @@ def is_latest(self, sourcemap_filename, base): sourcemap_file = find_file(sourcemap_filename) if not sourcemap_file or not os.path.isfile(sourcemap_file): return False + sourcemap_mtime = os.stat(sourcemap_file).st_mtime + with open(sourcemap_file, 'r') as fp: sourcemap = json.load(fp) for srcfilename in sourcemap.get('sources'): + # 2 fake custom_function in list for master source scss + srcfilename = srcfilename.replace('__replace_sass_cfunc_list', '') + srcfilename = os.path.join(base, srcfilename) if not os.path.isfile(srcfilename) or os.stat(srcfilename).st_mtime > sourcemap_mtime: # at least one of the source is younger that the sourcemap referring it From 1f25ff3e6bd9558ecafad527fe0264016167a1da Mon Sep 17 00:00:00 2001 From: Nicolas PASCAL Date: Thu, 31 Oct 2019 11:55:31 +0100 Subject: [PATCH 2/7] Update README.md: custom_functions list (sass_src only) --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index f576d4d..4ac61e3 100644 --- a/README.md +++ b/README.md @@ -412,7 +412,43 @@ documentation. Such customized functions must accept parameters explicilty, otherwise `sass_processor` does not know how to map them. Variable argument lists therefore can not be used. +Starting from the fact that libsass can not use the custom_functions in a list scss natively. An action has been implemented to overcome this and concerns only the source sass_src file. +The conditions are as follows: ++ the name of the function must have "docfunclist" in its name (do custom_function list) ++ must not have args in parameter. + +Its operation is as follows: +``` +{% addtoblock "css" %}{% endaddtoblock %} +``` +From the main.scss files, a main__replace_sass_cfunc_list.scss file is created which has hard values in the files. +Then, to check if main.scss has been modified, the file css.map is scrapper to restore its source origin. + +Example: +settings.py +``` +SASS_PROCESSOR_CUSTOM_FUNCTIONS = { + 'get-color-primary-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_primary', + 'get-color-secondary-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_secondary', + 'get-color-success-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_success', + 'get-color-warning-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_warning', + 'get-color-danger-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_danger', + 'get-color-info-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_info', + 'get-color-light-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_light', + 'get-color-dark-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_dark', +} +``` + +main.scss: +``` +@import "variables"; +$theme-colors: ( + primary: get-color-primary() +); +@import "bootstrap/scss/bootstrap"; +@import "footer"; +``` ## Serving static files with S3 From 3ccb864029069ebb99de06e4969302d9b6af3035 Mon Sep 17 00:00:00 2001 From: Nicolas PASCAL Date: Thu, 31 Oct 2019 13:23:19 +0100 Subject: [PATCH 3/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ac61e3..457d1c5 100644 --- a/README.md +++ b/README.md @@ -444,7 +444,7 @@ main.scss: ``` @import "variables"; $theme-colors: ( - primary: get-color-primary() + primary: get-color-primary-docfunclist() ); @import "bootstrap/scss/bootstrap"; @import "footer"; From fb0a96f3a5c212573ff7e72c2fff41f7673facd3 Mon Sep 17 00:00:00 2001 From: Nicolas PASCAL Date: Thu, 31 Oct 2019 13:26:01 +0100 Subject: [PATCH 4/7] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 457d1c5..29a037a 100644 --- a/README.md +++ b/README.md @@ -429,14 +429,14 @@ Example: settings.py ``` SASS_PROCESSOR_CUSTOM_FUNCTIONS = { - 'get-color-primary-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_primary', - 'get-color-secondary-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_secondary', - 'get-color-success-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_success', - 'get-color-warning-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_warning', - 'get-color-danger-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_danger', - 'get-color-info-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_info', - 'get-color-light-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_light', - 'get-color-dark-docfunclist': 'cmsplugin_cascade.cascade_theme.utils.get_color_dark', + 'get-color-primary-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_primary', + 'get-color-secondary-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_secondary', + 'get-color-success-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_success', + 'get-color-warning-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_warning', + 'get-color-danger-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_danger', + 'get-color-info-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_info', + 'get-color-light-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_light', + 'get-color-dark-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_dark', } ``` From b73cfcf123296d04f54e485d4bfd7318a7b0fd50 Mon Sep 17 00:00:00 2001 From: Nicolas PASCAL Date: Fri, 1 Nov 2019 13:59:42 +0100 Subject: [PATCH 5/7] rename docfunclist to sass_processor_prepass --- sass_processor/processor.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sass_processor/processor.py b/sass_processor/processor.py index 8303282..a70aa08 100644 --- a/sass_processor/processor.py +++ b/sass_processor/processor.py @@ -81,17 +81,17 @@ def __call__(self, path): filename_map = filename.replace(ext, '.css.map') # 1 fake custom_function in list for only master source scss - custom_function_docfunclist = {} + custom_function_sass_processor_prepass = {} for custom_function in get_custom_functions() : #check if tuple index out of range - if 'docfunclist' in custom_function.name: - custom_function_docfunclist.update({ custom_function.name :custom_function() }) - filename_scss = filename.replace(ext, '__replace_sass_cfunc_list.scss') + if 'sass_processor_prepass' in custom_function.name: + custom_function_sass_processor_prepass.update({ custom_function.name :custom_function() }) + filename_scss = filename.replace(ext, '__sass_processor_prepass.scss') with open(filename, "rt") as fin: with open(filename_scss , "wt") as fout: for line in fin: linem = None - for key , value in custom_function_docfunclist.items(): + for key , value in custom_function_sass_processor_prepass.items(): if key in line: linem = line.replace('{}{}'.format(key, '()'), value) if linem: @@ -159,7 +159,7 @@ def is_latest(self, sourcemap_filename, base): sourcemap = json.load(fp) for srcfilename in sourcemap.get('sources'): # 2 fake custom_function in list for master source scss - srcfilename = srcfilename.replace('__replace_sass_cfunc_list', '') + srcfilename = srcfilename.replace('__sass_processor_prepass', '') srcfilename = os.path.join(base, srcfilename) if not os.path.isfile(srcfilename) or os.stat(srcfilename).st_mtime > sourcemap_mtime: From e6fedd78180623e59098323b34e1c449cd8cf5dc Mon Sep 17 00:00:00 2001 From: Nicolas PASCAL Date: Fri, 1 Nov 2019 14:11:22 +0100 Subject: [PATCH 6/7] rename to presass --- sass_processor/processor.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sass_processor/processor.py b/sass_processor/processor.py index a70aa08..cbd3115 100644 --- a/sass_processor/processor.py +++ b/sass_processor/processor.py @@ -81,17 +81,17 @@ def __call__(self, path): filename_map = filename.replace(ext, '.css.map') # 1 fake custom_function in list for only master source scss - custom_function_sass_processor_prepass = {} + custom_function_presass = {} for custom_function in get_custom_functions() : #check if tuple index out of range - if 'sass_processor_prepass' in custom_function.name: - custom_function_sass_processor_prepass.update({ custom_function.name :custom_function() }) - filename_scss = filename.replace(ext, '__sass_processor_prepass.scss') + if 'presass' in custom_function.name: + custom_function_presass.update({ custom_function.name :custom_function() }) + filename_scss = filename.replace(ext, '__presass.scss') with open(filename, "rt") as fin: with open(filename_scss , "wt") as fout: for line in fin: linem = None - for key , value in custom_function_sass_processor_prepass.items(): + for key , value in custom_function_presass.items(): if key in line: linem = line.replace('{}{}'.format(key, '()'), value) if linem: @@ -159,7 +159,7 @@ def is_latest(self, sourcemap_filename, base): sourcemap = json.load(fp) for srcfilename in sourcemap.get('sources'): # 2 fake custom_function in list for master source scss - srcfilename = srcfilename.replace('__sass_processor_prepass', '') + srcfilename = srcfilename.replace('__presass', '') srcfilename = os.path.join(base, srcfilename) if not os.path.isfile(srcfilename) or os.stat(srcfilename).st_mtime > sourcemap_mtime: From a3726ce006d5234021f41efccf4b49471123fd44 Mon Sep 17 00:00:00 2001 From: Nicolas PASCAL Date: Fri, 1 Nov 2019 14:15:16 +0100 Subject: [PATCH 7/7] rename to presass --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 29a037a..1019e34 100644 --- a/README.md +++ b/README.md @@ -415,28 +415,28 @@ know how to map them. Variable argument lists therefore can not be used. Starting from the fact that libsass can not use the custom_functions in a list scss natively. An action has been implemented to overcome this and concerns only the source sass_src file. The conditions are as follows: -+ the name of the function must have "docfunclist" in its name (do custom_function list) ++ the name of the function must have "presass" in its name. + must not have args in parameter. Its operation is as follows: ``` {% addtoblock "css" %}{% endaddtoblock %} ``` -From the main.scss files, a main__replace_sass_cfunc_list.scss file is created which has hard values in the files. +From the main.scss files, a main__presass.scss file is created which has hard values in the files. Then, to check if main.scss has been modified, the file css.map is scrapper to restore its source origin. Example: settings.py ``` SASS_PROCESSOR_CUSTOM_FUNCTIONS = { - 'get-color-primary-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_primary', - 'get-color-secondary-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_secondary', - 'get-color-success-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_success', - 'get-color-warning-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_warning', - 'get-color-danger-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_danger', - 'get-color-info-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_info', - 'get-color-light-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_light', - 'get-color-dark-docfunclist': 'cmsplugin_cascade.theme.utils.get_color_dark', + 'get-color-primary-presass': 'cmsplugin_cascade.theme.utils.get_color_primary', + 'get-color-secondary-presass': 'cmsplugin_cascade.theme.utils.get_color_secondary', + 'get-color-success-presass': 'cmsplugin_cascade.theme.utils.get_color_success', + 'get-color-warning-presass': 'cmsplugin_cascade.theme.utils.get_color_warning', + 'get-color-danger-presass': 'cmsplugin_cascade.theme.utils.get_color_danger', + 'get-color-info-presass': 'cmsplugin_cascade.theme.utils.get_color_info', + 'get-color-light-presass': 'cmsplugin_cascade.theme.utils.get_color_light', + 'get-color-dark-presass': 'cmsplugin_cascade.theme.utils.get_color_dark', } ``` @@ -444,7 +444,7 @@ main.scss: ``` @import "variables"; $theme-colors: ( - primary: get-color-primary-docfunclist() + primary: get-color-primary-presass() ); @import "bootstrap/scss/bootstrap"; @import "footer";