Skip to content

Instantly share code, notes, and snippets.

@mudge
Created November 7, 2008 14:37
Show Gist options
  • Save mudge/22872 to your computer and use it in GitHub Desktop.
Save mudge/22872 to your computer and use it in GitHub Desktop.
Widon't helpers for Rails (both the original and 2.1 versions).
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