Patch for inline_javascript filter with variable interpolation

3 views
Skip to first unread message

Les Hill

unread,
Feb 22, 2008, 9:13:26 PM2/22/08
to Haml
Hi!

This is an unsolicited patch to allow undisturbed javascript in your
Haml (similar to the :plain filter with the sugar from the filter
mentioned here: http://groups.google.com/group/haml/msg/2d890cf1ede761ea
) *and* allow you to access the view variables using the familiar ==
(double quoted string) syntax for ruby interpolation (and this is not
similar to any other filter):

:inline_javascript
function use_instance() {
alert('Hello ' + '#{@instance_world}')
}

Find the git patch here:

http://pastie.org/156177

For any that might be interested right now, the monkey patch for Rails
is described here (for gem version 1.8.0) :

http://groups.google.com/group/rubyjax/msg/d5a83147349bff1f

Thanks for Haml!

Nathan Weizenbaum

unread,
Feb 22, 2008, 10:50:16 PM2/22/08
to ha...@googlegroups.com
Very cool, but I don't like that the interpolation is just defined for
this filter. I've always planned to add some facility to give filters
access to the surrounding context, and I feel like interpolation should
take advantage of that. I've got some ideas that I'm hacking on right
now... I'll see if I can get a commit pushed tonight. Once that's in,
defining this filter should be much easier.

Also, a bit of a nitpick, but I prefer :javascript to :inline_javascript
for the filter name.

- Nathan

Reply all
Reply to author
Forward
0 new messages