barista
barista copied to clipboard
Interpolation with CoffeeScript HAML filter
I have a view file written in haml which uses the coffeescript filter and having problem with string interpolation. Since haml uses the #{} syntax for inline ruby and coffeescript uses the same syntax for string interpolation there is a conflict. What happens is that haml will always see the #{} syntax as inline ruby making it basically impossible to use string interpolation in a coffeescript filter. Any idea if this is possible to solve?
Honestly, I'm not sure - It's likely solveable but would require using alternative syntax in coffeescript - I believe (but am not sure) that using \#
(e.g. \#{}
should fix it.
Ok, I'll give it a try.
i am having this issue as well. no way to differentiate interpolated ruby from interpolated js. i tried escaping the hash, but it just returns a string with an escape in it (e.g. "\#{ruby_variable}"
Same issue here.
+1
To get really hacky, would
"javascript string #{"\#{interpolated javascript string}"} javascript string"
work? Assuming it passes through Haml's filter first, then CoffeeScript compilation.