eyeseast / python-metalsmyth

A file processor, maybe a static site generator, inspired by Metalsmith.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What's the syntax for adding middleware?

eyeseast opened this issue · comments

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).

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)

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).