Skip to content

Instantly share code, notes, and snippets.

@pjz
Created June 27, 2012 03:37
Show Gist options
  • Save pjz/3001226 to your computer and use it in GitHub Desktop.
Save pjz/3001226 to your computer and use it in GitHub Desktop.
filter files by tags
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