-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Extension.on_frontmatter_loaded handler.
- Loading branch information
Matt Layman
committed
Mar 24, 2015
1 parent
05b7253
commit 1026851
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,31 @@ | ||
# Copyright (c) 2015, Matt Layman | ||
|
||
from handroll import signals | ||
|
||
|
||
class Extension(object): | ||
"""A base extension which hooks handler methods to handroll's signals.""" | ||
|
||
handle_frontmatter_loaded = False | ||
|
||
def __init__(self): | ||
# Handler functions are put in a dictionary to keep references to them. | ||
# Blinker behaves in strange ways without the references. | ||
self._handlers = {} | ||
|
||
if self.handle_frontmatter_loaded: | ||
def _handle_frontmatter_loaded(source_file, **kwargs): | ||
self.on_frontmatter_loaded(source_file, kwargs['frontmatter']) | ||
self._handlers['frontmatter_loaded'] = _handle_frontmatter_loaded | ||
signals.frontmatter_loaded.connect(_handle_frontmatter_loaded) | ||
|
||
def on_frontmatter_loaded(self, source_file, frontmatter): | ||
"""Handle the ``frontmatter_loaded`` signal. | ||
Activate this handler by setting ``handle_frontmatter_loaded`` | ||
to ``True`` in the extension subclass. | ||
:param source_file: Absolute path of the source file | ||
:param frontmatter: Dictionary of parsed frontmatter | ||
""" | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters