Created
April 5, 2018 16:56
-
-
Save driehle/36820f87e6a20d72a424c8ff3436ca53 to your computer and use it in GitHub Desktop.
Indico SCSS and Jinja validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The MIT License (MIT) | |
# Copyright (c) 2018 Dennis Riehle | |
import os | |
from pathlib import Path | |
from scss.compiler import Compiler | |
from scss.errors import SassBaseError | |
# get the path to SCSS folder and all files in it | |
dir_path = Path(os.path.dirname(os.path.realpath(__file__)) + "/../scss") | |
file_list = [f for f in dir_path.glob('*.scss') if f.is_file()] | |
# create a compiler object | |
compiler = Compiler(root=dir_path) | |
error = False | |
# iterate over all files and pass them to the compiler | |
for f in file_list: | |
print "Compiling '" + os.path.basename(str(f)) + "'..." | |
try: | |
compiler.compile(f) | |
print "Compilation succeeded.\n" | |
except SassBaseError as err: | |
error = True | |
print str(err) + "\n" | |
print "=" * 50 | |
# exit with a non-zero error code if errors occurred | |
if error: | |
print "Some errors occurred during compilation. Aborting." | |
exit(5) | |
# exit with zero if everything went fine | |
print "All SCSS files compiled successfully." | |
exit(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The MIT License (MIT) | |
# Copyright (c) 2018 Dennis Riehle | |
import os | |
from pathlib import Path | |
from jinja2 import Environment | |
from jinja2.exceptions import TemplateError | |
# get the path to SCSS folder and all files in it | |
dir_path = Path(os.path.dirname(os.path.realpath(__file__)) + "/../templates") | |
file_list = [f for f in dir_path.rglob('*.html') if f.is_file()] | |
# create an environment object for Jinja2 | |
env = Environment(extensions=['jinja2.ext.i18n']) | |
error = False | |
# iterate over all files and pass them to the environment | |
for template in file_list: | |
with open(str(template)) as t: | |
print "Parsing '" + str(template).replace(str(dir_path) + os.path.sep, "") + "'..." | |
try: | |
env.parse(t.read().decode("utf-8")) | |
print "Parsing succeeded.\n" | |
except (TemplateError, UnicodeError) as err: | |
error = True | |
print "Failed to parse template:" | |
print str(err) + "\n" | |
print "=" * 50 | |
# exit with a non-zero error code if errors occurred | |
if error: | |
print "Some errors occurred during compilation. Aborting." | |
exit(5) | |
# exit with zero if everything went fine | |
print "All templates parsed successfully." | |
exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment