mkae it work with python 3.11

This commit is contained in:
L3D 2023-03-21 19:36:28 +01:00
parent 1fd71eff13
commit fe489cdea6
Signed by: l3d
GPG key ID: CD08445BFF4313D1
2 changed files with 30 additions and 22 deletions

View file

@ -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)

View file

@ -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',