Update render Template with aditional parts
This commit is contained in:
parent
fe489cdea6
commit
36444bf833
3 changed files with 47 additions and 30 deletions
|
@ -6,9 +6,11 @@ In this case it is expecting the [galaxy.svg](https://backwesen.de/l3d/ansible.l
|
||||||
|
|
||||||
## Example Usage:
|
## Example Usage:
|
||||||
```json
|
```json
|
||||||
{'name': this.filename, 'state': this.colored_label, 'label': this.label_name} | svg
|
{'name': this.filename, 'state': this.colored_label, 'label': this.label_name, 'color': '#FF0000', 'suffix': 'fileend'} | svg
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note that ``name``, ``state`` and ``label`` are required keys, ``color`` and ``suffix`` are optional keys.
|
||||||
|
|
||||||
You can see a real life example of this plugin at [ansible.l3d.space](https://ansible.l3d.space/).
|
You can see a real life example of this plugin at [ansible.l3d.space](https://ansible.l3d.space/).
|
||||||
|
|
||||||
## Open Issues:
|
## Open Issues:
|
||||||
|
|
|
@ -62,9 +62,42 @@ def render_template(env, pad, filepath, label_name, label_value, color):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def create_filepath(svg_label, svg_name, svg_suffix):
|
||||||
|
""" Generate File path """
|
||||||
|
if svg_label == 'ansible-galaxy':
|
||||||
|
if bool(svg_suffix):
|
||||||
|
return f"/svg/{svg_name}_{svg_suffix}.svg"
|
||||||
|
return f"/svg/{svg_name}.svg"
|
||||||
|
if bool(svg_suffix):
|
||||||
|
return f"/svg/{svg_name}_{svg_label}_{svg_suffix}.svg"
|
||||||
|
return f"/svg/{svg_name}_{svg_label}.svg"
|
||||||
|
|
||||||
|
def create_color(svg_label, svg_state, svg_color):
|
||||||
|
""" Create Color based on Input or predefined patterns """
|
||||||
|
label_color_map = {
|
||||||
|
'ansible-galaxy': '#FF6600',
|
||||||
|
'license': '#064ccf',
|
||||||
|
'maintainance': {
|
||||||
|
'well': '#cd02fa',
|
||||||
|
'true': '#8a00a6',
|
||||||
|
'poor': '#5d0070',
|
||||||
|
'false': '#220029',
|
||||||
|
'default': '#000000'
|
||||||
|
},
|
||||||
|
'default': '#e74c3c'
|
||||||
|
}
|
||||||
|
if bool(svg_color):
|
||||||
|
return svg_color
|
||||||
|
if svg_label in label_color_map:
|
||||||
|
label_item = label_color_map[svg_label]
|
||||||
|
if isinstance(label_item, dict):
|
||||||
|
return label_item.get(svg_state, label_item.get('default', '#000000'))
|
||||||
|
return label_item
|
||||||
|
return label_color_map['default']
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def generate_svg(inputdict, **options):
|
def generate_svg(inputdict, **options):
|
||||||
""" Prepare Variables to geneate File based on a Jinja2 Template and returning its filepath """
|
""" Prepare Variables to geneate File based on a Jinja2 Template and return filepath """
|
||||||
# Setup Lektor Env, CTX and Pad
|
# Setup Lektor Env, CTX and Pad
|
||||||
project = Project.discover()
|
project = Project.discover()
|
||||||
env = project.make_env()
|
env = project.make_env()
|
||||||
|
@ -78,35 +111,17 @@ def generate_svg(inputdict, **options):
|
||||||
svg_name = str(dict(inputdict)['name'])
|
svg_name = str(dict(inputdict)['name'])
|
||||||
svg_state = str(dict(inputdict)['state'])
|
svg_state = str(dict(inputdict)['state'])
|
||||||
svg_label = str(dict(inputdict)['label'])
|
svg_label = str(dict(inputdict)['label'])
|
||||||
|
if 'suffix' in dict(inputdict).keys():
|
||||||
# File Path
|
svg_suffix = str(dict(inputdict)['suffix'])
|
||||||
if svg_label == 'ansible-galaxy':
|
|
||||||
filepath = f"/svg/{svg_name}.svg"
|
|
||||||
else:
|
else:
|
||||||
filepath = f"/svg/{svg_name}_{svg_label}.svg"
|
svg_suffix = False
|
||||||
|
if 'color' in dict(inputdict).keys():
|
||||||
# File Color
|
svg_color = str(dict(inputdict)['color'])
|
||||||
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:
|
else:
|
||||||
color = label_item
|
svg_color = False
|
||||||
else:
|
|
||||||
color = label_color_map['default']
|
filepath = create_filepath(svg_label, svg_name, svg_suffix)
|
||||||
|
color = create_color(svg_label, svg_state, svg_color)
|
||||||
|
|
||||||
# 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)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -27,7 +27,7 @@ setup(
|
||||||
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.6',
|
version='0.7',
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Framework :: Lektor',
|
'Framework :: Lektor',
|
||||||
'Environment :: Plugins',
|
'Environment :: Plugins',
|
||||||
|
|
Loading…
Reference in a new issue