Writing plugins

Johan Nordberg edited this page Sep 9, 2013 · 3 revisions

You can fork this handy template as a base for your plugin https://github.com/jnordberg/wintersmith-plugin

Wintersmith plugins are packaged as node.js modules, they are expected to export a function that accepts a environment and callback argument.

function plugin(env, callback) { }

The env is your wintersmith site's environment, at this point no content or templates are loaded. The callback should be called when the plugin has finished loading or when an error occurs.

env.registerContentPlugin(contentGroup, pattern, contentPlugin)

Add a content plugin to the environment. Files in the contents directory matching the glob pattern will be instanciated using the plugin's fromFile factory method. The group argument is used to group the loaded instances under each directory. I.e. plugin instances with the group 'textFiles' can be found in contents.somedir._.textFiles.

env.registerTemplatePlugin(pattern, templatePlugin)

Add a template plugin to the environment. All files in the template directory matching the glob pattern will be passed to the plugin's fromFile classmethod.

env.registerGenerator(contentGroup, generatorFn)

Add a generator to the environment. The generator function is called with the env and the current content tree. It should return a object with nested ContentPlugin instances. These will be merged into the final content tree.

function generator(contents, callback) { }

NOTE: do not modify the content tree directly in a generator, consider it read-only.

env.registerView(name, viewFn)

Add a reusable view to the environment. More on views: TODO


Namespace that can be used to hold helper functions etc used by plugins