From 548090e67f66acf84385c4152ca464e52d3e3319 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 13 Sep 2024 13:01:48 +0200 Subject: Migrate away from templ and towards html/template --- vendor/github.com/a-h/templ/jsonscript.go | 85 ------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 vendor/github.com/a-h/templ/jsonscript.go (limited to 'vendor/github.com/a-h/templ/jsonscript.go') diff --git a/vendor/github.com/a-h/templ/jsonscript.go b/vendor/github.com/a-h/templ/jsonscript.go deleted file mode 100644 index 6e88174..0000000 --- a/vendor/github.com/a-h/templ/jsonscript.go +++ /dev/null @@ -1,85 +0,0 @@ -package templ - -import ( - "context" - "encoding/json" - "fmt" - "io" -) - -var _ Component = JSONScriptElement{} - -// JSONScript renders a JSON object inside a script element. -// e.g. -func JSONScript(id string, data any) JSONScriptElement { - return JSONScriptElement{ - ID: id, - Type: "application/json", - Data: data, - Nonce: GetNonce, - } -} - -// WithType sets the value of the type attribute of the script element. -func (j JSONScriptElement) WithType(t string) JSONScriptElement { - j.Type = t - return j -} - -// WithNonceFromString sets the value of the nonce attribute of the script element to the given string. -func (j JSONScriptElement) WithNonceFromString(nonce string) JSONScriptElement { - j.Nonce = func(context.Context) string { - return nonce - } - return j -} - -// WithNonceFrom sets the value of the nonce attribute of the script element to the value returned by the given function. -func (j JSONScriptElement) WithNonceFrom(f func(context.Context) string) JSONScriptElement { - j.Nonce = f - return j -} - -type JSONScriptElement struct { - // ID of the element in the DOM. - ID string - // Type of the script element, defaults to "application/json". - Type string - // Data that will be encoded as JSON. - Data any - // Nonce is a function that returns a CSP nonce. - // Defaults to CSPNonceFromContext. - // See https://content-security-policy.com/nonce for more information. - Nonce func(ctx context.Context) string -} - -func (j JSONScriptElement) Render(ctx context.Context, w io.Writer) (err error) { - if _, err = io.WriteString(w, ""); err != nil { - return err - } - if err = json.NewEncoder(w).Encode(j.Data); err != nil { - return err - } - if _, err = io.WriteString(w, ""); err != nil { - return err - } - return nil -} -- cgit v1.2.3