template.html.go (2323B)
1 // Code generated by tplc. DO NOT EDIT. 2 3 package templates 4 5 import "go.lair.cx/tpls" 6 7 import ( 8 "path" 9 ) 10 11 type Page interface { 12 Title(w tpls.Writer) 13 Body(w tpls.Writer) 14 } 15 16 func Render(w tpls.Writer, p Page) { 17 w.WriteRaw(`<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" name="viewport"><meta http-equiv="X-UA-Compatible" content="ie=edge">`) 18 w.WriteRaw(`<title>`) 19 p.Title(w) 20 w.WriteRaw(`</title>`) 21 w.WriteRaw(`</head><body>`) 22 p.Body(w) 23 w.WriteRaw(`</body></html>`) 24 } 25 26 type MainPage struct { 27 Name string 28 Cond int 29 } 30 31 func (*MainPage) Title(w tpls.Writer) { 32 w.WriteRaw(` Main Page `) 33 } 34 35 func (p *MainPage) Body(w tpls.Writer) { 36 w.WriteRaw(`<div class="card" style=" 37 display: block; 38 width: 100%; 39 max-width: 50rem; 40 padding: 1rem; 41 border: 1px solid rgba(0, 0, 0, 0.14); 42 margin: 1rem auto; 43 border-radius: 2px; 44 ">`) 45 w.WriteRaw(`Custom Card!`) 46 w.WriteRaw(`</div>`) 47 w.WriteRaw(`<div class="card" style=" 48 display: block; 49 width: 100%; 50 max-width: 50rem; 51 padding: 1rem; 52 border: 1px solid rgba(0, 0, 0, 0.14); 53 margin: 1rem auto; 54 border-radius: 2px; 55 ">`) 56 w.WriteRaw(`<p> Card with no content </p>`) 57 w.WriteRaw(`</div>`) 58 w.WriteRaw(`<p> Strings:<br> Hello, `) 59 w.WriteString("World") 60 w.WriteRaw(`!<br>`) 61 w.WriteRaw(`<a href="http://example.com">Unsafe String</a>`) 62 w.WriteRaw(`<br>`) 63 w.WriteByteString([]byte{72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33}) 64 w.WriteRaw(`<br>`) 65 w.WriteString(path.Join("/path", "./to/file")) 66 w.WriteRaw(`</p><p> Numbers:<br>`) 67 w.WriteInteger(123) 68 w.WriteRaw(`<br>`) 69 w.WriteFloat(123.45, -1) 70 w.WriteRaw(`<br>`) 71 w.WriteFloat(123.45, 1) 72 w.WriteRaw(`</p><p> If:<br>`) 73 if p.Cond == 1 { 74 w.WriteRaw(` p.Cond is 1 `) 75 } else if p.Cond == 2 { 76 w.WriteRaw(` p.Cond is 2 `) 77 } else { 78 w.WriteRaw(` else. `) 79 } 80 w.WriteRaw(`</p><p> Loop:<br>`) 81 for _, s := range []string{`a`, `b`, `c`} { 82 w.WriteString(s) 83 w.WriteRaw(`<br>`) 84 } 85 w.WriteRaw(`</p>`) 86 theValue := "value" 87 w.WriteRaw(`<p> Binding:<br><a href="`) 88 w.WriteString(path.Join(`/path/to`, theValue)) 89 w.WriteRaw(`">`) 90 w.WriteString(theValue) 91 w.WriteRaw(`</a></p>`) 92 }