Wow, it's been a while since I've done one of these. When we first introduced filters in Haml 1.5, the idea was to allow Haml to focus on its strengths by leaving templating of the sort it's not good at - formatting blog posts, for example, or writing inline CSS - up to systems that were good at it. Thus we provided the :redcloth filter for formatting text, the :sass filter for embedding CSS, and so on. We even added an :erb filter for the masochistic.
Unfortunately, there was a problem: filters were static. That is, the filter code was run when the template was compiled. By the time a request was coming in and the template was actually running, there wasn't any way to run the filters with any sort of dynamic data. This made filters much less useful than they would otherwise have been. Encouraged by a recent patch by Les Hill (http://groups.google.com/group/haml/t/244e550d55709ebc?hl=en) and an older patch by Bob Aman (http://groups.google.com/group/haml/t/79871e3ec34f0b27), I've just fixed this. All filters now have access to the runtime template context. Not just helper methods and instance variables, but locals, too. For most filters, this means that you can interpolate dynamic code into the templates like you would with ==. For example: :javascript function showMessage() { alert([EMAIL PROTECTED]); } In addition, the Ruby-based filters - :ruby and :erb - both now use the template context. So now you can do - foo = "Hello" :erb <%= foo %>, world! and it'll work, just like it looks like it should. One side-effect of this change is that the architecture for creating filters has changed somewhat. The basic form for a filter is now module MyFilter include Haml::Filters::Base def render(text) my_function(text) end end You define a module, include Haml::Filters::Base, and define a render method that takes a string and returns another string. It's pretty simple, and all the interpolation stuff will be handled automatically. These changes are available right now in the master branch, which you can get via git clone git://github.com/nex3/haml/master Enjoy! Oh, and we also have a :javascript filter, now, too. - Nathan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Haml" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/haml?hl=en -~----------~----~----~----~------~----~------~--~---
