Module: Card::Content::Truncate

Included in:
Card::Content
Defined in:
card/lib/card/content/truncate.rb

Overview

tools for truncating content

Constant Summary collapse

ELLIPSES_HTML =
'<span class="closed-content-ellipses">...</span>'.freeze

Instance Method Summary collapse

Instance Method Details

#smart_truncate(input, words = 25) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'card/lib/card/content/truncate.rb', line 7

def smart_truncate input, words=25
  return if input.nil?

  truncated, wordstring = truncate input, words
  # nuke partial tags at end of snippet
  wordstring.gsub!(/(<[^>]+)$/, "")
  wordstring = close_tags wordstring
  wordstring += ELLIPSES_HTML if truncated
  # wordstring += '...' if wordlist.length > l
  polish wordstring
end