Sha256: 06acf3221902a11f87e1ae3a1a142782c1b2851ad18a0e1c5591ba97d190fea6
Contents?: true
Size: 703 Bytes
Versions: 6
Compression:
Stored size: 703 Bytes
Contents
gem 'sanitize'; require 'sanitize' gem 'nokogiri'; require 'nokogiri' module HtmlUtils # Truncates HTML text. Breaks on word boundaries and closes tags. # valid values for aLevel are :NO_TAGS, :RESTRICTED, :BASIC and :RELAXED def self.word_safe_truncate(aHtmlText,aMaxLength,aSuffix='...',aLevel=:BASIC) result = StringUtils.word_safe_truncate(aHtmlText,aMaxLength)+' '+aSuffix level = case aLevel when :NO_TAGS nil when :RESTRICTED Sanitize::Config::RESTRICTED when :BASIC Sanitize::Config::BASIC when :RELAXED Sanitize::Config::RELAXED else Sanitize::Config::BASIC end return level ? Sanitize.clean(result,level) : Sanitize.clean(result) end end
Version data entries
6 entries across 6 versions & 1 rubygems