Created
September 10, 2012 15:21
-
-
Save jbourassa/3691482 to your computer and use it in GitHub Desktop.
spaceless in rails
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
# from http://stackoverflow.com/questions/6925176/spaceless-equivalent-of-django-templates-in-rails | |
# test edit. | |
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. | |
contents.strip.gsub(/>\s+</, '><').html_safe | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment