github.com/vugu/vugu@v0.3.5/html.go (about) 1 package vugu 2 3 // HTMLer describes something that can return HTML. 4 type HTMLer interface { 5 HTML() string // return raw html (with any needed escaping already done) 6 } 7 8 // HTML implements the HTMLer interface on a string with no transform, just returns 9 // the string as-is for raw HTML. 10 type HTML string 11 12 // HTML implements the HTMLer interface. 13 func (h HTML) HTML() string { 14 return string(h) 15 } 16 17 // NOTE: I'm bailing on this OptionalHTMLer thing because you can get the same 18 // functionality with an explicit vg-if. It's unclear how much benefit 19 // it is to hide an element when you pass it a nil and if it's worth the effort 20 // and additional complexity. It is much more important that we handle escaping 21 // properly to prevent XSS, so we're going to simplify and focus on that. 22 23 // // OptionalHTMLer is like HTMLer but can also explicitly express "nothing here" 24 // // as distinct from an empty string. This is used, for example, to express 25 // // the difference between `<div></div>` and no tag at all. 26 // type OptionalHTMLer interface { 27 // // return html value and true for HTML content, or false to indicate no content. 28 // OptionalHTML() (string, bool) 29 // } 30 31 // // OptionalHTML implements OptionalHTMLer using a string pointer. 32 // type OptionalHTML struct { 33 // Value *string // nil means return ("", false) from OptionalHTML 34 // } 35 36 // // OptionalHTML implements the OptionalHTMLer interface. 37 // func (h OptionalHTML) OptionalHTML() (string, bool) { 38 // if h.Value == nil { 39 // return "", false 40 // } 41 // return *h.Value, true 42 // }