Re: Default filter in TT
by mithaldu (Monk) on Jan 01, 2011 at 21:20 UTC
|
Edit: Please do not use this and look at Template::AutoFilter for a much better solution instead!
(You can study this though if you want to see some pretty terrible monkey-patching.)
After some poking by tinita on the subject and looking at the horror that is Template::HTML i decided to implement a much more brutal, but more effective and way more straight-forward method of applying a user-defined filter to any unfiltered token, while still allowing exclusion of specific tokens.
As i implemented it just now, you won't find it on CPAN (yet). You can get the code here:
AutoFilter.pm
Please let me know if it breaks in some way for you and i'll attempt to get it fixed. | [reply] |
|
| [reply] |
|
I hope you meant you are going to use Template-AutoFilter. Also, if you hop on irc.perl.org you can poke me under Mithaldu/xsheep/sheepx most times for fastest fixing. ;)
| [reply] |
Re: Default filter in TT
by tinita (Parson) on Jan 01, 2011 at 18:50 UTC
|
| [reply] |
|
| [reply] |
|
Then I would look at the source of Template::HTML to see how it is implemented. It doesn't look very complicated at a first glance. seems it is necessary to subclass 4 Template::* classes though.
| [reply] |
Re: Default filter in TT
by Your Mother (Archbishop) on Jan 01, 2011 at 19:41 UTC
|
There was a thread in the past on the TT2 list about this. I couldn't find it though. Google is increasingly useless (to me) as it apparently only indexes around 200 pages (bing! has 16 listed…) of the TT2 mailing list archive. So, either poke around in there, try searching yourself, you might be smarter than I am today, or maybe sign-up for the list and ask there.
| [reply] |
|
There was a thread in the past on the TT2 list about this.
default_escape for Template::Toolkit? maybe?
edit: oh, the TT mailing list, sorry.
But as far as I remember whenever this question came up here the answer was complicated, and the last answer I got about this was Template::HTML. I would still be curious if there is an easy solution.
| [reply] |
|
| [reply] |
Template::AutoFilter
by mithaldu (Monk) on Jan 02, 2011 at 16:57 UTC
|
I just released Template-AutoFilter to CPAN, which means it'll be available for installation in a few hours. It solves the problem cleanly by sub-classing Template::Toolkit with a modified parser that adds filter instructions to unfiltered tokens and supplying a pass-through filter for exclusion.
I've only done very restricted testing on it, so please do poke me if it breaks things for you, but aside from that it should not be very dangerous to use as long as you remember that it tries to filter ALL TT instructions.
If you're the impatient type, you can get the code from Github as well. :) | [reply] |
|
| [reply] |
|
| [reply] |
Re: Default filter in TT
by Rhandom (Curate) on Jan 26, 2011 at 17:25 UTC
|
| [reply] |