slice filter

This commit is contained in:
Florian Weingarten
2014-08-04 16:47:08 +00:00
parent 17347d43de
commit baea0a6bf7
2 changed files with 18 additions and 1 deletions
+4 -1
View File
@@ -36,12 +36,15 @@ module Liquid
def escape(input)
CGI.escapeHTML(input) rescue input
end
alias_method :h, :escape
def escape_once(input)
input.to_s.gsub(HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE)
end
alias_method :h, :escape
def slice(input, offset, length=nil)
input.to_s.slice(offset.to_i, (length || 1).to_i) || ''
end
# Truncate a string down to x characters
def truncate(input, length = 50, truncate_string = "...".freeze)