From 0ea0fc04f0fadc538208c3af421e9d02e8e9eae9 Mon Sep 17 00:00:00 2001 From: Andrii Kolomiichenko Date: Wed, 7 Nov 2018 15:28:59 +0200 Subject: [PATCH] Add JS templating --- context.go | 6 ++++++ engine.go | 1 + 2 files changed, 7 insertions(+) diff --git a/context.go b/context.go index 79e1f38..c34962e 100644 --- a/context.go +++ b/context.go @@ -376,6 +376,12 @@ func (c *Context) XML(statusCode int, obj interface{}) { c.engine.Render.XML(c.RequestCtx, statusCode, obj) } +// JS renders the JS template specified by its file name. +// It also updates the HTTP code and sets the Content-Type as "text/javascript". +func (c *Context) JS(statusCode int, name string, obj interface{}) { + c.engine.Render.JS(c.RequestCtx, statusCode, name, obj) +} + // String writes the given string into the response body. func (c *Context) String(statusCode int, format string, values ...interface{}) { c.SetStatusCode(statusCode) diff --git a/engine.go b/engine.go index a79eeb0..cab06b9 100644 --- a/engine.go +++ b/engine.go @@ -23,6 +23,7 @@ type ( JSONP(*fasthttp.RequestCtx, int, string, interface{}) error HTML(*fasthttp.RequestCtx, int, string, interface{}, ...string) error XML(*fasthttp.RequestCtx, int, interface{}) error + JS(*fasthttp.RequestCtx, int, string, interface{}, ...string) error } // Handler is the function for handling HTTP requests.