forked from ag_kommunikation/webseite
29 lines
883 B
Python
29 lines
883 B
Python
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
|