Get rid of custom comment generation

This commit is contained in:
2019-08-27 16:59:59 -06:00
parent e2ca21a752
commit a0eecef935
4 changed files with 12 additions and 28 deletions

View File

@ -19,10 +19,6 @@ func identifier(s string) string {
return strings.Join(words, "")
}
func formatComment(s string) string {
return "// " + strings.TrimSpace(s) + "\n"
}
type AttribTypeInfo struct {
Template string
Imports []string
@ -92,31 +88,24 @@ type Spec interface {
}
type AttribSpec struct {
Name string `json:"name"`
Type string `json:"type"`
Comment string `json:"comment"`
Name string `json:"name"`
Type string `json:"type"`
}
func (spec AttribSpec) Generate() Def {
name := spec.Name
ident := identifier(spec.Name)
var comment string
if spec.Comment != "" {
comment = spec.Comment
} else {
comment = fmt.Sprintf("%s creates a \"%s\" attribute", ident, name)
}
comment := fmt.Sprintf("// %s creates a \"%s\" attribute\n", ident, name)
template := attribTypes[spec.Type].Template
return Def{
Source: formatComment(comment) + fmt.Sprintf(template, ident, name),
Source: comment + fmt.Sprintf(template, ident, name),
Imports: attribTypes[spec.Type].Imports,
}
}
type ElemSpec struct {
Name string `json:"name"`
Void bool `json:"void"`
Comment string `json:"comment"`
Name string `json:"name"`
Void bool `json:"void"`
}
func (spec ElemSpec) Generate() Def {
@ -144,18 +133,13 @@ func (spec ElemSpec) Generate() Def {
name := spec.Name
ident := identifier(spec.Name)
var comment string
if spec.Comment != "" {
comment = spec.Comment
} else {
comment = fmt.Sprintf("%s creates a <%s> element.", ident, name)
}
comment := fmt.Sprintf("// %s creates a <%s> element.\n", ident, name)
template := parentTemplate
if spec.Void {
template = voidTemplate
}
return Def{
Source: formatComment(comment) + fmt.Sprintf(template, ident, name),
Source: comment + fmt.Sprintf(template, ident, name),
}
}