From 3fd3feeffefac20f4e7878672330984cb2117be8 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Mon, 11 Jul 2016 08:37:19 -0600 Subject: [PATCH] Add Ext action to template context (closes #844) --- caddyhttp/httpserver/context.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/caddyhttp/httpserver/context.go b/caddyhttp/httpserver/context.go index 32ae2a40..51e01c95 100644 --- a/caddyhttp/httpserver/context.go +++ b/caddyhttp/httpserver/context.go @@ -7,6 +7,7 @@ import ( "net" "net/http" "net/url" + "path" "strings" "text/template" "time" @@ -158,6 +159,13 @@ func (c Context) StripHTML(s string) string { return buf.String() } +// Ext returns the suffix beginning at the final dot in the final +// slash-separated element of the pathStr (or in other words, the +// file extension). +func (c Context) Ext(pathStr string) string { + return path.Ext(pathStr) +} + // StripExt returns the input string without the extension, // which is the suffix starting with the final '.' character // but not before the final path separator ('/') character.