diff --git a/framework/h/attribute.go b/framework/h/attribute.go index 1807f0a..358ce98 100644 --- a/framework/h/attribute.go +++ b/framework/h/attribute.go @@ -1,43 +1,23 @@ package h -type AttributeR struct { - Name string - Value string -} +import "fmt" -func NewAttribute(name string, value string) *AttributeR { - return &AttributeR{ - Name: name, - Value: value, - } -} - -type TextContent struct { - Content string -} - -func NewTextContent(content string) *TextContent { - return &TextContent{ - Content: content, - } -} - -type RawContent struct { - Content string -} - -func NewRawContent(content string) *RawContent { - return &RawContent{ - Content: content, - } -} - -type ChildList struct { - Children []Ren -} - -func NewChildList(children ...Ren) *ChildList { - return &ChildList{ - Children: children, +type AttributeMap map[string]any + +func (m *AttributeMap) ToMap() map[string]string { + result := make(map[string]string) + for k, v := range *m { + switch v.(type) { + case AttributeMap: + m2 := v.(*AttributeMap).ToMap() + for _, a := range m2 { + result[k] = a + } + case string: + result[k] = v.(string) + default: + result[k] = fmt.Sprintf("%v", v) + } } + return result } diff --git a/framework/h/renderables.go b/framework/h/renderables.go new file mode 100644 index 0000000..fd09ea4 --- /dev/null +++ b/framework/h/renderables.go @@ -0,0 +1,43 @@ +package h + +type AttributeR struct { + Name string + Value string +} + +type TextContent struct { + Content string +} + +type RawContent struct { + Content string +} + +type ChildList struct { + Children []Ren +} + +func NewAttribute(name string, value string) *AttributeR { + return &AttributeR{ + Name: name, + Value: value, + } +} + +func NewRawContent(content string) *RawContent { + return &RawContent{ + Content: content, + } +} + +func NewTextContent(content string) *TextContent { + return &TextContent{ + Content: content, + } +} + +func NewChildList(children ...Ren) *ChildList { + return &ChildList{ + Children: children, + } +} diff --git a/framework/h/renderer.go b/framework/h/renderer.go index 57d9060..229da76 100644 --- a/framework/h/renderer.go +++ b/framework/h/renderer.go @@ -104,21 +104,3 @@ func (l *LifeCycle) Render(builder *strings.Builder) { Children(children...).Render(builder) } - -func (m *AttributeMap) ToMap() map[string]string { - result := make(map[string]string) - for k, v := range *m { - switch v.(type) { - case AttributeMap: - m2 := v.(*AttributeMap).ToMap() - for _, a := range m2 { - result[k] = a - } - case string: - result[k] = v.(string) - default: - result[k] = fmt.Sprintf("%v", v) - } - } - return result -} diff --git a/framework/h/tag.go b/framework/h/tag.go index b9a4fb8..f257300 100644 --- a/framework/h/tag.go +++ b/framework/h/tag.go @@ -70,7 +70,6 @@ func Id(value string) Ren { return Attribute("id", value) } -type AttributeMap map[string]any type ClassMap map[string]bool func Attributes(attrs *AttributeMap) *AttributeMap {