-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from ckoepp/filter/replace
Added Replace Filter
- Loading branch information
Showing
2 changed files
with
58 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- encoding: utf-8 -*- | ||
# | ||
# Copyright 2014 Christian Koepp <[email protected]>. All rights reserved. | ||
# License: BSD Style, 2 clauses -- see LICENSE. | ||
|
||
from acrylamid import log | ||
from acrylamid.filters import Filter | ||
|
||
class Replace(Filter): | ||
match = ['replace'] | ||
version = 1 | ||
priority = 0.0 | ||
|
||
def init(self, conf, env, *args): | ||
try: | ||
self._db = conf.replace_rules | ||
except AttributeError: | ||
log.warn('No configuration named REPLACE_RULES found. Replace filter has nothing to do.') | ||
self._db = dict() | ||
|
||
def transform(self, content, entry, *args): | ||
if len(self._db) == 0: | ||
return content | ||
|
||
for k,v in self._db.items(): | ||
content = content.replace(k, v) | ||
return content |
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