Hi!

I have some thoughts around the use of HEREDOCS to construct blocks of HTML
in helpers (or decorators) I'd like some feedback on before filing a
bug/feature request.


This kind of construct is bad:

"<div class="foo">#{content}</div>".html_safe

We should really do this:

content_tag(:div, content, :class => 'foo')

or this:

  html = "".html_safe
  html << "<div class='foor'>".html_safe
  html << content
  html << "</div>".html_safe

For longer blocks of HTML where there is a lot of logic required to get the
pieces content going into it, both of the above quickly become unwieldy and
hard to maintain.

Should we be able to do this:

[some logic that generates title, content, tags]

<<~HTML
  <div>
    <h4>#{title}</h4>
    <p>#{content}</p>
    <p>#{tags}</p>
  </div>
HTML

...and have all interpolated content be marked as unsafe?

Doing this:

<<~HTML.html_safe

is a Bad Things to be avoided.

I'd be inclined to leave regular interpolated strings as is.

Could this be better dealt with with a new .unsafe method?


Cheers,

Richard

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to