Skip to content

Instantly share code, notes, and snippets.

@michelson
Forked from jerome/word_truncate_helper.rb
Created June 1, 2009 14:33
Show Gist options
  • Save michelson/121451 to your computer and use it in GitHub Desktop.
Save michelson/121451 to your computer and use it in GitHub Desktop.
module WordTruncateHelper
def word_truncate(text, *args)
options = args.extract_options!
unless args.empty?
options[:size] = args[0] || 75
options[:omission] = args[1] || "..."
end
options.reverse_merge!(:size => 75, :omission => "...")
text.scan(/(\S+)(\s+)/)[0..options[:size]].flatten.join << options[:omission] if text
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment