Escape / Ignore special characters in HAML attributes

I use HAML to create html templates, but I have a problem writing attributes that will be replaced with a JavaScript string by the template.

The corresponding line is as follows:

%div{:class => "<%= from_class %>"}

HAML tries to encode the <% =%> tags:

<div class="&lt;%= from_class %&gt;">

I do not want this to happen in this case ... Does anyone know how to do this?

+4
source share
3 answers

The next version of Haml (3.1) will have an option :escape_attrsthat you can install in falseto prevent this. You can also pass --no-escape-attrson the command line. To use this right now, you can install the alpha version with gem install haml --prerelease.

+4

this html_safe:

- foo = "&#x0026".html_safe
%a(href='/posts' data-icon=foo aria-hidden='true')
0

@Natalie Weizenbaum @rchampourlier ,

//haml.rb

Haml::Template.options[:escape_attrs] = false

, haml :

- :

.input-group-addon{class: "<%= field_name %>"}

, :

<div class="%> <%= field_name input-group-addon">

dot (.input-group-addon) : text:

%div{class: "<%= field_name %> input-group-addon"} 

, :

<div class="<%= field_name %> input-group-addon">

(<% = field_name%>), , , .dot ...

0

Source: https://habr.com/ru/post/1772034/


All Articles