Skip to content

Instantly share code, notes, and snippets.

@jbourassa
Created September 10, 2012 15:21
Show Gist options
  • Save jbourassa/3691482 to your computer and use it in GitHub Desktop.
Save jbourassa/3691482 to your computer and use it in GitHub Desktop.
spaceless in rails
# 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