barista icon indicating copy to clipboard operation
barista copied to clipboard

Interpolation with CoffeeScript HAML filter

Open jacob-carlborg opened this issue 13 years ago • 6 comments

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?

jacob-carlborg avatar May 13 '11 11:05 jacob-carlborg

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.

Sutto avatar Jun 02 '11 09:06 Sutto

Ok, I'll give it a try.

jacob-carlborg avatar Jun 02 '11 14:06 jacob-carlborg

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}"

brewster1134 avatar Jun 24 '11 05:06 brewster1134

Same issue here.

iRonin avatar Aug 11 '11 06:08 iRonin

+1

damienbrz avatar Sep 14 '11 03:09 damienbrz

To get really hacky, would

"javascript string #{"\#{interpolated javascript string}"} javascript string"

work? Assuming it passes through Haml's filter first, then CoffeeScript compilation.

as016194 avatar Sep 15 '11 16:09 as016194