Created
November 7, 2008 14:37
-
-
Save mudge/22872 to your computer and use it in GitHub Desktop.
Widon't helpers for Rails (both the original and 2.1 versions).
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 | |
# Shaun Inman's original Widon't | |
# http://shauninman.com/archive/2006/08/22/widont_wordpress_plugin | |
# | |
# @param [String] text the text to apply Widon't to | |
# @return [String] the text with Widon't applied | |
def widont(text) | |
text.strip! | |
text[text.rindex(' '), 1] = ' ' if text.rindex(' ') | |
text | |
end | |
# Widon't 2.1 (the update based on Matthew Mullenweg's regular expression) | |
# http://www.shauninman.com/archive/2007/01/03/widont_2_1_wordpress_plugin | |
# | |
# @param [String] text the text to apply Widon't to | |
# @return [String] a copy of the text with Widon't applied | |
def widont(text) | |
text.gsub(/([^\s])\s+([^\s]+)\s*$/, '\1 \2') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment