From fe489cdea6ee621affd51888a0192fe9c28f84ab Mon Sep 17 00:00:00 2001 From: L3D Date: Tue, 21 Mar 2023 19:36:28 +0100 Subject: [PATCH] mkae it work with python 3.11 --- lektor_render_template.py | 48 +++++++++++++++++++++++---------------- setup.py | 4 ++-- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/lektor_render_template.py b/lektor_render_template.py index 32cbd46..4372595 100644 --- a/lektor_render_template.py +++ b/lektor_render_template.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """ Import lektor plugin stuff """ +from os import makedirs from lektor.pluginsystem import Plugin from lektor.project import Project from lektor.context import get_ctx @@ -8,6 +9,7 @@ from scour.scour import scourString from scour.scour import sanitizeOptions as sanitizeScourOptions from scour.scour import parse_args as parseScourArgs + def optimize_svg(source_svg): """ using scour to optimize and minify svg """ scour_options = parseScourArgs([ @@ -23,7 +25,10 @@ def optimize_svg(source_svg): # pylint: disable=too-many-arguments def render_template(env, pad, filepath, label_name, label_value, color): - """ Render my custom Jinja2 Template 'galaxy.svg' with the given variables as input and pass it to a svg optimizer """ + """ + Render my custom Jinja2 Template 'galaxy.svg' with + the given variables as input and pass it to a svg optimizer + """ # Prepare Final Variables for galaxy.svg font_spacing = int(7) rendered_title = f"{label_value}: {label_name}" @@ -35,6 +40,7 @@ def render_template(env, pad, filepath, label_name, label_value, color): right_box_position = float(int(overal_width - 132)-0.007) # Create an optimized SVG File + makedirs('assets/svg/', exist_ok=True) with open(f"assets/{filepath}", 'w', encoding='UTF-8') as outputfile: outputfile.write( optimize_svg( @@ -80,25 +86,27 @@ def generate_svg(inputdict, **options): filepath = f"/svg/{svg_name}_{svg_label}.svg" # File Color - match svg_label: - case 'ansible-galaxy': - color = '#FF6600' - case 'license': - color = '#064ccf' - case 'maintainance': - match svg_state: - case 'well': - color = '#cd02fa' - case 'true': - color = '#8a00a6' - case 'poor': - color = '#5d0070' - case 'false': - color = '#220029' - case _: - color = '#000000' - case _: - color = '#e74c3c' + label_color_map = { + 'ansible-galaxy': '#FF6600', + 'license': '#064ccf', + 'maintainance': { + 'well': '#cd02fa', + 'true': '#8a00a6', + 'poor': '#5d0070', + 'false': '#220029', + 'default': '#000000' + }, + 'default': '#e74c3c' + } + + if svg_label in label_color_map: + label_item = label_color_map[svg_label] + if isinstance(label_item, dict): + color = label_item.get(svg_state, label_item.get('default', '#000000')) + else: + color = label_item + else: + color = label_color_map['default'] # Render Template and Return Filepath render_template(env, pad, filepath, svg_state, svg_label, color) diff --git a/setup.py b/setup.py index f8b76db..06ba660 100644 --- a/setup.py +++ b/setup.py @@ -26,8 +26,8 @@ setup( name='lektor-render-template', packages=find_packages(), py_modules=['lektor_render_template'], -# url='https://backwesen.de/l3d/lektor-render-template.git', - version='0.5', + url='https://backwesen.de/l3d/lektor-render-template.git', + version='0.6', classifiers=[ 'Framework :: Lektor', 'Environment :: Plugins',