What's the syntax for adding middleware?
eyeseast opened this issue · comments
Chris Amico commented
A decorator might be nice here, for one-off plugins.
Could also just set or extend a list.
Should plugins take configuration arguments? Maybe plugins are classes with a __call__
method (or a run
method).
Chris Amico commented
Some options, not mutually-exclusive:
stack = Stack('src', Markdown(), Jinja())
stack = Stack('src')
stack.middleware = [
Bleach(),
Markdown(output_format='html5')
]
@stack.use
def count_files(files, stack):
stack.metadata['count'] = len(files)
stack.use(Markdown())
stack.use(Jinja())
stack.use(some_other_function)
Chris Amico commented
A plugin is just a callable that takes two arguments: files
and stack
.
files
is a dictionary of filename: post pairs
stack
is the current stack instance
Plugins can operate on either of those in place and don't have to return anything (return values are ignored).