Re: [htmltmpl] Patch for userdefined escape subroutines in H::T
Brought to you by:
samtregar
From: David K. <da...@gi...> - 2008-05-15 03:55:17
|
"Damien Clark" <d....@cq...> wrote: > I would like to extend HTML::Template to allow the user to implement > their own arbitrary escape functionality. [...] I am proposing the > following changes to the HTML::Template API and template format: > > . Extend the syntax for <tmpl_var escape=(JS,HTML,URL,NONE,1,0)> to > include user provided attribute values. Examples are probably more > clear: <tmpl_var name=¹bla¹ escape=php> or in my case <tmpl_var > name=¹bla2¹ escape=sql>. > > . The constructor to take the option ³escape² with the value being a > hashref. The keys will be the escape names gives in the templates > (e.g. php or sql) and the value a reference to a subroutine that is > provided by the user to escape any special meanings to the syntax used > in that context. Very nice work, Damien! +1 on the inclusion of this oft-requested feature! I started to write the same patch a few years ago, thinking "this should be easy," but stumbled when I realized just how easy it wasn't :-) Shortly thereafter Sam accepted Craig Manley's patch that added escape=JS (to the list of hard-coded escapes) and my immediate need for user-defined escaping went away. But there have still been many times that I wished could "bolt on" a new escape=rot13 or something. We can filter the template with our own arbitrary code, so it would be great to have the capability to also filter the data. -dave PS: kudos too, for including tests! |