diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-09-19 02:27:09 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-09-19 02:27:09 -0700 |
commit | 00968e11ea5ad0574ca2760d8fc8d9604e620176 (patch) | |
tree | ac36d6ab5dcda18248fbab333f0cad5dbeb5a04c | |
parent | 6c62bf522e1f583f2a1f4c01a6c8d65b31b9e840 (diff) |
refactoring elements.go labeling
-rw-r--r-- | management/editor/elements.go | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/management/editor/elements.go b/management/editor/elements.go index 59d74f0..da63f39 100644 --- a/management/editor/elements.go +++ b/management/editor/elements.go @@ -10,16 +10,9 @@ import ( // The `fieldName` argument will cause a panic if it is not exactly the string // form of the struct field that this editor input is representing func Input(fieldName string, p interface{}, attrs map[string]string) []byte { - var wrapInLabel = true - label, found := attrs["label"] - if !found { - wrapInLabel = false - label = "" - } - - e := newElement("input", label, fieldName, p, attrs) + e := newElement("input", attrs["label"], fieldName, p, attrs) - return domElementSelfClose(e, wrapInLabel) + return domElementSelfClose(e) } // Textarea returns the []byte of a <textarea> HTML element with a label. @@ -27,16 +20,9 @@ func Input(fieldName string, p interface{}, attrs map[string]string) []byte { // The `fieldName` argument will cause a panic if it is not exactly the string // form of the struct field that this editor input is representing func Textarea(fieldName string, p interface{}, attrs map[string]string) []byte { - var wrapInLabel = true - label, found := attrs["label"] - if !found { - wrapInLabel = false - label = "" - } - - e := newElement("textarea", label, fieldName, p, attrs) + e := newElement("textarea", attrs["label"], fieldName, p, attrs) - return domElement(e, wrapInLabel) + return domElement(e) } type element struct { @@ -50,8 +36,8 @@ type element struct { // domElementSelfClose is a special DOM element which is parsed as a // self-closing tag and thus needs to be created differently -func domElementSelfClose(e *element, wrapInLabel bool) []byte { - if wrapInLabel { +func domElementSelfClose(e *element) []byte { + if e.label != "" { e.viewBuf.Write([]byte(`<label>` + e.label + `</label>`)) } e.viewBuf.Write([]byte(`<` + e.TagName + ` value="`)) @@ -67,8 +53,8 @@ func domElementSelfClose(e *element, wrapInLabel bool) []byte { } // domElement creates a DOM element -func domElement(e *element, wrapInLabel bool) []byte { - if wrapInLabel { +func domElement(e *element) []byte { + if e.label != "" { e.viewBuf.Write([]byte(`<label>` + e.label + `</label>`)) } e.viewBuf.Write([]byte(`<` + e.TagName + ` `)) |