From be0e4a22abcef260e31e33ea22a3b08ab3e958ab Mon Sep 17 00:00:00 2001 From: Dean Sofer Date: Wed, 25 Apr 2018 13:56:44 -0700 Subject: [PATCH] Added negative truncation to helper function This allows you to grab a truncated portion of a string from the end. --- template/helpers.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/template/helpers.go b/template/helpers.go index 3c7a371..bd59acd 100644 --- a/template/helpers.go +++ b/template/helpers.go @@ -100,13 +100,18 @@ func isFailure(conditional bool, options *raymond.Options) string { } func truncate(s string, len int) string { - if utf8.RuneCountInString(s) <= len { + if utf8.RuneCountInString(s) <= int(math.Abs(float64(len))) { return s } runes := []rune(s) - return string(runes[:len]) + if len < 0 { + len = -len + return string(runes[len:]) + } else { + return string(runes[:len]) + } } func urlencode(options *raymond.Options) string {