Last active
August 29, 2015 13:56
-
-
Save tatat/9112434 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 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