mudge (owner)

Forks

Revisions

gist: 22872 Download_button fork
public
Description:
Widon't helpers for Rails (both the original and 2.1 versions).
Public Clone URL: git://gist.github.com/22872.git
Embed All Files: show embed
application_helper.rb #
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