github.com/neohugo/neohugo@v0.123.8/tpl/css/css.go (about) 1 package css 2 3 import ( 4 "context" 5 6 "github.com/neohugo/neohugo/common/types/css" 7 "github.com/neohugo/neohugo/deps" 8 "github.com/neohugo/neohugo/tpl/internal" 9 "github.com/spf13/cast" 10 ) 11 12 const name = "css" 13 14 // Namespace provides template functions for the "css" namespace. 15 type Namespace struct{} 16 17 // Quoted returns a string that needs to be quoted in CSS. 18 func (ns *Namespace) Quoted(v any) css.QuotedString { 19 s := cast.ToString(v) 20 return css.QuotedString(s) 21 } 22 23 // Unquoted returns a string that does not need to be quoted in CSS. 24 func (ns *Namespace) Unquoted(v any) css.UnquotedString { 25 s := cast.ToString(v) 26 return css.UnquotedString(s) 27 } 28 29 func init() { 30 f := func(d *deps.Deps) *internal.TemplateFuncsNamespace { 31 ctx := &Namespace{} 32 33 ns := &internal.TemplateFuncsNamespace{ 34 Name: name, 35 Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, 36 } 37 38 return ns 39 } 40 41 internal.AddTemplateFuncsNamespace(f) 42 }