ruby - How to use line breaks in a slim variable? -
i have variable in slim:
- foo = 'my \n desired multiline <br/> string' #{foo}
when parse output using slimrb command line command contents of variable encoded:
my \n desired multiline <br/> string
how can have slimrb
output raw contents in order generate multi-line strings?
note neither .html_safe
nor .raw
available.
there 2 issues here. first in ruby strings using single quotes – '
– don’t convert \n
newlines, remain literal \
, n
. need use double quotes. applies slim too.
second, slim html escapes result of interpolation default. avoid use double braces around code. slim html escapes ruby output default (using =
). avoid escaping in case use double equals (==
).
combining these two, code like:
- foo = "my \n desired multiline <br/> string" td #{{foo}}
this produces:
<td>my desired multiline <br/> string</td>
Comments
Post a Comment