Added jinja2 filters via lektor plugin to enable debug prints.

This commit is contained in:
Stephan 2021-04-06 21:42:31 +02:00
parent 1b19f07b35
commit 3b9fc36c42
3 changed files with 46 additions and 1 deletions

6
.gitignore vendored
View File

@ -86,4 +86,8 @@ $RECYCLE.BIN/
# Windows shortcuts # Windows shortcuts
*.lnk *.lnk
# End of https://www.toptal.com/developers/gitignore/api/vim,adobe,windows,macos # End of https://www.toptal.com/developers/gitignore/api/vim,adobe,windows,macos
# Lektor plugin files
**/*.egg-info/
**/__pycache__/

View File

@ -0,0 +1,28 @@
from lektor.pluginsystem import Plugin
class Jinja2FiltersPlugin(Plugin):
name = "Jinja2 Filters"
description = 'Custom Jinja2 filters to use with Lektor.'
def on_setup_env(self, **extra):
def shout_filter(value):
return value.upper() + '!!!!1111'
self.env.jinja_env.filters['shout'] = shout_filter
def show_all_attrs(value):
res = []
for item in dir(value):
res.append(str(item) + "\n")
return '\n'.join(res)
self.env.jinja_env.filters['show_all_attrs'] = show_all_attrs
def show_all_vars(value):
res = []
attr_list = vars(value)
for item in attr_list:
res.append(str(item) + ': ' + str(attr_list[item]))
return '\n'.join(res)
self.env.jinja_env.filters['show_all_vars'] = show_all_vars

View File

@ -0,0 +1,13 @@
from setuptools import setup
setup(
name='lektor-jinja2-filters',
version='0.2',
py_modules=['lektor_jinja2_fitlers'],
entry_points={
'lektor.plugins': [
'jinja2-filters = lektor_jinja2_fitlers:Jinja2FiltersPlugin',
]
},
install_requires=[]
)