github.com/linchen2chris/hugo@v0.0.0-20230307053224-cec209389705/tpl/css/css.go (about) 1 package css 2 3 import ( 4 "context" 5 6 "github.com/gohugoio/hugo/common/types/css" 7 "github.com/gohugoio/hugo/deps" 8 "github.com/gohugoio/hugo/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 18 // Quoted returns a string that needs to be quoted in CSS. 19 func (ns *Namespace) Quoted(v any) css.QuotedString { 20 s := cast.ToString(v) 21 return css.QuotedString(s) 22 } 23 24 // Unquoted returns a string that does not need to be quoted in CSS. 25 func (ns *Namespace) Unquoted(v any) css.UnquotedString { 26 s := cast.ToString(v) 27 return css.UnquotedString(s) 28 } 29 30 func init() { 31 f := func(d *deps.Deps) *internal.TemplateFuncsNamespace { 32 ctx := &Namespace{} 33 34 ns := &internal.TemplateFuncsNamespace{ 35 Name: name, 36 Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, 37 } 38 39 return ns 40 } 41 42 internal.AddTemplateFuncsNamespace(f) 43 }