TruncateHTML is a project mainly written in Ruby, it's free.
truncateHTML rubygem
truncateHTML
truncates text like the Rails truncate
helper but doesn't break HTML tags, entities, and optionally words.
The truncateHTML
gem can be installed by running:
gem install truncateHTML
require 'rubygems'
require 'truncateHTML'
A string html_string
can be truncated by running:
truncateHTML.truncate(`html_string`)
The following options can be passed to the trucate
method:
:max_length
The maximum length of the out put. Defaults to 40:ellipsis
The last few characters , in case the string is truncated. Defaults to ...
:words
Splicing words will be avoided if set to ttrue. Defaults to false.:link
A link will be appended to the truncated string if explicitely passed. Its by default nil.B V Satyaram <bvsatyaram.com>