-
Notifications
You must be signed in to change notification settings - Fork 2
/
htmlTemplates.go
122 lines (115 loc) · 3.77 KB
/
htmlTemplates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* ****************************************************************************
* Copyright 2020 51 Degrees Mobile Experts Limited (51degrees.com)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
* ***************************************************************************/
package owid
import (
"html/template"
"strings"
)
var registerTemplate = newHTMLTemplate("register", `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Shared Web State - Register Node</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:;base64,=">
</head>
<body style="margin: 0;
padding: 0;
font-family: nunito, sans-serif;
font-size: 16px;
font-weight: 600;
background-color: {{ .Services.Config.BackgroundColor }};
color: {{ .Services.Config.MessageColor }};
height: 100vh;
display: flex;
justify-content: center;
align-items: center;">
<form action="register" method="GET">
<table style="text-align: left;">
<tr>
<td colspan="3">
{{ if not .ReadOnly }}
<p>Register creator '{{ .Domain }}' to a organization.</p>
{{ else }}
<p>Success. Creator '{{ .Domain }}' registered to organization name '{{ .Name }}'.</p>
{{ end }}
</td>
</tr>
<tr>
<td>
<p><label for="name">Organization Name</label></p>
</td>
<td>
<p><input type="text" maxlength="20" id="name" name="name" value="{{ .Name }}" {{ if .ReadOnly }}disabled{{ end }}></p>
</td>
<td>
{{ if .DisplayErrors }}
<p>{{ .NameError }}</p>
{{ end }}
</td>
</tr>
<tr>
<td>
<p><label for="name">Contract URL</label></p>
</td>
<td>
<p><input type="text" maxlength="200" id="contractURL" name="contractURL" value="{{ .ContractURL }}" {{ if .ReadOnly }}disabled{{ end }}></p>
</td>
<td>
{{ if .DisplayErrors }}
<p>{{ .ContractURLError }}</p>
{{ end }}
</td>
</tr>
<tr>
<td colspan="3">
{{ if .DisplayErrors }}
<p>{{ .Error }}</p>
{{ end }}
</td>
</tr>
<tr>
{{ if not .ReadOnly }}
<td colspan="3" style="text-align: center;">
<input type="submit">
</td>
{{ end }}
</tr>
</table>
</form>
</body>
</html>`)
func newHTMLTemplate(n string, h string) *template.Template {
c := removeHTMLWhiteSpace(h)
return template.Must(template.New(n).Parse(c))
}
// Removes white space from the HTML string provided whilst retaining valid
// HTML.
func removeHTMLWhiteSpace(h string) string {
var sb strings.Builder
for i, r := range h {
// Only write out runes that are not control characters.
if r != '\r' && r != '\n' && r != '\t' {
// Only write this rune if the rune is not a space, or if it is a
// space the preceding rune is not a space.
if i == 0 || r != ' ' || h[i-1] != ' ' {
sb.WriteRune(r)
}
}
}
return sb.String()
}