Class: HTML_Truncator
- Inherits:
-
Object
- Object
- HTML_Truncator
- Defined in:
- lib/html_truncator.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :ellipsis => "…", :length_in_chars => false }
Class Attribute Summary collapse
-
.ellipsable_tags ⇒ Object
Returns the value of attribute ellipsable_tags.
Class Method Summary collapse
Class Attribute Details
.ellipsable_tags ⇒ Object
Returns the value of attribute ellipsable_tags.
20 21 22 |
# File 'lib/html_truncator.rb', line 20 def @ellipsable_tags end |
Class Method Details
.truncate(text, max, opts = {}) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/html_truncator.rb', line 10 def self.truncate(text, max, opts={}) return truncate(text, max, :ellipsis => opts) if String === opts opts = DEFAULT_OPTIONS.merge(opts) doc = Nokogiri::HTML::DocumentFragment.parse(text) str, _, opts = doc.truncate(max, opts) eval "class <<str; def html_truncated?; #{opts[:was_truncated]} end end" str end |