-
Notifications
You must be signed in to change notification settings - Fork 1
/
elements.go.tmpl
150 lines (133 loc) · 5.19 KB
/
elements.go.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// This file is automatically generated. DO NOT EDIT.
package svg
import "encoding/xml"
{{- range $element := .Elements }}
// {{ $element.Article | default "a" | titleize }} {{ $element.GoType }} is {{ $element.Article | default "a" }} {{ $element.Name }} element.
type {{ $element.GoType }} struct {
Attrs map[string]AttrValue
{{- if $element.Container }}
Children []Element
{{- end }}
}
// {{ $element.ConstructorName }} returns a new {{ $element.GoType }}.
func {{ $element.ConstructorName }}({{ if $element.Container }} children ...Element{{ end }}) *{{ $element.GoType }} {
return &{{ $element.GoType }}{
Attrs: map[string]AttrValue{
{{- range $attribute := allAttributes $element }}
{{- if $attribute.Default }}
{{ $attribute.Name | quote }}: String({{ $attribute.Default | quote }}),
{{- end }}
{{- end }}
},
{{- if $element.Container }}
Children: children,
{{- end }}
}
}
{{- if $element.Container }}
// AppendChildren appends the given children.
func (e *{{ $element.GoType }}) AppendChildren(children ...Element) *{{ $element.GoType }} {
e.Children = append(e.Children, children...)
return e
}
{{- end }}
{{- range $attribute := allAttributes $element }}
// {{ $attribute.ExportedGoName }} sets the {{ $attribute.Name }} attribute.
{{- if eq $attribute.Type "ViewBox" }}
func (e *{{ $element.GoType }}) {{ $attribute.ExportedGoName }}(minX, minY, width, height float64) *{{ $element.GoType }} {
e.Attrs[{{ $attribute.Name | quote }}] = ViewBox{MinX: minX, MinY: minY, Width: width, Height: height}
return e
}
{{- else }}
func (e *{{ $element.GoType }}) {{ $attribute.ExportedGoName }}({{ $attribute.GoName }} {{ $attribute.Type }}) *{{ $element.GoType }} {
e.Attrs[{{ $attribute.Name | quote }}] = {{ $attribute.GoName }}
return e
}
{{- end }}
{{- end }}
{{- if eq $element.Name "circle" "ellipse" }}
// CXCY sets the cx and cy attributes.
func (e *{{ $element.GoType }}) CXCY(cx, cy float64, lengthFunc LengthFunc) *{{ $element.GoType }} {
e.Attrs["cx"] = lengthFunc(cx)
e.Attrs["cy"] = lengthFunc(cy)
return e
}
{{- end }}
{{- if eq $element.Name "circle" }}
// CXCYR sets the cx, cy, and r attributes.
func (e *{{ $element.GoType }}) CXCYR(cx, cy, r float64, lengthFunc LengthFunc) *{{ $element.GoType }} {
e.Attrs["cx"] = lengthFunc(cx)
e.Attrs["cy"] = lengthFunc(cy)
e.Attrs["r"] = lengthFunc(r)
return e
}
{{- end }}
{{- if eq $element.Name "marker" }}
// RefXY sets the refX and refY attributes.
func (e *{{ $element.GoType }}) RefXY(refX, refY float64) *{{ $element.GoType }} {
e.Attrs["refX"] = Float64(refX)
e.Attrs["refY"] = Float64(refY)
return e
}
// MarkerWidthHeight sets the markerWidth and markerHeight attributes.
func (e *{{ $element.GoType }}) MarkerWidthHeight(markerWidth, markerHeight float64) *{{ $element.GoType }} {
e.Attrs["markerWidth"] = Float64(markerWidth)
e.Attrs["markerHeight"] = Float64(markerHeight)
return e
}
{{- end }}
{{- if eq $element.Name "ellipse" "rect" }}
// RXRY sets the rx and ry attributes.
func (e *{{ $element.GoType }}) RXRY(rx, ry float64, lengthFunc LengthFunc) *{{ $element.GoType }} {
e.Attrs["rx"] = lengthFunc(rx)
e.Attrs["ry"] = lengthFunc(ry)
return e
}
{{- end }}
{{- if eq $element.Name "foreignObject" "image" "rect" "svg" "symbol" "use" }}
// WidthHeight sets the width and height attributes.
func (e *{{ $element.GoType }}) WidthHeight(width, height float64, lengthFunc LengthFunc) *{{ $element.GoType }} {
e.Attrs["width"] = lengthFunc(width)
e.Attrs["height"] = lengthFunc(height)
return e
}
{{- end }}
{{- if eq $element.Name "foreignObject" "image" "rect" "svg" "symbol" "text" "use" }}
// XY sets the x and y attributes.
func (e *{{ $element.GoType }}) XY(x, y float64, lengthFunc LengthFunc) *{{ $element.GoType }} {
e.Attrs["x"] = lengthFunc(x)
e.Attrs["y"] = lengthFunc(y)
return e
}
{{- else if eq $element.Name "line" }}
// X1Y1X2Y2 sets the x1, y1, x2, and y2 attributes.
func (e *{{ $element.GoType }}) X1Y1X2Y2(x1, y1, x2, y2 float64) *{{ $element.GoType }} {
e.Attrs["x1"] = Float64(x1)
e.Attrs["y1"] = Float64(y1)
e.Attrs["x2"] = Float64(x2)
e.Attrs["y2"] = Float64(y2)
return e
}
{{- else if eq $element.Name "tspan" }}
// XY sets the x and y attributes.
func (e *{{ $element.GoType }}) XY(x, y float64) *{{ $element.GoType }} {
e.Attrs["x"] = Float64(x)
e.Attrs["y"] = Float64(y)
return e
}
{{- end }}
{{- if eq $element.Name "foreignObject" "image" "rect" "svg" "symbol" "use" }}
// XYWidthHeight sets the x, y, width, and height attributes.
func (e *{{ $element.GoType }}) XYWidthHeight(x, y, width, height float64, lengthFunc LengthFunc) *{{ $element.GoType }} {
e.Attrs["x"] = lengthFunc(x)
e.Attrs["y"] = lengthFunc(y)
e.Attrs["width"] = lengthFunc(width)
e.Attrs["height"] = lengthFunc(height)
return e
}
{{- end }}
// MarshallXML implements encoding/xml.Marshaller.MarshalXML.
func (e *{{ $element.GoType }}) MarshalXML(encoder *xml.Encoder, _ xml.StartElement) error {
return encodeElement(encoder, "{{ $element.Name }}", e.Attrs, {{ if $element.Container }}e.Children{{ else }}nil{{ end }})
}
{{- end }}