update filters

This commit is contained in:
L3D 2023-03-08 02:29:24 +01:00
parent 0cea6f3cfa
commit 3825f3932e
Signed by: l3d
GPG key ID: CD08445BFF4313D1

View file

@ -4,9 +4,48 @@ 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
# pylint: disable=too-many-arguments
def render_template(env, pad, filepath, inputname, inputvalue, color, tiny):
""" Render my custom Jinja2 Template """
# Prepare Variables
rendered_title = f"{inputvalue}: {inputname}"
if not tiny:
rendered_sizes = f"width=\"{int(132.5+(int(len(inputname)/2)*10))}\" height=\"20\""
orange_box_width = str(int(5+len(inputname)*5))
orange_position = str(int(50+(len(inputname)*5)))
latest_element_x = str(int(1+(int(len(inputname)/2)*10)-1)-0.007)
accent_02_multiplier = str(1+int(len(inputname)/2))
name_position = str(105)
else:
rendered_sizes = f"width=\"{int(102.5+(int(len(inputname)/2)*10))}\" height=\"20\""
orange_box_width = str(int(5+len(inputname)*5)+25)
orange_position = str(int(50+(len(inputname)*5)))
latest_element_x = str(int(1+(int(len(inputname)/2)*10)-1)-30.007)
accent_02_multiplier = str(1+int(len(inputname)/2)-3)
name_position = str(75)
# Create File
with open(f"assets/{filepath}", 'w', encoding='UTF-8') as outputfile:
outputfile.write(env.render_template(
'galaxy.svg', pad=pad, this={
'title': str(rendered_title),
'name': str(inputname),
'name_position': str(name_position),
"sizes": str(rendered_sizes),
"orange_box_width": str(orange_box_width),
"orange_position": str(orange_position),
"accent03_x": str(latest_element_x),
"bg_orange_x": str(latest_element_x),
"accent_02_multiplier": str(accent_02_multiplier),
"inputvalue": str(inputvalue),
"color_orange": str(color)
}))
# pylint: disable=unused-argument # pylint: disable=unused-argument
def generate_from_template(inputname, **options): def generate_galaxy_svg(inputname, **options):
""" Generate a File based on a Jinja2 Templated """ """ Generate a File based on a Jinja2 Templated that will show the ansible galaxy name """
# Setup Lektor Env # Setup Lektor Env
project = Project.discover() project = Project.discover()
env = project.make_env() env = project.make_env()
@ -18,35 +57,77 @@ def generate_from_template(inputname, **options):
else: else:
pad = env.new_pad() pad = env.new_pad()
# Prepare Variables # Create File
rendered_title = f"Ansible Role: {inputname}" filepath = f"/svg/{inputname}.svg"
rendered_sizes = f"width=\"{int(132.5+(int(len(inputname)/2)*10))}\" height=\"20\"" color = '#FF6600'
orange_box_width = str(int(5+len(inputname)*6)) render_template(env, pad, filepath, inputname, 'ansible-galaxy', color, False)
orange_position = str(int(50+(len(inputname)*6))) return filepath
latest_element_x = str(int(1+(int(len(inputname)/2)*10)-1)-0.007)
accent_02_multiplier = str(1+int(len(inputname)/2)) # pylint: disable=unused-argument
def generate_maintainance_svg(inputdict, **options):
""" Generate a File based on a Jinja2 Templated that will show the maintainance state """
# Setup Lektor Env
project = Project.discover()
env = project.make_env()
# Setup CTX
ctx = get_ctx()
if ctx is not None:
pad = ctx.pad
else:
pad = env.new_pad()
# Sort Input
inputname = str(dict(inputdict)['name'])
inputstate = str(dict(inputdict)['state'])
# Create File # Create File
file = f"assets/svg/{inputname}.svg" filepath = f"/svg/{inputname}_maintainance.svg"
with open(file, 'w', encoding='UTF-8') as outputfile: match inputstate:
outputfile.write(env.render_template( case 'well':
'galaxy.svg', pad=pad, this={ color = '#cd02fa'
'title': rendered_title, case 'true':
'name': inputname, color = '#8a00a6'
"sizes": rendered_sizes, case 'poor':
"orange_box_width": orange_box_width, color = '#5d0070'
"orange_position": orange_position, case 'false':
"accent03_x": latest_element_x, color = '#220029'
"bg_orange_x": latest_element_x, case _:
"accent_02_multiplier": accent_02_multiplier})) color = '#000000'
returnvalue = f"/svg/{inputname}.svg" render_template(env, pad, filepath, inputstate, 'maintainance', color, False)
return returnvalue return filepath
# pylint: disable=unused-argument
def generate_license_svg(inputdict, **options):
""" Generate a File based on a Jinja2 Templated that will show the used License """
# Setup Lektor Env
project = Project.discover()
env = project.make_env()
# Setup CTX
ctx = get_ctx()
if ctx is not None:
pad = ctx.pad
else:
pad = env.new_pad()
# Sort Input
inputname = str(dict(inputdict)['name'])
inputstate = str(dict(inputdict)['state'])
# Create File
filepath = f"/svg/{inputname}_license.svg"
color = '#064ccf'
render_template(env, pad, filepath, inputstate, 'license', color, True)
return filepath
class RenderTemplatePlugin(Plugin): class RenderTemplatePlugin(Plugin):
""" Create Plugin and listen to Filter Keyword """ """ Create Plugin and listen to Filter Keyword """
name = 'lektor_render_template' name = 'lektor_render_template'
description = 'Lektor plugin to generate files form filters.' description = 'Lektor plugin to generate files form filters.'
def on_setup_env(self, **extra): def on_setup_env(self, **extra):
""" Create Listener for Filter """ """ Create Listener for Filter """
self.env.jinja_env.filters['svg'] = generate_from_template self.env.jinja_env.filters['galaxy'] = generate_galaxy_svg
self.env.jinja_env.filters['maintainance'] = generate_maintainance_svg
self.env.jinja_env.filters['license'] = generate_license_svg