Class: HTML_Truncator
- Inherits:
-
Object
- Object
- HTML_Truncator
- Defined in:
- lib/html_truncator.rb,
lib/html_truncator/version.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :ellipsis => "…", :length_in_chars => false }
- VERSION =
"0.4.2"
Class Attribute Summary collapse
-
.ellipsable_tags ⇒ Object
Returns the value of attribute ellipsable_tags.
-
.punctuation_chars ⇒ Object
Returns the value of attribute punctuation_chars.
-
.self_closing_tags ⇒ Object
Returns the value of attribute self_closing_tags.
Class Method Summary collapse
Class Attribute Details
.ellipsable_tags ⇒ Object
Returns the value of attribute ellipsable_tags.
21 22 23 |
# File 'lib/html_truncator.rb', line 21 def @ellipsable_tags end |
.punctuation_chars ⇒ Object
Returns the value of attribute punctuation_chars.
21 22 23 |
# File 'lib/html_truncator.rb', line 21 def punctuation_chars @punctuation_chars end |
.self_closing_tags ⇒ Object
Returns the value of attribute self_closing_tags.
21 22 23 |
# File 'lib/html_truncator.rb', line 21 def @self_closing_tags end |
Class Method Details
.truncate(text, max, opts = {}) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/html_truncator.rb', line 11 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 |