public
Last active

Widon't helpers for Rails (both the original and 2.1 versions).

  • Download Gist
application_helper.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.