52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
""" Import lektor plugin stuff """
|
|
from lektor.pluginsystem import Plugin
|
|
from lektor.project import Project
|
|
from lektor.context import get_ctx
|
|
|
|
# pylint: disable=unused-argument
|
|
def generate_from_template(inputname, **options):
|
|
""" Generate a File based on a Jinja2 Templated """
|
|
# 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()
|
|
|
|
# Prepare Variables
|
|
rendered_title = f"Ansible Role: {inputname}"
|
|
rendered_sizes = f"width=\"{int(132.5+(int(len(inputname)/2)*10))}\" height=\"20\""
|
|
orange_box_width = str(int(5+len(inputname)*6))
|
|
orange_position = str(int(50+(len(inputname)*6)))
|
|
latest_element_x = str(int(1+(int(len(inputname)/2)*10)-1)-0.007)
|
|
accent_02_multiplier = str(1+int(len(inputname)/2))
|
|
|
|
# Create File
|
|
file = f"assets/svg/{inputname}.svg"
|
|
with open(file, 'w', encoding='UTF-8') as outputfile:
|
|
outputfile.write(env.render_template(
|
|
'galaxy.svg', pad=pad, this={
|
|
'title': rendered_title,
|
|
'name': inputname,
|
|
"sizes": rendered_sizes,
|
|
"orange_box_width": orange_box_width,
|
|
"orange_position": orange_position,
|
|
"accent03_x": latest_element_x,
|
|
"bg_orange_x": latest_element_x,
|
|
"accent_02_multiplier": accent_02_multiplier}))
|
|
returnvalue = f"/svg/{inputname}.svg"
|
|
return returnvalue
|
|
|
|
class RenderTemplatePlugin(Plugin):
|
|
""" Create Plugin and listen to Filter Keyword """
|
|
name = 'lektor_render_template'
|
|
description = 'Lektor plugin to generate files form filters.'
|
|
|
|
def on_setup_env(self, **extra):
|
|
""" Create Listener for Filter """
|
|
self.env.jinja_env.filters['svg'] = generate_from_template
|