Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adding options argument for all hooks #100

Merged
merged 2 commits into from

3 participants

@jgoodson

Automatically calls hooks with self.config from the Engine() as the first argument, followed by the arguments passed to run_hook(). Also updates the only hook I could find in contrib/hooks.py and adds the changes to the hooks.mkd file in docs.

@mythmon
Owner

This looks good, thank you!

@mythmon mythmon merged commit 87ec3cd into mythmon:master
@ngokevin

should've posted this on the PR

This argument could probably be passed in as a kwarg; it's backwards incompatible. And it's caused me some pain since PyPi and master aren't compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 38 additions and 14 deletions.
  1. +36 −12 docs/content/docs/hooks.mkd
  2. +1 −1  wok/contrib/hooks.py
  3. +1 −1  wok/engine.py
View
48 docs/content/docs/hooks.mkd
@@ -68,19 +68,25 @@ will pass to the hooked functions (if any.)
<!-- 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>
+`site.start(config)` <a name="site.start"> </a>
+: `config`
+ : Dictionary containing site configuration
: <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.</p>
-`site.output.pre(output_path)` <a name="site.output.pre"> </a>
+`site.output.pre(config, output_path)` <a name="site.output.pre"> </a>
+: `config`
+ : Dictionary containing site configuration
: `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)` <a name="site.output.post"> </a>
+`site.output.post(config, output_path)` <a name="site.output.post"> </a>
+: `config`
+ : Dictionary containing site configuration
: `output_path`
: The path to the output directory.
: This hook will run after the output directory is populated by the media,
@@ -88,13 +94,17 @@ will pass to the hooked functions (if any.)
to modify, overwrite, or otherwise fiddle with the media directory after it
has been copied to the output directory.
-`site.content.gather.pre()` <a name="site.content.gather.pre"> </a>
+`site.content.gather.pre(config)` <a name="site.content.gather.pre"> </a>
+: `config`
+ : Dictionary containing site configuration
: 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)` <a name="site.content.gather.post"> </a>
+`site.content.gather.post(config, pages)` <a name="site.content.gather.post"> </a>
+: `config`
+ : Dictionary containing site configuration
: `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
@@ -106,7 +116,9 @@ 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.render.pre(page)` <a name="page.render.pre"> </a>
+`page.render.pre(config, page)` <a name="page.render.pre"> </a>
+: `config`
+ : Dictionary containing site configuration
: `page`
: The current page object that is being processed.
: This hook will be called for each page before the page is rendered by
@@ -115,7 +127,9 @@ will pass to the hooked functions (if any.)
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.render.post(config, page)` <a name="page.render.post"> </a>
+: `config`
+ : Dictionary containing site configuration
: `page`
: The current page object that is being processed.
: This hook will be called for each page right after the page is rendered by
@@ -125,20 +139,26 @@ will pass to the hooked functions (if any.)
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.meta.pre(config, page)` <a name="page.render.pre"> </a>
+: `config`
+ : Dictionary containing site configuration
: `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.meta.post(config, page)` <a name="page.render.post"> </a>
+: `config`
+ : Dictionary containing site configuration
: `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.template.pre(config, page, templ_vars)` <a name="page.template.pre"> </a>
+: `config`
+ : Dictionary containing site configuration
: `page`
: The current page object that is being processed.
: `templ_vars`
@@ -154,14 +174,18 @@ will pass to the hooked functions (if any.)
[templates]: /docs/templates/
-`page.template.post(page)` <a name="page.template.postpage"> </a>
+`page.template.post(config, page)` <a name="page.template.postpage"> </a>
+: `config`
+ : Dictionary containing site configuration
: `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()` <a name="site.done"> </a>
+`site.done(config)` <a name="site.done"> </a>
+: `config`
+ : Dictionary containing site configuration
: 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
View
2  wok/contrib/hooks.py
@@ -68,7 +68,7 @@ def __call__(self, page):
page.rendered = sio_destination.getvalue()
-def compile_sass(output_dir):
+def compile_sass(config, output_dir):
'''
Compile Sass files -> CSS in the output directory.
View
2  wok/engine.py
@@ -194,7 +194,7 @@ def run_hook(self, hook_name, *args):
returns = []
try:
for hook in self.hooks.get(hook_name, []):
- returns.append(hook(*args))
+ returns.append(hook(self.options, *args))
except AttributeError:
logging.info('Hook {0} not defined'.format(hook_name))
return returns
Something went wrong with that request. Please try again.