mkae it work with python 3.11
This commit is contained in:
parent
1fd71eff13
commit
fe489cdea6
2 changed files with 30 additions and 22 deletions
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
""" Import lektor plugin stuff """
|
""" Import lektor plugin stuff """
|
||||||
|
from os import makedirs
|
||||||
from lektor.pluginsystem import Plugin
|
from lektor.pluginsystem import Plugin
|
||||||
from lektor.project import Project
|
from lektor.project import Project
|
||||||
from lektor.context import get_ctx
|
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 sanitizeOptions as sanitizeScourOptions
|
||||||
from scour.scour import parse_args as parseScourArgs
|
from scour.scour import parse_args as parseScourArgs
|
||||||
|
|
||||||
|
|
||||||
def optimize_svg(source_svg):
|
def optimize_svg(source_svg):
|
||||||
""" using scour to optimize and minify svg """
|
""" using scour to optimize and minify svg """
|
||||||
scour_options = parseScourArgs([
|
scour_options = parseScourArgs([
|
||||||
|
@ -23,7 +25,10 @@ def optimize_svg(source_svg):
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
def render_template(env, pad, filepath, label_name, label_value, color):
|
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
|
# Prepare Final Variables for galaxy.svg
|
||||||
font_spacing = int(7)
|
font_spacing = int(7)
|
||||||
rendered_title = f"{label_value}: {label_name}"
|
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)
|
right_box_position = float(int(overal_width - 132)-0.007)
|
||||||
|
|
||||||
# Create an optimized SVG File
|
# Create an optimized SVG File
|
||||||
|
makedirs('assets/svg/', exist_ok=True)
|
||||||
with open(f"assets/{filepath}", 'w', encoding='UTF-8') as outputfile:
|
with open(f"assets/{filepath}", 'w', encoding='UTF-8') as outputfile:
|
||||||
outputfile.write(
|
outputfile.write(
|
||||||
optimize_svg(
|
optimize_svg(
|
||||||
|
@ -80,25 +86,27 @@ def generate_svg(inputdict, **options):
|
||||||
filepath = f"/svg/{svg_name}_{svg_label}.svg"
|
filepath = f"/svg/{svg_name}_{svg_label}.svg"
|
||||||
|
|
||||||
# File Color
|
# File Color
|
||||||
match svg_label:
|
label_color_map = {
|
||||||
case 'ansible-galaxy':
|
'ansible-galaxy': '#FF6600',
|
||||||
color = '#FF6600'
|
'license': '#064ccf',
|
||||||
case 'license':
|
'maintainance': {
|
||||||
color = '#064ccf'
|
'well': '#cd02fa',
|
||||||
case 'maintainance':
|
'true': '#8a00a6',
|
||||||
match svg_state:
|
'poor': '#5d0070',
|
||||||
case 'well':
|
'false': '#220029',
|
||||||
color = '#cd02fa'
|
'default': '#000000'
|
||||||
case 'true':
|
},
|
||||||
color = '#8a00a6'
|
'default': '#e74c3c'
|
||||||
case 'poor':
|
}
|
||||||
color = '#5d0070'
|
|
||||||
case 'false':
|
if svg_label in label_color_map:
|
||||||
color = '#220029'
|
label_item = label_color_map[svg_label]
|
||||||
case _:
|
if isinstance(label_item, dict):
|
||||||
color = '#000000'
|
color = label_item.get(svg_state, label_item.get('default', '#000000'))
|
||||||
case _:
|
else:
|
||||||
color = '#e74c3c'
|
color = label_item
|
||||||
|
else:
|
||||||
|
color = label_color_map['default']
|
||||||
|
|
||||||
# Render Template and Return Filepath
|
# Render Template and Return Filepath
|
||||||
render_template(env, pad, filepath, svg_state, svg_label, color)
|
render_template(env, pad, filepath, svg_state, svg_label, color)
|
||||||
|
|
4
setup.py
4
setup.py
|
@ -26,8 +26,8 @@ setup(
|
||||||
name='lektor-render-template',
|
name='lektor-render-template',
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
py_modules=['lektor_render_template'],
|
py_modules=['lektor_render_template'],
|
||||||
# url='https://backwesen.de/l3d/lektor-render-template.git',
|
url='https://backwesen.de/l3d/lektor-render-template.git',
|
||||||
version='0.5',
|
version='0.6',
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Framework :: Lektor',
|
'Framework :: Lektor',
|
||||||
'Environment :: Plugins',
|
'Environment :: Plugins',
|
||||||
|
|
Loading…
Reference in a new issue