jsonenums/server/static/home.html
2017-05-04 15:18:34 -04:00

89 lines
2.0 KiB
HTML

<!DOCTYPE html>
<!--
Copyright 2017 Google Inc. All rights reserved.
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 writing, software distributed
under the License is distributed on a "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.
-->
<html>
<title>jsonenums</title>
<style>
textarea,
input {
display: block;
width: 80%;
margin: auto;
}
textarea {
height: 200px;
overflow-y: scroll;
}
</style>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script>
function generate() {
$.get("/generate", {
"code": $("#code").val(),
"type": $("#type").val(),
"template": $("#template").val(),
}).done(function(res) {
$("#result").val(res);
$("#result").css('background','#fff');
}).fail(function(res) {
$("#result").val(res.responseText);
$("#result").css('background','#fee');
})
}
</script>
<body>
<form action="/generate" method="GET">
<input type="text" id="type" value="WeekDay">
<textarea id="code">
package test
type WeekDay int
const (
Monday WeekDay = iota
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
)
</textarea>
<textarea id="template">
package {{.PackageName}}
func (r {{.TypeName}}) String() string {
s, ok := map[{{.TypeName}}]string {
{{range .Values}}{{.}}:"{{.}}",{{end}}
}
if !ok {
return "unknown {{.TypeName}}"
}
return s
}
</textarea>
</form>
<input type="button" onclick="generate()" value="generate code">
<textarea id="result">
</textarea>
</body>
</html>