Get rid of custom comment generation

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

View File

@ -7,7 +7,7 @@ import "gitlab.codemonkeysoftware.net/b/hatmill"
import "strings" import "strings"
import "strconv" 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 { func Accept(value ...string) hatmill.Attrib {
return hatmill.Attrib{ return hatmill.Attrib{
Key: "accept", Key: "accept",

View File

@ -1,6 +1,6 @@
{ {
"attributes": [ "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": "accept-charset", "type": "space list"},
{"name": "action", "type": "string"}, {"name": "action", "type": "string"},
{"name": "alt", "type": "string"}, {"name": "alt", "type": "string"},
@ -98,7 +98,7 @@
{"name": "wrap", "type": "string"} {"name": "wrap", "type": "string"}
], ],
"elements": [ "elements": [
{"name": "a", "comment": "A creates a hyperlink."}, {"name": "a"},
{"name": "abbr"}, {"name": "abbr"},
{"name": "address"}, {"name": "address"},
{"name": "area", "void": true}, {"name": "area", "void": true},

View File

@ -5,7 +5,7 @@ package element
import "gitlab.codemonkeysoftware.net/b/hatmill" import "gitlab.codemonkeysoftware.net/b/hatmill"
// A creates a hyperlink. // A creates a <a> element.
func A(attribs ...hatmill.Attrib) func(children ...hatmill.Term) hatmill.ParentElement { func A(attribs ...hatmill.Attrib) func(children ...hatmill.Term) hatmill.ParentElement {
return func(children ...hatmill.Term) hatmill.ParentElement { return func(children ...hatmill.Term) hatmill.ParentElement {
return hatmill.ParentElement{ return hatmill.ParentElement{

View File

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