Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Commit

Permalink
Document and test the new hooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmon committed Jan 19, 2012
1 parent 2b7342a commit ad32eb2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 12 deletions.
73 changes: 61 additions & 12 deletions docs/content/docs/hooks.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,52 @@ Available hooks
Below are the available hooks, when they will be run, and the arguments they
will pass to the hooked functions (if any.)

<!-- I don't know why this <p> isn't applied automatically... -->

`site.start()`
: Called before anything else has started, except for the loading of hooks.
###List of hooks

- [site.start](#site.start)
- [site.output.pre](#site.output.pre)
- [site.output.post](#site.output.post)
- [site.content.gather.pre](#site.content.gather.pre)
- [site.content.gather.post](#site.content.gather.post)
- [page.render.pre](#page.render.pre)
- [page.render.post](#page.render.post)
- [page.meta.pre](#page.meta.pre)
- [page.meta.post](#page.meta.post)
- [page.template.pre](#page.template.pre)
- [page.template.post](#page.template.post)
- [site.done](#site.done)

### Details

<!-- This first one needs to be wrapped in a p tag, because it doesn't happen automatically for some reason...? -->

`site.start()` <a name="site.start"> </a>
: <p>Called before anything else has started, except for the loading of hooks.
This would be a good time to modify the content, templates, or the files in
the media directory.
the media directory.</p>

`site.output.pre(output_path)`
`site.output.pre(output_path)` <a name="site.output.pre"> </a>
: `output_path`
: The path to the output directory.
: This path will run before the output directory is populated by the media,
and after any existing output files have been deleted. You can add files
that may be overwritten by the media files or the site content.

`site.output.post(output_path)`
`site.output.post(output_path)` <a name="site.output.post"> </a>
: `output_path`
: The path to the output directory.
: This hook will run after the output directory is populated by the media,
and before the content pages have started to be processed. You can use this
to modify, overwrite, or otherwise fiddle with the media directory after it
has been copied to the output directory.

`site.content.gather.pre()`
`site.content.gather.pre()` <a name="site.content.gather.pre"> </a>
: Return value
: List of `Page` objects to add to the list of pages.
: This hook will run before wok gathers content pages, and can be used to add
pages that don't exist on disk.

`site.content.gather.post(pages)`
`site.content.gather.post(pages)` <a name="site.content.gather.post"> </a>
: `pages`
: The list of pages that wok has gathered from the content directory, and
any other hooks that have run. Also includes the duplicated versions of
Expand All @@ -89,7 +106,39 @@ will pass to the hooked functions (if any.)
you modify the list of pages received, those changes will take effect in
wok. You may also return pages to add.

`page.template.pre(page, templ_vars)`
`page.render.pre(page)` <a name="page.render.pre"> </a>
: `page`
: The current page object that is being processed.
: This hook will be called for each page before the page is rendered by
Markdown, reStructuredText, etc. The unrendered text will be in the
variable `page.original`, if there is an original text. Keep in mind that
some pages won't be run through this hook because they come from other
sources, such as hooks, or pagination.

`page.render.post(page)` <a name="page.render.post"> </a>
: `page`
: The current page object that is being processed.
: This hook will be called for each page right after the page is rendered by
Markdown, reStructuredText, etc. The unrendered text will be in the
variable `page.original`, and the rendered text will be in the meta
variable `page.meta['content']. Keep in mind that some pages won't be run
through this hook because they come from other sources, such as hooks, or
pagination.

`page.meta.pre(page)` <a name="page.render.pre"> </a>
: `page`
: The current page object that is being processed.
: This hook will be called for each page before the page has it's meta data
filled in. Some metadata will exist, but it will be in an unnormalized
state.

`page.meta.post(page)` <a name="page.render.post"> </a>
: `page`
: The current page object that is being processed.
: This hook will be called for each page right after the page has it's meta
data filled in and normalized.

`page.template.pre(page, templ_vars)` <a name="page.template.pre"> </a>
: `page`
: The current page object that is being processed.
: `templ_vars`
Expand All @@ -105,14 +154,14 @@ will pass to the hooked functions (if any.)

[templates]: /docs/templates/

`page.template.post(page)`
`page.template.post(page)` <a name="page.template.postpage"> </a>
: `page`
: The current page being processed.
: This hook will be called after the page has been processed by the template
engine. The next step will be write the file to disk, if applicable, so any
last minute changes should happen here.

`site.done()`
`site.done()` <a name="site.done"> </a>
: Called after wok has finished everything. This would be a good time to make
any general modifications to the output, or to do something like upload the
site for distribution. If the `--server` option has been specified, this
Expand Down
4 changes: 4 additions & 0 deletions sample/hooks/__hooks__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def logging_hook(*args):
'site.output.post': make_hook('site.output.post'),
'site.content.gather.pre': make_hook('site.content.gather.pre'),
'site.content.gather.post': make_hook('site.content.gather.post'),
'page.meta.pre': make_hook('page.template.pre'),
'page.meta.post': make_hook('page.template.post'),
'page.render.pre': make_hook('page.template.pre'),
'page.render.post': make_hook('page.template.post'),
'page.template.pre': make_hook('page.template.pre'),
'page.template.post': make_hook('page.template.post'),
'site.stop': make_hook('site.stop'),
Expand Down

0 comments on commit ad32eb2

Please sign in to comment.