Created
October 11, 2016 17:17
-
-
Save renatocassino/511ca0558ba81540c908e2dced08ca9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def spaceless(&block) | |
contents = capture(&block) | |
# Note that string returned by +capture+ is implicitly HTML-safe, | |
# and this mangling does not introduce unsafe changes, so I'm just | |
# resetting the flag. | |
if Rails.env.production? then | |
contents.strip.gsub(/>\s+</, '><').html_safe | |
else | |
contents.html_safe | |
end | |
end | |
end | |
# In view: | |
<%= spaceless do %> | |
<!-- ........ --> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment