Exemple #1
0
func Builder(visited map[string]struct{}, root bool, fieldname string, help string, repeated bool, msg *generator.Descriptor, g *generator.Generator, proto3 bool, buildField FieldBuilder) string {
	s := []string{`function build` + typ(fieldname, repeated, msg.DescriptorProto) + `(json) {`}
	if repeated {
		s = append(s, `var s = '<div class="node" type="`+typ(fieldname, repeated, msg.DescriptorProto)+`" fieldname="`+fieldname+`" repeated="true">';`)
	} else {
		s = append(s, `if (json == undefined) {
		return "";
	}
	`)
		s = append(s, `var s = '<div class="node" type="`+typ(fieldname, repeated, msg.DescriptorProto)+`" fieldname="`+fieldname+`" repeated="false">';`)
	}
	if !root {
		s = append(s, `s += '<div class="row"><div class="col-sm-2">'`)
		s = append(s, `s += '<a href="#" class="del-child btn btn-danger btn-xs" role="button" fieldname="`+fieldname+`">Remove</a>'`)
		s = append(s, `s += '</div><div class="col-sm-10">'`)
		s = append(s, `s += '<label class="heading">`+fieldname+`</label>'`)
		s = append(s, `s += '</div></div>'`)
	}
	ms := []string{}
	for i, f := range msg.GetField() {
		help := g.Comments(fmt.Sprintf("%s,%d,%d", msg.Path(), 2, i))
		if f.IsMessage() {
			fieldMsg := g.ObjectNamed(f.GetTypeName()).(*generator.Descriptor)
			if _, ok := visited[msg.GetName()+"."+f.GetName()]; !ok {
				visited[msg.GetName()+"."+f.GetName()] = struct{}{}
				ms = append(ms, Builder(visited, false, f.GetName(), help, f.IsRepeated(), fieldMsg, g, proto3, buildField))
			}
		}
		s = append(s, buildField(g.AllFiles(), msg.DescriptorProto, f, help, proto3))
	}
	if root {
		s = append(s, `
			s += '</div>';
			var node = $(s);
			activateLinks(node);
			return node;
		}`)
	} else {
		s = append(s, `
		s += '</div>';
		return s;
		}`)
	}
	f := strings.Join(s, "\n")
	ms = append(ms, f)
	return strings.Join(ms, "\n\n")
}
Exemple #2
0
func CreateCustom(methodName, packageName, messageName string, g *generator.Generator, buildField FieldBuilder) string {
	msg := g.ObjectNamed("." + packageName + "." + messageName).(*generator.Descriptor)
	proto3 := g.AllFiles().IsProto3(packageName, messageName)
	text := `
	<form class="form-horizontal">
	<div id="form"><div class="children"></div></div>
    <a href="#" id="submit" class="btn btn-primary" role="button">Submit</a>
    </form>
    `
	text += `
	<script>`
	text += Header
	text += `var nodeFactory = {` + strings.Join(BuilderMap(make(map[string]struct{}),
		"RootKeyword", false, msg.DescriptorProto, g.AllFiles()), "\n") + `}
	`
	text += Builder(make(map[string]struct{}), true, "RootKeyword", "", false, msg, g, proto3, buildField)
	text += Init(methodName, "RootKeyword", false, msg.DescriptorProto)
	text += `
	init();

	</script>

	<style>

	.node{
		padding-left: 2em;
		min-height:20px;
	    padding:10px;
	    margin-top:10px;
	    margin-bottom:20px;
	    //border-left:0.5px solid #999;
	    -webkit-border-radius:4px;
	    -moz-border-radius:4px;
	    border-radius:4px;
	    -webkit-box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05);
	    -moz-box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05);
	    box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05);
	    background-color:#eaeaea;
	}

	.node .node {
		background-color:#e2e2e2;
	}

	.node .node .node {
		background-color:#d9d9d9;
	}

	.node .node .node .node {
		background-color:#d1d1d1;
	}

	.node .node .node .node .node {
		background-color:#c7c7c7;
	}

	.node .node .node .node .node .node {
		background-color:#c0c0c0;
	}

	label{
	        font-weight: normal;
	}

	.heading {
		font-weight: bold;
	}

	</style>
	`
	return text
}