Skip to content

Instantly share code, notes, and snippets.

@tatat
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatat/9112434 to your computer and use it in GitHub Desktop.
Save tatat/9112434 to your computer and use it in GitHub Desktop.
module ApplicationHelper
# 私がやるとこうなる(ごたごたしてる)
def without_whitespaces(options = {})
captured = capture &Proc.new
captured = captured.gsub(%r{\A\s+|\s+\Z}, '').gsub(%r{(>)\s+(<)}, '\1\2')
captured = captured.gsub(%r{(>)\s*(.*?)\s*(<)}, '\1\2\3') if options[:trim]
captured.html_safe
end
# takkkun がやるとこうなる(スマート!)
def smash_whitespaces(&block)
capture(&block).lines.map(&:strip).join.html_safe
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment