From a0eecef935fd5fa36a33d3d60dc5b63686985aaf Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Tue, 27 Aug 2019 16:59:59 -0600 Subject: [PATCH] Get rid of custom comment generation --- attribute/generated.go | 2 +- defs.json | 4 ++-- element/generated.go | 2 +- internal/codegen/codegen.go | 32 ++++++++------------------------ 4 files changed, 12 insertions(+), 28 deletions(-) diff --git a/attribute/generated.go b/attribute/generated.go index bbe02e8..4323078 100644 --- a/attribute/generated.go +++ b/attribute/generated.go @@ -7,7 +7,7 @@ import "gitlab.codemonkeysoftware.net/b/hatmill" import "strings" import "strconv" -// Accept sets the content types or file types allowed in a form or file input. +// Accept creates a "accept" attribute func Accept(value ...string) hatmill.Attrib { return hatmill.Attrib{ Key: "accept", diff --git a/defs.json b/defs.json index f7df4c0..064889f 100644 --- a/defs.json +++ b/defs.json @@ -1,6 +1,6 @@ { "attributes": [ - {"name": "accept", "type": "comma list", "comment": "Accept sets the content types or file types allowed in a form or file input."}, + {"name": "accept", "type": "comma list"}, {"name": "accept-charset", "type": "space list"}, {"name": "action", "type": "string"}, {"name": "alt", "type": "string"}, @@ -98,7 +98,7 @@ {"name": "wrap", "type": "string"} ], "elements": [ - {"name": "a", "comment": "A creates a hyperlink."}, + {"name": "a"}, {"name": "abbr"}, {"name": "address"}, {"name": "area", "void": true}, diff --git a/element/generated.go b/element/generated.go index 2523cdf..9a93088 100644 --- a/element/generated.go +++ b/element/generated.go @@ -5,7 +5,7 @@ package element import "gitlab.codemonkeysoftware.net/b/hatmill" -// A creates a hyperlink. +// A creates a element. func A(attribs ...hatmill.Attrib) func(children ...hatmill.Term) hatmill.ParentElement { return func(children ...hatmill.Term) hatmill.ParentElement { return hatmill.ParentElement{ diff --git a/internal/codegen/codegen.go b/internal/codegen/codegen.go index 67afa8a..cf0114b 100644 --- a/internal/codegen/codegen.go +++ b/internal/codegen/codegen.go @@ -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), } }