Method: Liquid::StandardFilters#truncatewords

Defined in:
lib/liquid/standardfilters.rb

#truncatewords(input, words = 15, truncate_string = "...") ⇒ Object



48
49
50
51
52
53
54
# File 'lib/liquid/standardfilters.rb', line 48

def truncatewords(input, words = 15, truncate_string = "...")
  if input.nil? then return end
  wordlist = input.to_s.split
  l = words.to_i - 1
  l = 0 if l < 0
  wordlist.length > l ? wordlist[0..l].join(" ") + truncate_string : input
end