Merge pull request #406 from Shopify/slice_filter

slice filter
This commit is contained in:
Florian Weingarten
2014-08-05 17:14:01 +02:00
2 changed files with 20 additions and 1 deletions

View File

@@ -36,12 +36,17 @@ 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)
offset = Integer(offset)
length = length ? Integer(length) : 1
input.to_s.slice(offset, length) || ''
end
# Truncate a string down to x characters
def truncate(input, length = 50, truncate_string = "...".freeze)