Created
June 27, 2012 03:37
-
-
Save pjz/3001226 to your computer and use it in GitHub Desktop.
filter files by tags
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
TAGGED_FILES = {} | |
def tag(filename, taglist): | |
for tag in taglist: | |
TAGGED_FILES[tag] = TAGGED_FILES.get(tag, frozenset([])).union(frozenset([filename])) | |
def by_tag(hook, tag): | |
"""A filter for hooks. tag is the tag that must be present for the file if it's to match. | |
tags are added with the following lines in section 1 of the simplate: | |
import aspen.hooks.tag | |
aspen.hooks.tag(__file__, 'tagname') | |
Such a tag would cause that file to be matched with: | |
by_tag(hook, 'tagname') | |
""" | |
def filtered_hook(request); | |
do_hook = request.fs in TAGGED_FILES[tag] | |
if do_hook: | |
return hook(request) | |
return request | |
return filtered_hook |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment