├── .gitignore ├── LICENSE ├── README.md ├── attributes └── attributes.go ├── elements.go ├── examples └── server │ └── main.go └── htmlgogen ├── attr.go ├── main.go ├── tags.go └── templates ├── attributes └── attributes.go └── elements.go /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Julian Vossen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # htmlgo 2 | A library for writing type-safe HTML in Go 3 | 4 | [This blog post](https://julianvossen.de/posts/2019-03-17-htmlgo) provides a short introduction. 5 | 6 | ## Why? 7 | As much as I like the simplicity and the contextual escaping of `html/template`, it doesn't provide much type safety. 8 | Pipelines (e.g. `{{.DoesNotExist.Value}}`) can produce errors at runtime, which should be caught during compilation. 9 | Using nested templates with `html/template` can become hard to maintain, as a template user has to inspect the pipelines within a templates to infer the data format to be passed into the template. 10 | As a bonus, using Go functions to produce HTML elements prevents malformed HTML. 11 | 12 | This library is inspired by [Haskell's blaze-html](http://hackage.haskell.org/package/blaze-html). 13 | 14 | ## Status 15 | * Support for all HTML5 tags and attributes 16 | * Secure, contextual escaping (based on `html/template`) 17 | * Not optimised for performance, expect it to be significantly slower than `html/template` 18 | 19 | ## API 20 | ### Tags 21 | Functions for all HTML tags are part of the top-level package `htmlgo`. The 22 | function signatures are `Tagname(attrs []attributes.Attribute, children ...HTML) HTML` 23 | To omit the first argument, i.e. to create an element without attributes, there 24 | are functions with an underscore suffix `Tagname_(children ...HTML) HTML` to 25 | reduce verbosity. 26 | 27 | ### Attributes 28 | Functions to create attributes are located in the package `htmlgo/attributes`. 29 | Use `Attr(attrs ...attributes.Attribute)` from `htmlgo` as a less verbose way to 30 | create a slice of attributes. The function signatures are `Attributename(data 31 | interface{}, templates ...string) Attribute`. The `data` will be placed into the 32 | given `templates` using `html/template` and, therefore, follows the same syntax. 33 | Note, as `templates` is a variadic argument, it can be omitted entirely, in 34 | which case a `{{.}}` template is used. Data provided as `data` will be escaped, 35 | whereas the `templates` itself can be used to provide values which shall not be 36 | escaped. Again, there are convenience functions with an underscore suffix to omit the first argument, 37 | which is `data` in this case `Attributename_(templates ...string) Attribute`. 38 | Use the underscore-suffixed attribute functions wisely, as they will not escape 39 | their arguments. A good rule of thumb is that you should never pass a variable 40 | into the suffixed functions, only string literals. 41 | 42 | The dataset attributes `data-*` can be added using `Dataset(key, value string)`. 43 | 44 | ## Example 45 | 46 | ```golang 47 | package main 48 | 49 | import ( 50 | "fmt" 51 | 52 | . "github.com/julvo/htmlgo" 53 | a "github.com/julvo/htmlgo/attributes" 54 | ) 55 | 56 | func main() { 57 | var numberDivs HTML 58 | for i := 0; i < 3; i++ { 59 | numberDivs += Div(Attr(a.Style_("font-family:monospace;")), 60 | Text(i)) 61 | } 62 | 63 | page := 64 | Html5_( 65 | Head_(), 66 | Body_( 67 | H1_(Text("Welcome 102 | 105 | 106 | 107 | ``` 108 | -------------------------------------------------------------------------------- /attributes/attributes.go: -------------------------------------------------------------------------------- 1 | package attributes 2 | 3 | import "strings" 4 | 5 | type Attribute struct { 6 | Templ string 7 | Data interface{} 8 | Name string 9 | } 10 | 11 | // Begin of manually implemented attributes 12 | 13 | func Dataset(key, value string) Attribute { 14 | key_ := strings.Replace(key, "-", "_", -1) 15 | return Attribute{ 16 | Data: map[string]string{ 17 | "key": key, 18 | "value": value, 19 | }, 20 | Templ: `{{define "Dataset_`+key_+`"}}data-{{.key}}="{{.value}}"{{end}}`, 21 | Name: "Dataset_"+key_, 22 | } 23 | } 24 | 25 | func Dataset_(key, value string) Attribute { 26 | key_ := strings.Replace(key, "-", "_", -1) 27 | return Attribute{ 28 | Data: map[string]string{ 29 | "value": value, 30 | }, 31 | Templ: `{{define "Dataset_`+key_+`"}}data-`+key+`="{{.value}}"{{end}}`, 32 | Name: "Dataset_"+key_, 33 | } 34 | } 35 | 36 | // Begin of generated attributes 37 | 38 | 39 | func Accept(data interface{}, templs ...string) Attribute { 40 | attr := Attribute{ Data: data, Name: "Accept" } 41 | if len(templs) == 0 { 42 | attr.Templ = `{{define "Accept"}}accept="{{.}}"{{end}}` 43 | } else { 44 | attr.Templ = `{{define "Accept"}}accept="` + strings.Join(templs, " ") + `"{{end}}` 45 | } 46 | return attr 47 | } 48 | 49 | func Accept_(values ...string) Attribute { 50 | return Accept(nil, values...) 51 | } 52 | 53 | 54 | func AcceptCharset(data interface{}, templs ...string) Attribute { 55 | attr := Attribute{ Data: data, Name: "AcceptCharset" } 56 | if len(templs) == 0 { 57 | attr.Templ = `{{define "AcceptCharset"}}accept-charset="{{.}}"{{end}}` 58 | } else { 59 | attr.Templ = `{{define "AcceptCharset"}}accept-charset="` + strings.Join(templs, " ") + `"{{end}}` 60 | } 61 | return attr 62 | } 63 | 64 | func AcceptCharset_(values ...string) Attribute { 65 | return AcceptCharset(nil, values...) 66 | } 67 | 68 | 69 | func Accesskey(data interface{}, templs ...string) Attribute { 70 | attr := Attribute{ Data: data, Name: "Accesskey" } 71 | if len(templs) == 0 { 72 | attr.Templ = `{{define "Accesskey"}}accesskey="{{.}}"{{end}}` 73 | } else { 74 | attr.Templ = `{{define "Accesskey"}}accesskey="` + strings.Join(templs, " ") + `"{{end}}` 75 | } 76 | return attr 77 | } 78 | 79 | func Accesskey_(values ...string) Attribute { 80 | return Accesskey(nil, values...) 81 | } 82 | 83 | 84 | func Action(data interface{}, templs ...string) Attribute { 85 | attr := Attribute{ Data: data, Name: "Action" } 86 | if len(templs) == 0 { 87 | attr.Templ = `{{define "Action"}}action="{{.}}"{{end}}` 88 | } else { 89 | attr.Templ = `{{define "Action"}}action="` + strings.Join(templs, " ") + `"{{end}}` 90 | } 91 | return attr 92 | } 93 | 94 | func Action_(values ...string) Attribute { 95 | return Action(nil, values...) 96 | } 97 | 98 | 99 | func Align(data interface{}, templs ...string) Attribute { 100 | attr := Attribute{ Data: data, Name: "Align" } 101 | if len(templs) == 0 { 102 | attr.Templ = `{{define "Align"}}align="{{.}}"{{end}}` 103 | } else { 104 | attr.Templ = `{{define "Align"}}align="` + strings.Join(templs, " ") + `"{{end}}` 105 | } 106 | return attr 107 | } 108 | 109 | func Align_(values ...string) Attribute { 110 | return Align(nil, values...) 111 | } 112 | 113 | 114 | func Alt(data interface{}, templs ...string) Attribute { 115 | attr := Attribute{ Data: data, Name: "Alt" } 116 | if len(templs) == 0 { 117 | attr.Templ = `{{define "Alt"}}alt="{{.}}"{{end}}` 118 | } else { 119 | attr.Templ = `{{define "Alt"}}alt="` + strings.Join(templs, " ") + `"{{end}}` 120 | } 121 | return attr 122 | } 123 | 124 | func Alt_(values ...string) Attribute { 125 | return Alt(nil, values...) 126 | } 127 | 128 | 129 | func AriaExpanded(data interface{}, templs ...string) Attribute { 130 | attr := Attribute{ Data: data, Name: "AriaExpanded" } 131 | if len(templs) == 0 { 132 | attr.Templ = `{{define "AriaExpanded"}}aria-expanded="{{.}}"{{end}}` 133 | } else { 134 | attr.Templ = `{{define "AriaExpanded"}}aria-expanded="` + strings.Join(templs, " ") + `"{{end}}` 135 | } 136 | return attr 137 | } 138 | 139 | func AriaExpanded_(values ...string) Attribute { 140 | return AriaExpanded(nil, values...) 141 | } 142 | 143 | 144 | func AriaHidden(data interface{}, templs ...string) Attribute { 145 | attr := Attribute{ Data: data, Name: "AriaHidden" } 146 | if len(templs) == 0 { 147 | attr.Templ = `{{define "AriaHidden"}}aria-hidden="{{.}}"{{end}}` 148 | } else { 149 | attr.Templ = `{{define "AriaHidden"}}aria-hidden="` + strings.Join(templs, " ") + `"{{end}}` 150 | } 151 | return attr 152 | } 153 | 154 | func AriaHidden_(values ...string) Attribute { 155 | return AriaHidden(nil, values...) 156 | } 157 | 158 | 159 | func AriaLabel(data interface{}, templs ...string) Attribute { 160 | attr := Attribute{ Data: data, Name: "AriaLabel" } 161 | if len(templs) == 0 { 162 | attr.Templ = `{{define "AriaLabel"}}aria-label="{{.}}"{{end}}` 163 | } else { 164 | attr.Templ = `{{define "AriaLabel"}}aria-label="` + strings.Join(templs, " ") + `"{{end}}` 165 | } 166 | return attr 167 | } 168 | 169 | func AriaLabel_(values ...string) Attribute { 170 | return AriaLabel(nil, values...) 171 | } 172 | 173 | 174 | func Async(data interface{}, templs ...string) Attribute { 175 | attr := Attribute{ Data: data, Name: "Async" } 176 | if len(templs) == 0 { 177 | attr.Templ = `{{define "Async"}}async="{{.}}"{{end}}` 178 | } else { 179 | attr.Templ = `{{define "Async"}}async="` + strings.Join(templs, " ") + `"{{end}}` 180 | } 181 | return attr 182 | } 183 | 184 | func Async_(values ...string) Attribute { 185 | return Async(nil, values...) 186 | } 187 | 188 | 189 | func Autocomplete(data interface{}, templs ...string) Attribute { 190 | attr := Attribute{ Data: data, Name: "Autocomplete" } 191 | if len(templs) == 0 { 192 | attr.Templ = `{{define "Autocomplete"}}autocomplete="{{.}}"{{end}}` 193 | } else { 194 | attr.Templ = `{{define "Autocomplete"}}autocomplete="` + strings.Join(templs, " ") + `"{{end}}` 195 | } 196 | return attr 197 | } 198 | 199 | func Autocomplete_(values ...string) Attribute { 200 | return Autocomplete(nil, values...) 201 | } 202 | 203 | 204 | func Autofocus(data interface{}, templs ...string) Attribute { 205 | attr := Attribute{ Data: data, Name: "Autofocus" } 206 | if len(templs) == 0 { 207 | attr.Templ = `{{define "Autofocus"}}autofocus="{{.}}"{{end}}` 208 | } else { 209 | attr.Templ = `{{define "Autofocus"}}autofocus="` + strings.Join(templs, " ") + `"{{end}}` 210 | } 211 | return attr 212 | } 213 | 214 | func Autofocus_(values ...string) Attribute { 215 | return Autofocus(nil, values...) 216 | } 217 | 218 | 219 | func Autoplay(data interface{}, templs ...string) Attribute { 220 | attr := Attribute{ Data: data, Name: "Autoplay" } 221 | if len(templs) == 0 { 222 | attr.Templ = `{{define "Autoplay"}}autoplay="{{.}}"{{end}}` 223 | } else { 224 | attr.Templ = `{{define "Autoplay"}}autoplay="` + strings.Join(templs, " ") + `"{{end}}` 225 | } 226 | return attr 227 | } 228 | 229 | func Autoplay_(values ...string) Attribute { 230 | return Autoplay(nil, values...) 231 | } 232 | 233 | 234 | func Bgcolor(data interface{}, templs ...string) Attribute { 235 | attr := Attribute{ Data: data, Name: "Bgcolor" } 236 | if len(templs) == 0 { 237 | attr.Templ = `{{define "Bgcolor"}}bgcolor="{{.}}"{{end}}` 238 | } else { 239 | attr.Templ = `{{define "Bgcolor"}}bgcolor="` + strings.Join(templs, " ") + `"{{end}}` 240 | } 241 | return attr 242 | } 243 | 244 | func Bgcolor_(values ...string) Attribute { 245 | return Bgcolor(nil, values...) 246 | } 247 | 248 | 249 | func Border(data interface{}, templs ...string) Attribute { 250 | attr := Attribute{ Data: data, Name: "Border" } 251 | if len(templs) == 0 { 252 | attr.Templ = `{{define "Border"}}border="{{.}}"{{end}}` 253 | } else { 254 | attr.Templ = `{{define "Border"}}border="` + strings.Join(templs, " ") + `"{{end}}` 255 | } 256 | return attr 257 | } 258 | 259 | func Border_(values ...string) Attribute { 260 | return Border(nil, values...) 261 | } 262 | 263 | 264 | func Charset(data interface{}, templs ...string) Attribute { 265 | attr := Attribute{ Data: data, Name: "Charset" } 266 | if len(templs) == 0 { 267 | attr.Templ = `{{define "Charset"}}charset="{{.}}"{{end}}` 268 | } else { 269 | attr.Templ = `{{define "Charset"}}charset="` + strings.Join(templs, " ") + `"{{end}}` 270 | } 271 | return attr 272 | } 273 | 274 | func Charset_(values ...string) Attribute { 275 | return Charset(nil, values...) 276 | } 277 | 278 | 279 | func Checked(data interface{}, templs ...string) Attribute { 280 | attr := Attribute{ Data: data, Name: "Checked" } 281 | if len(templs) == 0 { 282 | attr.Templ = `{{define "Checked"}}checked="{{.}}"{{end}}` 283 | } else { 284 | attr.Templ = `{{define "Checked"}}checked="` + strings.Join(templs, " ") + `"{{end}}` 285 | } 286 | return attr 287 | } 288 | 289 | func Checked_(values ...string) Attribute { 290 | return Checked(nil, values...) 291 | } 292 | 293 | 294 | func Cite(data interface{}, templs ...string) Attribute { 295 | attr := Attribute{ Data: data, Name: "Cite" } 296 | if len(templs) == 0 { 297 | attr.Templ = `{{define "Cite"}}cite="{{.}}"{{end}}` 298 | } else { 299 | attr.Templ = `{{define "Cite"}}cite="` + strings.Join(templs, " ") + `"{{end}}` 300 | } 301 | return attr 302 | } 303 | 304 | func Cite_(values ...string) Attribute { 305 | return Cite(nil, values...) 306 | } 307 | 308 | 309 | func Class(data interface{}, templs ...string) Attribute { 310 | attr := Attribute{ Data: data, Name: "Class" } 311 | if len(templs) == 0 { 312 | attr.Templ = `{{define "Class"}}class="{{.}}"{{end}}` 313 | } else { 314 | attr.Templ = `{{define "Class"}}class="` + strings.Join(templs, " ") + `"{{end}}` 315 | } 316 | return attr 317 | } 318 | 319 | func Class_(values ...string) Attribute { 320 | return Class(nil, values...) 321 | } 322 | 323 | 324 | func Color(data interface{}, templs ...string) Attribute { 325 | attr := Attribute{ Data: data, Name: "Color" } 326 | if len(templs) == 0 { 327 | attr.Templ = `{{define "Color"}}color="{{.}}"{{end}}` 328 | } else { 329 | attr.Templ = `{{define "Color"}}color="` + strings.Join(templs, " ") + `"{{end}}` 330 | } 331 | return attr 332 | } 333 | 334 | func Color_(values ...string) Attribute { 335 | return Color(nil, values...) 336 | } 337 | 338 | 339 | func Cols(data interface{}, templs ...string) Attribute { 340 | attr := Attribute{ Data: data, Name: "Cols" } 341 | if len(templs) == 0 { 342 | attr.Templ = `{{define "Cols"}}cols="{{.}}"{{end}}` 343 | } else { 344 | attr.Templ = `{{define "Cols"}}cols="` + strings.Join(templs, " ") + `"{{end}}` 345 | } 346 | return attr 347 | } 348 | 349 | func Cols_(values ...string) Attribute { 350 | return Cols(nil, values...) 351 | } 352 | 353 | 354 | func Colspan(data interface{}, templs ...string) Attribute { 355 | attr := Attribute{ Data: data, Name: "Colspan" } 356 | if len(templs) == 0 { 357 | attr.Templ = `{{define "Colspan"}}colspan="{{.}}"{{end}}` 358 | } else { 359 | attr.Templ = `{{define "Colspan"}}colspan="` + strings.Join(templs, " ") + `"{{end}}` 360 | } 361 | return attr 362 | } 363 | 364 | func Colspan_(values ...string) Attribute { 365 | return Colspan(nil, values...) 366 | } 367 | 368 | 369 | func Content(data interface{}, templs ...string) Attribute { 370 | attr := Attribute{ Data: data, Name: "Content" } 371 | if len(templs) == 0 { 372 | attr.Templ = `{{define "Content"}}content="{{.}}"{{end}}` 373 | } else { 374 | attr.Templ = `{{define "Content"}}content="` + strings.Join(templs, " ") + `"{{end}}` 375 | } 376 | return attr 377 | } 378 | 379 | func Content_(values ...string) Attribute { 380 | return Content(nil, values...) 381 | } 382 | 383 | 384 | func Contenteditable(data interface{}, templs ...string) Attribute { 385 | attr := Attribute{ Data: data, Name: "Contenteditable" } 386 | if len(templs) == 0 { 387 | attr.Templ = `{{define "Contenteditable"}}contenteditable="{{.}}"{{end}}` 388 | } else { 389 | attr.Templ = `{{define "Contenteditable"}}contenteditable="` + strings.Join(templs, " ") + `"{{end}}` 390 | } 391 | return attr 392 | } 393 | 394 | func Contenteditable_(values ...string) Attribute { 395 | return Contenteditable(nil, values...) 396 | } 397 | 398 | 399 | func Controls(data interface{}, templs ...string) Attribute { 400 | attr := Attribute{ Data: data, Name: "Controls" } 401 | if len(templs) == 0 { 402 | attr.Templ = `{{define "Controls"}}controls="{{.}}"{{end}}` 403 | } else { 404 | attr.Templ = `{{define "Controls"}}controls="` + strings.Join(templs, " ") + `"{{end}}` 405 | } 406 | return attr 407 | } 408 | 409 | func Controls_(values ...string) Attribute { 410 | return Controls(nil, values...) 411 | } 412 | 413 | 414 | func Coords(data interface{}, templs ...string) Attribute { 415 | attr := Attribute{ Data: data, Name: "Coords" } 416 | if len(templs) == 0 { 417 | attr.Templ = `{{define "Coords"}}coords="{{.}}"{{end}}` 418 | } else { 419 | attr.Templ = `{{define "Coords"}}coords="` + strings.Join(templs, " ") + `"{{end}}` 420 | } 421 | return attr 422 | } 423 | 424 | func Coords_(values ...string) Attribute { 425 | return Coords(nil, values...) 426 | } 427 | 428 | 429 | func Data(data interface{}, templs ...string) Attribute { 430 | attr := Attribute{ Data: data, Name: "Data" } 431 | if len(templs) == 0 { 432 | attr.Templ = `{{define "Data"}}data="{{.}}"{{end}}` 433 | } else { 434 | attr.Templ = `{{define "Data"}}data="` + strings.Join(templs, " ") + `"{{end}}` 435 | } 436 | return attr 437 | } 438 | 439 | func Data_(values ...string) Attribute { 440 | return Data(nil, values...) 441 | } 442 | 443 | 444 | func Datetime(data interface{}, templs ...string) Attribute { 445 | attr := Attribute{ Data: data, Name: "Datetime" } 446 | if len(templs) == 0 { 447 | attr.Templ = `{{define "Datetime"}}datetime="{{.}}"{{end}}` 448 | } else { 449 | attr.Templ = `{{define "Datetime"}}datetime="` + strings.Join(templs, " ") + `"{{end}}` 450 | } 451 | return attr 452 | } 453 | 454 | func Datetime_(values ...string) Attribute { 455 | return Datetime(nil, values...) 456 | } 457 | 458 | 459 | func Default(data interface{}, templs ...string) Attribute { 460 | attr := Attribute{ Data: data, Name: "Default" } 461 | if len(templs) == 0 { 462 | attr.Templ = `{{define "Default"}}default="{{.}}"{{end}}` 463 | } else { 464 | attr.Templ = `{{define "Default"}}default="` + strings.Join(templs, " ") + `"{{end}}` 465 | } 466 | return attr 467 | } 468 | 469 | func Default_(values ...string) Attribute { 470 | return Default(nil, values...) 471 | } 472 | 473 | 474 | func Defer(data interface{}, templs ...string) Attribute { 475 | attr := Attribute{ Data: data, Name: "Defer" } 476 | if len(templs) == 0 { 477 | attr.Templ = `{{define "Defer"}}defer="{{.}}"{{end}}` 478 | } else { 479 | attr.Templ = `{{define "Defer"}}defer="` + strings.Join(templs, " ") + `"{{end}}` 480 | } 481 | return attr 482 | } 483 | 484 | func Defer_(values ...string) Attribute { 485 | return Defer(nil, values...) 486 | } 487 | 488 | 489 | func Dir(data interface{}, templs ...string) Attribute { 490 | attr := Attribute{ Data: data, Name: "Dir" } 491 | if len(templs) == 0 { 492 | attr.Templ = `{{define "Dir"}}dir="{{.}}"{{end}}` 493 | } else { 494 | attr.Templ = `{{define "Dir"}}dir="` + strings.Join(templs, " ") + `"{{end}}` 495 | } 496 | return attr 497 | } 498 | 499 | func Dir_(values ...string) Attribute { 500 | return Dir(nil, values...) 501 | } 502 | 503 | 504 | func Dirname(data interface{}, templs ...string) Attribute { 505 | attr := Attribute{ Data: data, Name: "Dirname" } 506 | if len(templs) == 0 { 507 | attr.Templ = `{{define "Dirname"}}dirname="{{.}}"{{end}}` 508 | } else { 509 | attr.Templ = `{{define "Dirname"}}dirname="` + strings.Join(templs, " ") + `"{{end}}` 510 | } 511 | return attr 512 | } 513 | 514 | func Dirname_(values ...string) Attribute { 515 | return Dirname(nil, values...) 516 | } 517 | 518 | 519 | func Disabled(data interface{}, templs ...string) Attribute { 520 | attr := Attribute{ Data: data, Name: "Disabled" } 521 | if len(templs) == 0 { 522 | attr.Templ = `{{define "Disabled"}}disabled="{{.}}"{{end}}` 523 | } else { 524 | attr.Templ = `{{define "Disabled"}}disabled="` + strings.Join(templs, " ") + `"{{end}}` 525 | } 526 | return attr 527 | } 528 | 529 | func Disabled_(values ...string) Attribute { 530 | return Disabled(nil, values...) 531 | } 532 | 533 | 534 | func Download(data interface{}, templs ...string) Attribute { 535 | attr := Attribute{ Data: data, Name: "Download" } 536 | if len(templs) == 0 { 537 | attr.Templ = `{{define "Download"}}download="{{.}}"{{end}}` 538 | } else { 539 | attr.Templ = `{{define "Download"}}download="` + strings.Join(templs, " ") + `"{{end}}` 540 | } 541 | return attr 542 | } 543 | 544 | func Download_(values ...string) Attribute { 545 | return Download(nil, values...) 546 | } 547 | 548 | 549 | func Draggable(data interface{}, templs ...string) Attribute { 550 | attr := Attribute{ Data: data, Name: "Draggable" } 551 | if len(templs) == 0 { 552 | attr.Templ = `{{define "Draggable"}}draggable="{{.}}"{{end}}` 553 | } else { 554 | attr.Templ = `{{define "Draggable"}}draggable="` + strings.Join(templs, " ") + `"{{end}}` 555 | } 556 | return attr 557 | } 558 | 559 | func Draggable_(values ...string) Attribute { 560 | return Draggable(nil, values...) 561 | } 562 | 563 | 564 | func Dropzone(data interface{}, templs ...string) Attribute { 565 | attr := Attribute{ Data: data, Name: "Dropzone" } 566 | if len(templs) == 0 { 567 | attr.Templ = `{{define "Dropzone"}}dropzone="{{.}}"{{end}}` 568 | } else { 569 | attr.Templ = `{{define "Dropzone"}}dropzone="` + strings.Join(templs, " ") + `"{{end}}` 570 | } 571 | return attr 572 | } 573 | 574 | func Dropzone_(values ...string) Attribute { 575 | return Dropzone(nil, values...) 576 | } 577 | 578 | 579 | func Enctype(data interface{}, templs ...string) Attribute { 580 | attr := Attribute{ Data: data, Name: "Enctype" } 581 | if len(templs) == 0 { 582 | attr.Templ = `{{define "Enctype"}}enctype="{{.}}"{{end}}` 583 | } else { 584 | attr.Templ = `{{define "Enctype"}}enctype="` + strings.Join(templs, " ") + `"{{end}}` 585 | } 586 | return attr 587 | } 588 | 589 | func Enctype_(values ...string) Attribute { 590 | return Enctype(nil, values...) 591 | } 592 | 593 | 594 | func For(data interface{}, templs ...string) Attribute { 595 | attr := Attribute{ Data: data, Name: "For" } 596 | if len(templs) == 0 { 597 | attr.Templ = `{{define "For"}}for="{{.}}"{{end}}` 598 | } else { 599 | attr.Templ = `{{define "For"}}for="` + strings.Join(templs, " ") + `"{{end}}` 600 | } 601 | return attr 602 | } 603 | 604 | func For_(values ...string) Attribute { 605 | return For(nil, values...) 606 | } 607 | 608 | 609 | func Form(data interface{}, templs ...string) Attribute { 610 | attr := Attribute{ Data: data, Name: "Form" } 611 | if len(templs) == 0 { 612 | attr.Templ = `{{define "Form"}}form="{{.}}"{{end}}` 613 | } else { 614 | attr.Templ = `{{define "Form"}}form="` + strings.Join(templs, " ") + `"{{end}}` 615 | } 616 | return attr 617 | } 618 | 619 | func Form_(values ...string) Attribute { 620 | return Form(nil, values...) 621 | } 622 | 623 | 624 | func Formaction(data interface{}, templs ...string) Attribute { 625 | attr := Attribute{ Data: data, Name: "Formaction" } 626 | if len(templs) == 0 { 627 | attr.Templ = `{{define "Formaction"}}formaction="{{.}}"{{end}}` 628 | } else { 629 | attr.Templ = `{{define "Formaction"}}formaction="` + strings.Join(templs, " ") + `"{{end}}` 630 | } 631 | return attr 632 | } 633 | 634 | func Formaction_(values ...string) Attribute { 635 | return Formaction(nil, values...) 636 | } 637 | 638 | 639 | func Headers(data interface{}, templs ...string) Attribute { 640 | attr := Attribute{ Data: data, Name: "Headers" } 641 | if len(templs) == 0 { 642 | attr.Templ = `{{define "Headers"}}headers="{{.}}"{{end}}` 643 | } else { 644 | attr.Templ = `{{define "Headers"}}headers="` + strings.Join(templs, " ") + `"{{end}}` 645 | } 646 | return attr 647 | } 648 | 649 | func Headers_(values ...string) Attribute { 650 | return Headers(nil, values...) 651 | } 652 | 653 | 654 | func Height(data interface{}, templs ...string) Attribute { 655 | attr := Attribute{ Data: data, Name: "Height" } 656 | if len(templs) == 0 { 657 | attr.Templ = `{{define "Height"}}height="{{.}}"{{end}}` 658 | } else { 659 | attr.Templ = `{{define "Height"}}height="` + strings.Join(templs, " ") + `"{{end}}` 660 | } 661 | return attr 662 | } 663 | 664 | func Height_(values ...string) Attribute { 665 | return Height(nil, values...) 666 | } 667 | 668 | 669 | func Hidden(data interface{}, templs ...string) Attribute { 670 | attr := Attribute{ Data: data, Name: "Hidden" } 671 | if len(templs) == 0 { 672 | attr.Templ = `{{define "Hidden"}}hidden="{{.}}"{{end}}` 673 | } else { 674 | attr.Templ = `{{define "Hidden"}}hidden="` + strings.Join(templs, " ") + `"{{end}}` 675 | } 676 | return attr 677 | } 678 | 679 | func Hidden_(values ...string) Attribute { 680 | return Hidden(nil, values...) 681 | } 682 | 683 | 684 | func High(data interface{}, templs ...string) Attribute { 685 | attr := Attribute{ Data: data, Name: "High" } 686 | if len(templs) == 0 { 687 | attr.Templ = `{{define "High"}}high="{{.}}"{{end}}` 688 | } else { 689 | attr.Templ = `{{define "High"}}high="` + strings.Join(templs, " ") + `"{{end}}` 690 | } 691 | return attr 692 | } 693 | 694 | func High_(values ...string) Attribute { 695 | return High(nil, values...) 696 | } 697 | 698 | 699 | func Href(data interface{}, templs ...string) Attribute { 700 | attr := Attribute{ Data: data, Name: "Href" } 701 | if len(templs) == 0 { 702 | attr.Templ = `{{define "Href"}}href="{{.}}"{{end}}` 703 | } else { 704 | attr.Templ = `{{define "Href"}}href="` + strings.Join(templs, " ") + `"{{end}}` 705 | } 706 | return attr 707 | } 708 | 709 | func Href_(values ...string) Attribute { 710 | return Href(nil, values...) 711 | } 712 | 713 | 714 | func Hreflang(data interface{}, templs ...string) Attribute { 715 | attr := Attribute{ Data: data, Name: "Hreflang" } 716 | if len(templs) == 0 { 717 | attr.Templ = `{{define "Hreflang"}}hreflang="{{.}}"{{end}}` 718 | } else { 719 | attr.Templ = `{{define "Hreflang"}}hreflang="` + strings.Join(templs, " ") + `"{{end}}` 720 | } 721 | return attr 722 | } 723 | 724 | func Hreflang_(values ...string) Attribute { 725 | return Hreflang(nil, values...) 726 | } 727 | 728 | 729 | func HttpEquiv(data interface{}, templs ...string) Attribute { 730 | attr := Attribute{ Data: data, Name: "HttpEquiv" } 731 | if len(templs) == 0 { 732 | attr.Templ = `{{define "HttpEquiv"}}http-equiv="{{.}}"{{end}}` 733 | } else { 734 | attr.Templ = `{{define "HttpEquiv"}}http-equiv="` + strings.Join(templs, " ") + `"{{end}}` 735 | } 736 | return attr 737 | } 738 | 739 | func HttpEquiv_(values ...string) Attribute { 740 | return HttpEquiv(nil, values...) 741 | } 742 | 743 | 744 | func Id(data interface{}, templs ...string) Attribute { 745 | attr := Attribute{ Data: data, Name: "Id" } 746 | if len(templs) == 0 { 747 | attr.Templ = `{{define "Id"}}id="{{.}}"{{end}}` 748 | } else { 749 | attr.Templ = `{{define "Id"}}id="` + strings.Join(templs, " ") + `"{{end}}` 750 | } 751 | return attr 752 | } 753 | 754 | func Id_(values ...string) Attribute { 755 | return Id(nil, values...) 756 | } 757 | 758 | 759 | func InitialScale(data interface{}, templs ...string) Attribute { 760 | attr := Attribute{ Data: data, Name: "InitialScale" } 761 | if len(templs) == 0 { 762 | attr.Templ = `{{define "InitialScale"}}initial-scale="{{.}}"{{end}}` 763 | } else { 764 | attr.Templ = `{{define "InitialScale"}}initial-scale="` + strings.Join(templs, " ") + `"{{end}}` 765 | } 766 | return attr 767 | } 768 | 769 | func InitialScale_(values ...string) Attribute { 770 | return InitialScale(nil, values...) 771 | } 772 | 773 | 774 | func Ismap(data interface{}, templs ...string) Attribute { 775 | attr := Attribute{ Data: data, Name: "Ismap" } 776 | if len(templs) == 0 { 777 | attr.Templ = `{{define "Ismap"}}ismap="{{.}}"{{end}}` 778 | } else { 779 | attr.Templ = `{{define "Ismap"}}ismap="` + strings.Join(templs, " ") + `"{{end}}` 780 | } 781 | return attr 782 | } 783 | 784 | func Ismap_(values ...string) Attribute { 785 | return Ismap(nil, values...) 786 | } 787 | 788 | 789 | func Kind(data interface{}, templs ...string) Attribute { 790 | attr := Attribute{ Data: data, Name: "Kind" } 791 | if len(templs) == 0 { 792 | attr.Templ = `{{define "Kind"}}kind="{{.}}"{{end}}` 793 | } else { 794 | attr.Templ = `{{define "Kind"}}kind="` + strings.Join(templs, " ") + `"{{end}}` 795 | } 796 | return attr 797 | } 798 | 799 | func Kind_(values ...string) Attribute { 800 | return Kind(nil, values...) 801 | } 802 | 803 | 804 | func Label(data interface{}, templs ...string) Attribute { 805 | attr := Attribute{ Data: data, Name: "Label" } 806 | if len(templs) == 0 { 807 | attr.Templ = `{{define "Label"}}label="{{.}}"{{end}}` 808 | } else { 809 | attr.Templ = `{{define "Label"}}label="` + strings.Join(templs, " ") + `"{{end}}` 810 | } 811 | return attr 812 | } 813 | 814 | func Label_(values ...string) Attribute { 815 | return Label(nil, values...) 816 | } 817 | 818 | 819 | func Lang(data interface{}, templs ...string) Attribute { 820 | attr := Attribute{ Data: data, Name: "Lang" } 821 | if len(templs) == 0 { 822 | attr.Templ = `{{define "Lang"}}lang="{{.}}"{{end}}` 823 | } else { 824 | attr.Templ = `{{define "Lang"}}lang="` + strings.Join(templs, " ") + `"{{end}}` 825 | } 826 | return attr 827 | } 828 | 829 | func Lang_(values ...string) Attribute { 830 | return Lang(nil, values...) 831 | } 832 | 833 | 834 | func List(data interface{}, templs ...string) Attribute { 835 | attr := Attribute{ Data: data, Name: "List" } 836 | if len(templs) == 0 { 837 | attr.Templ = `{{define "List"}}list="{{.}}"{{end}}` 838 | } else { 839 | attr.Templ = `{{define "List"}}list="` + strings.Join(templs, " ") + `"{{end}}` 840 | } 841 | return attr 842 | } 843 | 844 | func List_(values ...string) Attribute { 845 | return List(nil, values...) 846 | } 847 | 848 | 849 | func Loop(data interface{}, templs ...string) Attribute { 850 | attr := Attribute{ Data: data, Name: "Loop" } 851 | if len(templs) == 0 { 852 | attr.Templ = `{{define "Loop"}}loop="{{.}}"{{end}}` 853 | } else { 854 | attr.Templ = `{{define "Loop"}}loop="` + strings.Join(templs, " ") + `"{{end}}` 855 | } 856 | return attr 857 | } 858 | 859 | func Loop_(values ...string) Attribute { 860 | return Loop(nil, values...) 861 | } 862 | 863 | 864 | func Low(data interface{}, templs ...string) Attribute { 865 | attr := Attribute{ Data: data, Name: "Low" } 866 | if len(templs) == 0 { 867 | attr.Templ = `{{define "Low"}}low="{{.}}"{{end}}` 868 | } else { 869 | attr.Templ = `{{define "Low"}}low="` + strings.Join(templs, " ") + `"{{end}}` 870 | } 871 | return attr 872 | } 873 | 874 | func Low_(values ...string) Attribute { 875 | return Low(nil, values...) 876 | } 877 | 878 | 879 | func Max(data interface{}, templs ...string) Attribute { 880 | attr := Attribute{ Data: data, Name: "Max" } 881 | if len(templs) == 0 { 882 | attr.Templ = `{{define "Max"}}max="{{.}}"{{end}}` 883 | } else { 884 | attr.Templ = `{{define "Max"}}max="` + strings.Join(templs, " ") + `"{{end}}` 885 | } 886 | return attr 887 | } 888 | 889 | func Max_(values ...string) Attribute { 890 | return Max(nil, values...) 891 | } 892 | 893 | 894 | func Maxlength(data interface{}, templs ...string) Attribute { 895 | attr := Attribute{ Data: data, Name: "Maxlength" } 896 | if len(templs) == 0 { 897 | attr.Templ = `{{define "Maxlength"}}maxlength="{{.}}"{{end}}` 898 | } else { 899 | attr.Templ = `{{define "Maxlength"}}maxlength="` + strings.Join(templs, " ") + `"{{end}}` 900 | } 901 | return attr 902 | } 903 | 904 | func Maxlength_(values ...string) Attribute { 905 | return Maxlength(nil, values...) 906 | } 907 | 908 | 909 | func Media(data interface{}, templs ...string) Attribute { 910 | attr := Attribute{ Data: data, Name: "Media" } 911 | if len(templs) == 0 { 912 | attr.Templ = `{{define "Media"}}media="{{.}}"{{end}}` 913 | } else { 914 | attr.Templ = `{{define "Media"}}media="` + strings.Join(templs, " ") + `"{{end}}` 915 | } 916 | return attr 917 | } 918 | 919 | func Media_(values ...string) Attribute { 920 | return Media(nil, values...) 921 | } 922 | 923 | 924 | func Method(data interface{}, templs ...string) Attribute { 925 | attr := Attribute{ Data: data, Name: "Method" } 926 | if len(templs) == 0 { 927 | attr.Templ = `{{define "Method"}}method="{{.}}"{{end}}` 928 | } else { 929 | attr.Templ = `{{define "Method"}}method="` + strings.Join(templs, " ") + `"{{end}}` 930 | } 931 | return attr 932 | } 933 | 934 | func Method_(values ...string) Attribute { 935 | return Method(nil, values...) 936 | } 937 | 938 | 939 | func Min(data interface{}, templs ...string) Attribute { 940 | attr := Attribute{ Data: data, Name: "Min" } 941 | if len(templs) == 0 { 942 | attr.Templ = `{{define "Min"}}min="{{.}}"{{end}}` 943 | } else { 944 | attr.Templ = `{{define "Min"}}min="` + strings.Join(templs, " ") + `"{{end}}` 945 | } 946 | return attr 947 | } 948 | 949 | func Min_(values ...string) Attribute { 950 | return Min(nil, values...) 951 | } 952 | 953 | 954 | func Multiple(data interface{}, templs ...string) Attribute { 955 | attr := Attribute{ Data: data, Name: "Multiple" } 956 | if len(templs) == 0 { 957 | attr.Templ = `{{define "Multiple"}}multiple="{{.}}"{{end}}` 958 | } else { 959 | attr.Templ = `{{define "Multiple"}}multiple="` + strings.Join(templs, " ") + `"{{end}}` 960 | } 961 | return attr 962 | } 963 | 964 | func Multiple_(values ...string) Attribute { 965 | return Multiple(nil, values...) 966 | } 967 | 968 | 969 | func Muted(data interface{}, templs ...string) Attribute { 970 | attr := Attribute{ Data: data, Name: "Muted" } 971 | if len(templs) == 0 { 972 | attr.Templ = `{{define "Muted"}}muted="{{.}}"{{end}}` 973 | } else { 974 | attr.Templ = `{{define "Muted"}}muted="` + strings.Join(templs, " ") + `"{{end}}` 975 | } 976 | return attr 977 | } 978 | 979 | func Muted_(values ...string) Attribute { 980 | return Muted(nil, values...) 981 | } 982 | 983 | 984 | func Name(data interface{}, templs ...string) Attribute { 985 | attr := Attribute{ Data: data, Name: "Name" } 986 | if len(templs) == 0 { 987 | attr.Templ = `{{define "Name"}}name="{{.}}"{{end}}` 988 | } else { 989 | attr.Templ = `{{define "Name"}}name="` + strings.Join(templs, " ") + `"{{end}}` 990 | } 991 | return attr 992 | } 993 | 994 | func Name_(values ...string) Attribute { 995 | return Name(nil, values...) 996 | } 997 | 998 | 999 | func Novalidate(data interface{}, templs ...string) Attribute { 1000 | attr := Attribute{ Data: data, Name: "Novalidate" } 1001 | if len(templs) == 0 { 1002 | attr.Templ = `{{define "Novalidate"}}novalidate="{{.}}"{{end}}` 1003 | } else { 1004 | attr.Templ = `{{define "Novalidate"}}novalidate="` + strings.Join(templs, " ") + `"{{end}}` 1005 | } 1006 | return attr 1007 | } 1008 | 1009 | func Novalidate_(values ...string) Attribute { 1010 | return Novalidate(nil, values...) 1011 | } 1012 | 1013 | 1014 | func Onabort(data interface{}, templs ...string) Attribute { 1015 | attr := Attribute{ Data: data, Name: "Onabort" } 1016 | if len(templs) == 0 { 1017 | attr.Templ = `{{define "Onabort"}}onabort="{{.}}"{{end}}` 1018 | } else { 1019 | attr.Templ = `{{define "Onabort"}}onabort="` + strings.Join(templs, " ") + `"{{end}}` 1020 | } 1021 | return attr 1022 | } 1023 | 1024 | func Onabort_(values ...string) Attribute { 1025 | return Onabort(nil, values...) 1026 | } 1027 | 1028 | 1029 | func Onafterprint(data interface{}, templs ...string) Attribute { 1030 | attr := Attribute{ Data: data, Name: "Onafterprint" } 1031 | if len(templs) == 0 { 1032 | attr.Templ = `{{define "Onafterprint"}}onafterprint="{{.}}"{{end}}` 1033 | } else { 1034 | attr.Templ = `{{define "Onafterprint"}}onafterprint="` + strings.Join(templs, " ") + `"{{end}}` 1035 | } 1036 | return attr 1037 | } 1038 | 1039 | func Onafterprint_(values ...string) Attribute { 1040 | return Onafterprint(nil, values...) 1041 | } 1042 | 1043 | 1044 | func Onbeforeprint(data interface{}, templs ...string) Attribute { 1045 | attr := Attribute{ Data: data, Name: "Onbeforeprint" } 1046 | if len(templs) == 0 { 1047 | attr.Templ = `{{define "Onbeforeprint"}}onbeforeprint="{{.}}"{{end}}` 1048 | } else { 1049 | attr.Templ = `{{define "Onbeforeprint"}}onbeforeprint="` + strings.Join(templs, " ") + `"{{end}}` 1050 | } 1051 | return attr 1052 | } 1053 | 1054 | func Onbeforeprint_(values ...string) Attribute { 1055 | return Onbeforeprint(nil, values...) 1056 | } 1057 | 1058 | 1059 | func Onbeforeunload(data interface{}, templs ...string) Attribute { 1060 | attr := Attribute{ Data: data, Name: "Onbeforeunload" } 1061 | if len(templs) == 0 { 1062 | attr.Templ = `{{define "Onbeforeunload"}}onbeforeunload="{{.}}"{{end}}` 1063 | } else { 1064 | attr.Templ = `{{define "Onbeforeunload"}}onbeforeunload="` + strings.Join(templs, " ") + `"{{end}}` 1065 | } 1066 | return attr 1067 | } 1068 | 1069 | func Onbeforeunload_(values ...string) Attribute { 1070 | return Onbeforeunload(nil, values...) 1071 | } 1072 | 1073 | 1074 | func Onblur(data interface{}, templs ...string) Attribute { 1075 | attr := Attribute{ Data: data, Name: "Onblur" } 1076 | if len(templs) == 0 { 1077 | attr.Templ = `{{define "Onblur"}}onblur="{{.}}"{{end}}` 1078 | } else { 1079 | attr.Templ = `{{define "Onblur"}}onblur="` + strings.Join(templs, " ") + `"{{end}}` 1080 | } 1081 | return attr 1082 | } 1083 | 1084 | func Onblur_(values ...string) Attribute { 1085 | return Onblur(nil, values...) 1086 | } 1087 | 1088 | 1089 | func Oncanplay(data interface{}, templs ...string) Attribute { 1090 | attr := Attribute{ Data: data, Name: "Oncanplay" } 1091 | if len(templs) == 0 { 1092 | attr.Templ = `{{define "Oncanplay"}}oncanplay="{{.}}"{{end}}` 1093 | } else { 1094 | attr.Templ = `{{define "Oncanplay"}}oncanplay="` + strings.Join(templs, " ") + `"{{end}}` 1095 | } 1096 | return attr 1097 | } 1098 | 1099 | func Oncanplay_(values ...string) Attribute { 1100 | return Oncanplay(nil, values...) 1101 | } 1102 | 1103 | 1104 | func Oncanplaythrough(data interface{}, templs ...string) Attribute { 1105 | attr := Attribute{ Data: data, Name: "Oncanplaythrough" } 1106 | if len(templs) == 0 { 1107 | attr.Templ = `{{define "Oncanplaythrough"}}oncanplaythrough="{{.}}"{{end}}` 1108 | } else { 1109 | attr.Templ = `{{define "Oncanplaythrough"}}oncanplaythrough="` + strings.Join(templs, " ") + `"{{end}}` 1110 | } 1111 | return attr 1112 | } 1113 | 1114 | func Oncanplaythrough_(values ...string) Attribute { 1115 | return Oncanplaythrough(nil, values...) 1116 | } 1117 | 1118 | 1119 | func Onchange(data interface{}, templs ...string) Attribute { 1120 | attr := Attribute{ Data: data, Name: "Onchange" } 1121 | if len(templs) == 0 { 1122 | attr.Templ = `{{define "Onchange"}}onchange="{{.}}"{{end}}` 1123 | } else { 1124 | attr.Templ = `{{define "Onchange"}}onchange="` + strings.Join(templs, " ") + `"{{end}}` 1125 | } 1126 | return attr 1127 | } 1128 | 1129 | func Onchange_(values ...string) Attribute { 1130 | return Onchange(nil, values...) 1131 | } 1132 | 1133 | 1134 | func Onclick(data interface{}, templs ...string) Attribute { 1135 | attr := Attribute{ Data: data, Name: "Onclick" } 1136 | if len(templs) == 0 { 1137 | attr.Templ = `{{define "Onclick"}}onclick="{{.}}"{{end}}` 1138 | } else { 1139 | attr.Templ = `{{define "Onclick"}}onclick="` + strings.Join(templs, " ") + `"{{end}}` 1140 | } 1141 | return attr 1142 | } 1143 | 1144 | func Onclick_(values ...string) Attribute { 1145 | return Onclick(nil, values...) 1146 | } 1147 | 1148 | 1149 | func Oncontextmenu(data interface{}, templs ...string) Attribute { 1150 | attr := Attribute{ Data: data, Name: "Oncontextmenu" } 1151 | if len(templs) == 0 { 1152 | attr.Templ = `{{define "Oncontextmenu"}}oncontextmenu="{{.}}"{{end}}` 1153 | } else { 1154 | attr.Templ = `{{define "Oncontextmenu"}}oncontextmenu="` + strings.Join(templs, " ") + `"{{end}}` 1155 | } 1156 | return attr 1157 | } 1158 | 1159 | func Oncontextmenu_(values ...string) Attribute { 1160 | return Oncontextmenu(nil, values...) 1161 | } 1162 | 1163 | 1164 | func Oncopy(data interface{}, templs ...string) Attribute { 1165 | attr := Attribute{ Data: data, Name: "Oncopy" } 1166 | if len(templs) == 0 { 1167 | attr.Templ = `{{define "Oncopy"}}oncopy="{{.}}"{{end}}` 1168 | } else { 1169 | attr.Templ = `{{define "Oncopy"}}oncopy="` + strings.Join(templs, " ") + `"{{end}}` 1170 | } 1171 | return attr 1172 | } 1173 | 1174 | func Oncopy_(values ...string) Attribute { 1175 | return Oncopy(nil, values...) 1176 | } 1177 | 1178 | 1179 | func Oncuechange(data interface{}, templs ...string) Attribute { 1180 | attr := Attribute{ Data: data, Name: "Oncuechange" } 1181 | if len(templs) == 0 { 1182 | attr.Templ = `{{define "Oncuechange"}}oncuechange="{{.}}"{{end}}` 1183 | } else { 1184 | attr.Templ = `{{define "Oncuechange"}}oncuechange="` + strings.Join(templs, " ") + `"{{end}}` 1185 | } 1186 | return attr 1187 | } 1188 | 1189 | func Oncuechange_(values ...string) Attribute { 1190 | return Oncuechange(nil, values...) 1191 | } 1192 | 1193 | 1194 | func Oncut(data interface{}, templs ...string) Attribute { 1195 | attr := Attribute{ Data: data, Name: "Oncut" } 1196 | if len(templs) == 0 { 1197 | attr.Templ = `{{define "Oncut"}}oncut="{{.}}"{{end}}` 1198 | } else { 1199 | attr.Templ = `{{define "Oncut"}}oncut="` + strings.Join(templs, " ") + `"{{end}}` 1200 | } 1201 | return attr 1202 | } 1203 | 1204 | func Oncut_(values ...string) Attribute { 1205 | return Oncut(nil, values...) 1206 | } 1207 | 1208 | 1209 | func Ondblclick(data interface{}, templs ...string) Attribute { 1210 | attr := Attribute{ Data: data, Name: "Ondblclick" } 1211 | if len(templs) == 0 { 1212 | attr.Templ = `{{define "Ondblclick"}}ondblclick="{{.}}"{{end}}` 1213 | } else { 1214 | attr.Templ = `{{define "Ondblclick"}}ondblclick="` + strings.Join(templs, " ") + `"{{end}}` 1215 | } 1216 | return attr 1217 | } 1218 | 1219 | func Ondblclick_(values ...string) Attribute { 1220 | return Ondblclick(nil, values...) 1221 | } 1222 | 1223 | 1224 | func Ondrag(data interface{}, templs ...string) Attribute { 1225 | attr := Attribute{ Data: data, Name: "Ondrag" } 1226 | if len(templs) == 0 { 1227 | attr.Templ = `{{define "Ondrag"}}ondrag="{{.}}"{{end}}` 1228 | } else { 1229 | attr.Templ = `{{define "Ondrag"}}ondrag="` + strings.Join(templs, " ") + `"{{end}}` 1230 | } 1231 | return attr 1232 | } 1233 | 1234 | func Ondrag_(values ...string) Attribute { 1235 | return Ondrag(nil, values...) 1236 | } 1237 | 1238 | 1239 | func Ondragend(data interface{}, templs ...string) Attribute { 1240 | attr := Attribute{ Data: data, Name: "Ondragend" } 1241 | if len(templs) == 0 { 1242 | attr.Templ = `{{define "Ondragend"}}ondragend="{{.}}"{{end}}` 1243 | } else { 1244 | attr.Templ = `{{define "Ondragend"}}ondragend="` + strings.Join(templs, " ") + `"{{end}}` 1245 | } 1246 | return attr 1247 | } 1248 | 1249 | func Ondragend_(values ...string) Attribute { 1250 | return Ondragend(nil, values...) 1251 | } 1252 | 1253 | 1254 | func Ondragenter(data interface{}, templs ...string) Attribute { 1255 | attr := Attribute{ Data: data, Name: "Ondragenter" } 1256 | if len(templs) == 0 { 1257 | attr.Templ = `{{define "Ondragenter"}}ondragenter="{{.}}"{{end}}` 1258 | } else { 1259 | attr.Templ = `{{define "Ondragenter"}}ondragenter="` + strings.Join(templs, " ") + `"{{end}}` 1260 | } 1261 | return attr 1262 | } 1263 | 1264 | func Ondragenter_(values ...string) Attribute { 1265 | return Ondragenter(nil, values...) 1266 | } 1267 | 1268 | 1269 | func Ondragleave(data interface{}, templs ...string) Attribute { 1270 | attr := Attribute{ Data: data, Name: "Ondragleave" } 1271 | if len(templs) == 0 { 1272 | attr.Templ = `{{define "Ondragleave"}}ondragleave="{{.}}"{{end}}` 1273 | } else { 1274 | attr.Templ = `{{define "Ondragleave"}}ondragleave="` + strings.Join(templs, " ") + `"{{end}}` 1275 | } 1276 | return attr 1277 | } 1278 | 1279 | func Ondragleave_(values ...string) Attribute { 1280 | return Ondragleave(nil, values...) 1281 | } 1282 | 1283 | 1284 | func Ondragover(data interface{}, templs ...string) Attribute { 1285 | attr := Attribute{ Data: data, Name: "Ondragover" } 1286 | if len(templs) == 0 { 1287 | attr.Templ = `{{define "Ondragover"}}ondragover="{{.}}"{{end}}` 1288 | } else { 1289 | attr.Templ = `{{define "Ondragover"}}ondragover="` + strings.Join(templs, " ") + `"{{end}}` 1290 | } 1291 | return attr 1292 | } 1293 | 1294 | func Ondragover_(values ...string) Attribute { 1295 | return Ondragover(nil, values...) 1296 | } 1297 | 1298 | 1299 | func Ondragstart(data interface{}, templs ...string) Attribute { 1300 | attr := Attribute{ Data: data, Name: "Ondragstart" } 1301 | if len(templs) == 0 { 1302 | attr.Templ = `{{define "Ondragstart"}}ondragstart="{{.}}"{{end}}` 1303 | } else { 1304 | attr.Templ = `{{define "Ondragstart"}}ondragstart="` + strings.Join(templs, " ") + `"{{end}}` 1305 | } 1306 | return attr 1307 | } 1308 | 1309 | func Ondragstart_(values ...string) Attribute { 1310 | return Ondragstart(nil, values...) 1311 | } 1312 | 1313 | 1314 | func Ondrop(data interface{}, templs ...string) Attribute { 1315 | attr := Attribute{ Data: data, Name: "Ondrop" } 1316 | if len(templs) == 0 { 1317 | attr.Templ = `{{define "Ondrop"}}ondrop="{{.}}"{{end}}` 1318 | } else { 1319 | attr.Templ = `{{define "Ondrop"}}ondrop="` + strings.Join(templs, " ") + `"{{end}}` 1320 | } 1321 | return attr 1322 | } 1323 | 1324 | func Ondrop_(values ...string) Attribute { 1325 | return Ondrop(nil, values...) 1326 | } 1327 | 1328 | 1329 | func Ondurationchange(data interface{}, templs ...string) Attribute { 1330 | attr := Attribute{ Data: data, Name: "Ondurationchange" } 1331 | if len(templs) == 0 { 1332 | attr.Templ = `{{define "Ondurationchange"}}ondurationchange="{{.}}"{{end}}` 1333 | } else { 1334 | attr.Templ = `{{define "Ondurationchange"}}ondurationchange="` + strings.Join(templs, " ") + `"{{end}}` 1335 | } 1336 | return attr 1337 | } 1338 | 1339 | func Ondurationchange_(values ...string) Attribute { 1340 | return Ondurationchange(nil, values...) 1341 | } 1342 | 1343 | 1344 | func Onemptied(data interface{}, templs ...string) Attribute { 1345 | attr := Attribute{ Data: data, Name: "Onemptied" } 1346 | if len(templs) == 0 { 1347 | attr.Templ = `{{define "Onemptied"}}onemptied="{{.}}"{{end}}` 1348 | } else { 1349 | attr.Templ = `{{define "Onemptied"}}onemptied="` + strings.Join(templs, " ") + `"{{end}}` 1350 | } 1351 | return attr 1352 | } 1353 | 1354 | func Onemptied_(values ...string) Attribute { 1355 | return Onemptied(nil, values...) 1356 | } 1357 | 1358 | 1359 | func Onended(data interface{}, templs ...string) Attribute { 1360 | attr := Attribute{ Data: data, Name: "Onended" } 1361 | if len(templs) == 0 { 1362 | attr.Templ = `{{define "Onended"}}onended="{{.}}"{{end}}` 1363 | } else { 1364 | attr.Templ = `{{define "Onended"}}onended="` + strings.Join(templs, " ") + `"{{end}}` 1365 | } 1366 | return attr 1367 | } 1368 | 1369 | func Onended_(values ...string) Attribute { 1370 | return Onended(nil, values...) 1371 | } 1372 | 1373 | 1374 | func Onerror(data interface{}, templs ...string) Attribute { 1375 | attr := Attribute{ Data: data, Name: "Onerror" } 1376 | if len(templs) == 0 { 1377 | attr.Templ = `{{define "Onerror"}}onerror="{{.}}"{{end}}` 1378 | } else { 1379 | attr.Templ = `{{define "Onerror"}}onerror="` + strings.Join(templs, " ") + `"{{end}}` 1380 | } 1381 | return attr 1382 | } 1383 | 1384 | func Onerror_(values ...string) Attribute { 1385 | return Onerror(nil, values...) 1386 | } 1387 | 1388 | 1389 | func Onfocus(data interface{}, templs ...string) Attribute { 1390 | attr := Attribute{ Data: data, Name: "Onfocus" } 1391 | if len(templs) == 0 { 1392 | attr.Templ = `{{define "Onfocus"}}onfocus="{{.}}"{{end}}` 1393 | } else { 1394 | attr.Templ = `{{define "Onfocus"}}onfocus="` + strings.Join(templs, " ") + `"{{end}}` 1395 | } 1396 | return attr 1397 | } 1398 | 1399 | func Onfocus_(values ...string) Attribute { 1400 | return Onfocus(nil, values...) 1401 | } 1402 | 1403 | 1404 | func Onhashchange(data interface{}, templs ...string) Attribute { 1405 | attr := Attribute{ Data: data, Name: "Onhashchange" } 1406 | if len(templs) == 0 { 1407 | attr.Templ = `{{define "Onhashchange"}}onhashchange="{{.}}"{{end}}` 1408 | } else { 1409 | attr.Templ = `{{define "Onhashchange"}}onhashchange="` + strings.Join(templs, " ") + `"{{end}}` 1410 | } 1411 | return attr 1412 | } 1413 | 1414 | func Onhashchange_(values ...string) Attribute { 1415 | return Onhashchange(nil, values...) 1416 | } 1417 | 1418 | 1419 | func Oninput(data interface{}, templs ...string) Attribute { 1420 | attr := Attribute{ Data: data, Name: "Oninput" } 1421 | if len(templs) == 0 { 1422 | attr.Templ = `{{define "Oninput"}}oninput="{{.}}"{{end}}` 1423 | } else { 1424 | attr.Templ = `{{define "Oninput"}}oninput="` + strings.Join(templs, " ") + `"{{end}}` 1425 | } 1426 | return attr 1427 | } 1428 | 1429 | func Oninput_(values ...string) Attribute { 1430 | return Oninput(nil, values...) 1431 | } 1432 | 1433 | 1434 | func Oninvalid(data interface{}, templs ...string) Attribute { 1435 | attr := Attribute{ Data: data, Name: "Oninvalid" } 1436 | if len(templs) == 0 { 1437 | attr.Templ = `{{define "Oninvalid"}}oninvalid="{{.}}"{{end}}` 1438 | } else { 1439 | attr.Templ = `{{define "Oninvalid"}}oninvalid="` + strings.Join(templs, " ") + `"{{end}}` 1440 | } 1441 | return attr 1442 | } 1443 | 1444 | func Oninvalid_(values ...string) Attribute { 1445 | return Oninvalid(nil, values...) 1446 | } 1447 | 1448 | 1449 | func Onkeydown(data interface{}, templs ...string) Attribute { 1450 | attr := Attribute{ Data: data, Name: "Onkeydown" } 1451 | if len(templs) == 0 { 1452 | attr.Templ = `{{define "Onkeydown"}}onkeydown="{{.}}"{{end}}` 1453 | } else { 1454 | attr.Templ = `{{define "Onkeydown"}}onkeydown="` + strings.Join(templs, " ") + `"{{end}}` 1455 | } 1456 | return attr 1457 | } 1458 | 1459 | func Onkeydown_(values ...string) Attribute { 1460 | return Onkeydown(nil, values...) 1461 | } 1462 | 1463 | 1464 | func Onkeypress(data interface{}, templs ...string) Attribute { 1465 | attr := Attribute{ Data: data, Name: "Onkeypress" } 1466 | if len(templs) == 0 { 1467 | attr.Templ = `{{define "Onkeypress"}}onkeypress="{{.}}"{{end}}` 1468 | } else { 1469 | attr.Templ = `{{define "Onkeypress"}}onkeypress="` + strings.Join(templs, " ") + `"{{end}}` 1470 | } 1471 | return attr 1472 | } 1473 | 1474 | func Onkeypress_(values ...string) Attribute { 1475 | return Onkeypress(nil, values...) 1476 | } 1477 | 1478 | 1479 | func Onkeyup(data interface{}, templs ...string) Attribute { 1480 | attr := Attribute{ Data: data, Name: "Onkeyup" } 1481 | if len(templs) == 0 { 1482 | attr.Templ = `{{define "Onkeyup"}}onkeyup="{{.}}"{{end}}` 1483 | } else { 1484 | attr.Templ = `{{define "Onkeyup"}}onkeyup="` + strings.Join(templs, " ") + `"{{end}}` 1485 | } 1486 | return attr 1487 | } 1488 | 1489 | func Onkeyup_(values ...string) Attribute { 1490 | return Onkeyup(nil, values...) 1491 | } 1492 | 1493 | 1494 | func Onload(data interface{}, templs ...string) Attribute { 1495 | attr := Attribute{ Data: data, Name: "Onload" } 1496 | if len(templs) == 0 { 1497 | attr.Templ = `{{define "Onload"}}onload="{{.}}"{{end}}` 1498 | } else { 1499 | attr.Templ = `{{define "Onload"}}onload="` + strings.Join(templs, " ") + `"{{end}}` 1500 | } 1501 | return attr 1502 | } 1503 | 1504 | func Onload_(values ...string) Attribute { 1505 | return Onload(nil, values...) 1506 | } 1507 | 1508 | 1509 | func Onloadeddata(data interface{}, templs ...string) Attribute { 1510 | attr := Attribute{ Data: data, Name: "Onloadeddata" } 1511 | if len(templs) == 0 { 1512 | attr.Templ = `{{define "Onloadeddata"}}onloadeddata="{{.}}"{{end}}` 1513 | } else { 1514 | attr.Templ = `{{define "Onloadeddata"}}onloadeddata="` + strings.Join(templs, " ") + `"{{end}}` 1515 | } 1516 | return attr 1517 | } 1518 | 1519 | func Onloadeddata_(values ...string) Attribute { 1520 | return Onloadeddata(nil, values...) 1521 | } 1522 | 1523 | 1524 | func Onloadedmetadata(data interface{}, templs ...string) Attribute { 1525 | attr := Attribute{ Data: data, Name: "Onloadedmetadata" } 1526 | if len(templs) == 0 { 1527 | attr.Templ = `{{define "Onloadedmetadata"}}onloadedmetadata="{{.}}"{{end}}` 1528 | } else { 1529 | attr.Templ = `{{define "Onloadedmetadata"}}onloadedmetadata="` + strings.Join(templs, " ") + `"{{end}}` 1530 | } 1531 | return attr 1532 | } 1533 | 1534 | func Onloadedmetadata_(values ...string) Attribute { 1535 | return Onloadedmetadata(nil, values...) 1536 | } 1537 | 1538 | 1539 | func Onloadstart(data interface{}, templs ...string) Attribute { 1540 | attr := Attribute{ Data: data, Name: "Onloadstart" } 1541 | if len(templs) == 0 { 1542 | attr.Templ = `{{define "Onloadstart"}}onloadstart="{{.}}"{{end}}` 1543 | } else { 1544 | attr.Templ = `{{define "Onloadstart"}}onloadstart="` + strings.Join(templs, " ") + `"{{end}}` 1545 | } 1546 | return attr 1547 | } 1548 | 1549 | func Onloadstart_(values ...string) Attribute { 1550 | return Onloadstart(nil, values...) 1551 | } 1552 | 1553 | 1554 | func Onmousedown(data interface{}, templs ...string) Attribute { 1555 | attr := Attribute{ Data: data, Name: "Onmousedown" } 1556 | if len(templs) == 0 { 1557 | attr.Templ = `{{define "Onmousedown"}}onmousedown="{{.}}"{{end}}` 1558 | } else { 1559 | attr.Templ = `{{define "Onmousedown"}}onmousedown="` + strings.Join(templs, " ") + `"{{end}}` 1560 | } 1561 | return attr 1562 | } 1563 | 1564 | func Onmousedown_(values ...string) Attribute { 1565 | return Onmousedown(nil, values...) 1566 | } 1567 | 1568 | 1569 | func Onmousemove(data interface{}, templs ...string) Attribute { 1570 | attr := Attribute{ Data: data, Name: "Onmousemove" } 1571 | if len(templs) == 0 { 1572 | attr.Templ = `{{define "Onmousemove"}}onmousemove="{{.}}"{{end}}` 1573 | } else { 1574 | attr.Templ = `{{define "Onmousemove"}}onmousemove="` + strings.Join(templs, " ") + `"{{end}}` 1575 | } 1576 | return attr 1577 | } 1578 | 1579 | func Onmousemove_(values ...string) Attribute { 1580 | return Onmousemove(nil, values...) 1581 | } 1582 | 1583 | 1584 | func Onmouseout(data interface{}, templs ...string) Attribute { 1585 | attr := Attribute{ Data: data, Name: "Onmouseout" } 1586 | if len(templs) == 0 { 1587 | attr.Templ = `{{define "Onmouseout"}}onmouseout="{{.}}"{{end}}` 1588 | } else { 1589 | attr.Templ = `{{define "Onmouseout"}}onmouseout="` + strings.Join(templs, " ") + `"{{end}}` 1590 | } 1591 | return attr 1592 | } 1593 | 1594 | func Onmouseout_(values ...string) Attribute { 1595 | return Onmouseout(nil, values...) 1596 | } 1597 | 1598 | 1599 | func Onmouseover(data interface{}, templs ...string) Attribute { 1600 | attr := Attribute{ Data: data, Name: "Onmouseover" } 1601 | if len(templs) == 0 { 1602 | attr.Templ = `{{define "Onmouseover"}}onmouseover="{{.}}"{{end}}` 1603 | } else { 1604 | attr.Templ = `{{define "Onmouseover"}}onmouseover="` + strings.Join(templs, " ") + `"{{end}}` 1605 | } 1606 | return attr 1607 | } 1608 | 1609 | func Onmouseover_(values ...string) Attribute { 1610 | return Onmouseover(nil, values...) 1611 | } 1612 | 1613 | 1614 | func Onmouseup(data interface{}, templs ...string) Attribute { 1615 | attr := Attribute{ Data: data, Name: "Onmouseup" } 1616 | if len(templs) == 0 { 1617 | attr.Templ = `{{define "Onmouseup"}}onmouseup="{{.}}"{{end}}` 1618 | } else { 1619 | attr.Templ = `{{define "Onmouseup"}}onmouseup="` + strings.Join(templs, " ") + `"{{end}}` 1620 | } 1621 | return attr 1622 | } 1623 | 1624 | func Onmouseup_(values ...string) Attribute { 1625 | return Onmouseup(nil, values...) 1626 | } 1627 | 1628 | 1629 | func Onmousewheel(data interface{}, templs ...string) Attribute { 1630 | attr := Attribute{ Data: data, Name: "Onmousewheel" } 1631 | if len(templs) == 0 { 1632 | attr.Templ = `{{define "Onmousewheel"}}onmousewheel="{{.}}"{{end}}` 1633 | } else { 1634 | attr.Templ = `{{define "Onmousewheel"}}onmousewheel="` + strings.Join(templs, " ") + `"{{end}}` 1635 | } 1636 | return attr 1637 | } 1638 | 1639 | func Onmousewheel_(values ...string) Attribute { 1640 | return Onmousewheel(nil, values...) 1641 | } 1642 | 1643 | 1644 | func Onoffline(data interface{}, templs ...string) Attribute { 1645 | attr := Attribute{ Data: data, Name: "Onoffline" } 1646 | if len(templs) == 0 { 1647 | attr.Templ = `{{define "Onoffline"}}onoffline="{{.}}"{{end}}` 1648 | } else { 1649 | attr.Templ = `{{define "Onoffline"}}onoffline="` + strings.Join(templs, " ") + `"{{end}}` 1650 | } 1651 | return attr 1652 | } 1653 | 1654 | func Onoffline_(values ...string) Attribute { 1655 | return Onoffline(nil, values...) 1656 | } 1657 | 1658 | 1659 | func Ononline(data interface{}, templs ...string) Attribute { 1660 | attr := Attribute{ Data: data, Name: "Ononline" } 1661 | if len(templs) == 0 { 1662 | attr.Templ = `{{define "Ononline"}}ononline="{{.}}"{{end}}` 1663 | } else { 1664 | attr.Templ = `{{define "Ononline"}}ononline="` + strings.Join(templs, " ") + `"{{end}}` 1665 | } 1666 | return attr 1667 | } 1668 | 1669 | func Ononline_(values ...string) Attribute { 1670 | return Ononline(nil, values...) 1671 | } 1672 | 1673 | 1674 | func Onpagehide(data interface{}, templs ...string) Attribute { 1675 | attr := Attribute{ Data: data, Name: "Onpagehide" } 1676 | if len(templs) == 0 { 1677 | attr.Templ = `{{define "Onpagehide"}}onpagehide="{{.}}"{{end}}` 1678 | } else { 1679 | attr.Templ = `{{define "Onpagehide"}}onpagehide="` + strings.Join(templs, " ") + `"{{end}}` 1680 | } 1681 | return attr 1682 | } 1683 | 1684 | func Onpagehide_(values ...string) Attribute { 1685 | return Onpagehide(nil, values...) 1686 | } 1687 | 1688 | 1689 | func Onpageshow(data interface{}, templs ...string) Attribute { 1690 | attr := Attribute{ Data: data, Name: "Onpageshow" } 1691 | if len(templs) == 0 { 1692 | attr.Templ = `{{define "Onpageshow"}}onpageshow="{{.}}"{{end}}` 1693 | } else { 1694 | attr.Templ = `{{define "Onpageshow"}}onpageshow="` + strings.Join(templs, " ") + `"{{end}}` 1695 | } 1696 | return attr 1697 | } 1698 | 1699 | func Onpageshow_(values ...string) Attribute { 1700 | return Onpageshow(nil, values...) 1701 | } 1702 | 1703 | 1704 | func Onpaste(data interface{}, templs ...string) Attribute { 1705 | attr := Attribute{ Data: data, Name: "Onpaste" } 1706 | if len(templs) == 0 { 1707 | attr.Templ = `{{define "Onpaste"}}onpaste="{{.}}"{{end}}` 1708 | } else { 1709 | attr.Templ = `{{define "Onpaste"}}onpaste="` + strings.Join(templs, " ") + `"{{end}}` 1710 | } 1711 | return attr 1712 | } 1713 | 1714 | func Onpaste_(values ...string) Attribute { 1715 | return Onpaste(nil, values...) 1716 | } 1717 | 1718 | 1719 | func Onpause(data interface{}, templs ...string) Attribute { 1720 | attr := Attribute{ Data: data, Name: "Onpause" } 1721 | if len(templs) == 0 { 1722 | attr.Templ = `{{define "Onpause"}}onpause="{{.}}"{{end}}` 1723 | } else { 1724 | attr.Templ = `{{define "Onpause"}}onpause="` + strings.Join(templs, " ") + `"{{end}}` 1725 | } 1726 | return attr 1727 | } 1728 | 1729 | func Onpause_(values ...string) Attribute { 1730 | return Onpause(nil, values...) 1731 | } 1732 | 1733 | 1734 | func Onplay(data interface{}, templs ...string) Attribute { 1735 | attr := Attribute{ Data: data, Name: "Onplay" } 1736 | if len(templs) == 0 { 1737 | attr.Templ = `{{define "Onplay"}}onplay="{{.}}"{{end}}` 1738 | } else { 1739 | attr.Templ = `{{define "Onplay"}}onplay="` + strings.Join(templs, " ") + `"{{end}}` 1740 | } 1741 | return attr 1742 | } 1743 | 1744 | func Onplay_(values ...string) Attribute { 1745 | return Onplay(nil, values...) 1746 | } 1747 | 1748 | 1749 | func Onplaying(data interface{}, templs ...string) Attribute { 1750 | attr := Attribute{ Data: data, Name: "Onplaying" } 1751 | if len(templs) == 0 { 1752 | attr.Templ = `{{define "Onplaying"}}onplaying="{{.}}"{{end}}` 1753 | } else { 1754 | attr.Templ = `{{define "Onplaying"}}onplaying="` + strings.Join(templs, " ") + `"{{end}}` 1755 | } 1756 | return attr 1757 | } 1758 | 1759 | func Onplaying_(values ...string) Attribute { 1760 | return Onplaying(nil, values...) 1761 | } 1762 | 1763 | 1764 | func Onpopstate(data interface{}, templs ...string) Attribute { 1765 | attr := Attribute{ Data: data, Name: "Onpopstate" } 1766 | if len(templs) == 0 { 1767 | attr.Templ = `{{define "Onpopstate"}}onpopstate="{{.}}"{{end}}` 1768 | } else { 1769 | attr.Templ = `{{define "Onpopstate"}}onpopstate="` + strings.Join(templs, " ") + `"{{end}}` 1770 | } 1771 | return attr 1772 | } 1773 | 1774 | func Onpopstate_(values ...string) Attribute { 1775 | return Onpopstate(nil, values...) 1776 | } 1777 | 1778 | 1779 | func Onprogress(data interface{}, templs ...string) Attribute { 1780 | attr := Attribute{ Data: data, Name: "Onprogress" } 1781 | if len(templs) == 0 { 1782 | attr.Templ = `{{define "Onprogress"}}onprogress="{{.}}"{{end}}` 1783 | } else { 1784 | attr.Templ = `{{define "Onprogress"}}onprogress="` + strings.Join(templs, " ") + `"{{end}}` 1785 | } 1786 | return attr 1787 | } 1788 | 1789 | func Onprogress_(values ...string) Attribute { 1790 | return Onprogress(nil, values...) 1791 | } 1792 | 1793 | 1794 | func Onratechange(data interface{}, templs ...string) Attribute { 1795 | attr := Attribute{ Data: data, Name: "Onratechange" } 1796 | if len(templs) == 0 { 1797 | attr.Templ = `{{define "Onratechange"}}onratechange="{{.}}"{{end}}` 1798 | } else { 1799 | attr.Templ = `{{define "Onratechange"}}onratechange="` + strings.Join(templs, " ") + `"{{end}}` 1800 | } 1801 | return attr 1802 | } 1803 | 1804 | func Onratechange_(values ...string) Attribute { 1805 | return Onratechange(nil, values...) 1806 | } 1807 | 1808 | 1809 | func Onreset(data interface{}, templs ...string) Attribute { 1810 | attr := Attribute{ Data: data, Name: "Onreset" } 1811 | if len(templs) == 0 { 1812 | attr.Templ = `{{define "Onreset"}}onreset="{{.}}"{{end}}` 1813 | } else { 1814 | attr.Templ = `{{define "Onreset"}}onreset="` + strings.Join(templs, " ") + `"{{end}}` 1815 | } 1816 | return attr 1817 | } 1818 | 1819 | func Onreset_(values ...string) Attribute { 1820 | return Onreset(nil, values...) 1821 | } 1822 | 1823 | 1824 | func Onresize(data interface{}, templs ...string) Attribute { 1825 | attr := Attribute{ Data: data, Name: "Onresize" } 1826 | if len(templs) == 0 { 1827 | attr.Templ = `{{define "Onresize"}}onresize="{{.}}"{{end}}` 1828 | } else { 1829 | attr.Templ = `{{define "Onresize"}}onresize="` + strings.Join(templs, " ") + `"{{end}}` 1830 | } 1831 | return attr 1832 | } 1833 | 1834 | func Onresize_(values ...string) Attribute { 1835 | return Onresize(nil, values...) 1836 | } 1837 | 1838 | 1839 | func Onscroll(data interface{}, templs ...string) Attribute { 1840 | attr := Attribute{ Data: data, Name: "Onscroll" } 1841 | if len(templs) == 0 { 1842 | attr.Templ = `{{define "Onscroll"}}onscroll="{{.}}"{{end}}` 1843 | } else { 1844 | attr.Templ = `{{define "Onscroll"}}onscroll="` + strings.Join(templs, " ") + `"{{end}}` 1845 | } 1846 | return attr 1847 | } 1848 | 1849 | func Onscroll_(values ...string) Attribute { 1850 | return Onscroll(nil, values...) 1851 | } 1852 | 1853 | 1854 | func Onsearch(data interface{}, templs ...string) Attribute { 1855 | attr := Attribute{ Data: data, Name: "Onsearch" } 1856 | if len(templs) == 0 { 1857 | attr.Templ = `{{define "Onsearch"}}onsearch="{{.}}"{{end}}` 1858 | } else { 1859 | attr.Templ = `{{define "Onsearch"}}onsearch="` + strings.Join(templs, " ") + `"{{end}}` 1860 | } 1861 | return attr 1862 | } 1863 | 1864 | func Onsearch_(values ...string) Attribute { 1865 | return Onsearch(nil, values...) 1866 | } 1867 | 1868 | 1869 | func Onseeked(data interface{}, templs ...string) Attribute { 1870 | attr := Attribute{ Data: data, Name: "Onseeked" } 1871 | if len(templs) == 0 { 1872 | attr.Templ = `{{define "Onseeked"}}onseeked="{{.}}"{{end}}` 1873 | } else { 1874 | attr.Templ = `{{define "Onseeked"}}onseeked="` + strings.Join(templs, " ") + `"{{end}}` 1875 | } 1876 | return attr 1877 | } 1878 | 1879 | func Onseeked_(values ...string) Attribute { 1880 | return Onseeked(nil, values...) 1881 | } 1882 | 1883 | 1884 | func Onseeking(data interface{}, templs ...string) Attribute { 1885 | attr := Attribute{ Data: data, Name: "Onseeking" } 1886 | if len(templs) == 0 { 1887 | attr.Templ = `{{define "Onseeking"}}onseeking="{{.}}"{{end}}` 1888 | } else { 1889 | attr.Templ = `{{define "Onseeking"}}onseeking="` + strings.Join(templs, " ") + `"{{end}}` 1890 | } 1891 | return attr 1892 | } 1893 | 1894 | func Onseeking_(values ...string) Attribute { 1895 | return Onseeking(nil, values...) 1896 | } 1897 | 1898 | 1899 | func Onselect(data interface{}, templs ...string) Attribute { 1900 | attr := Attribute{ Data: data, Name: "Onselect" } 1901 | if len(templs) == 0 { 1902 | attr.Templ = `{{define "Onselect"}}onselect="{{.}}"{{end}}` 1903 | } else { 1904 | attr.Templ = `{{define "Onselect"}}onselect="` + strings.Join(templs, " ") + `"{{end}}` 1905 | } 1906 | return attr 1907 | } 1908 | 1909 | func Onselect_(values ...string) Attribute { 1910 | return Onselect(nil, values...) 1911 | } 1912 | 1913 | 1914 | func Onstalled(data interface{}, templs ...string) Attribute { 1915 | attr := Attribute{ Data: data, Name: "Onstalled" } 1916 | if len(templs) == 0 { 1917 | attr.Templ = `{{define "Onstalled"}}onstalled="{{.}}"{{end}}` 1918 | } else { 1919 | attr.Templ = `{{define "Onstalled"}}onstalled="` + strings.Join(templs, " ") + `"{{end}}` 1920 | } 1921 | return attr 1922 | } 1923 | 1924 | func Onstalled_(values ...string) Attribute { 1925 | return Onstalled(nil, values...) 1926 | } 1927 | 1928 | 1929 | func Onstorage(data interface{}, templs ...string) Attribute { 1930 | attr := Attribute{ Data: data, Name: "Onstorage" } 1931 | if len(templs) == 0 { 1932 | attr.Templ = `{{define "Onstorage"}}onstorage="{{.}}"{{end}}` 1933 | } else { 1934 | attr.Templ = `{{define "Onstorage"}}onstorage="` + strings.Join(templs, " ") + `"{{end}}` 1935 | } 1936 | return attr 1937 | } 1938 | 1939 | func Onstorage_(values ...string) Attribute { 1940 | return Onstorage(nil, values...) 1941 | } 1942 | 1943 | 1944 | func Onsubmit(data interface{}, templs ...string) Attribute { 1945 | attr := Attribute{ Data: data, Name: "Onsubmit" } 1946 | if len(templs) == 0 { 1947 | attr.Templ = `{{define "Onsubmit"}}onsubmit="{{.}}"{{end}}` 1948 | } else { 1949 | attr.Templ = `{{define "Onsubmit"}}onsubmit="` + strings.Join(templs, " ") + `"{{end}}` 1950 | } 1951 | return attr 1952 | } 1953 | 1954 | func Onsubmit_(values ...string) Attribute { 1955 | return Onsubmit(nil, values...) 1956 | } 1957 | 1958 | 1959 | func Onsuspend(data interface{}, templs ...string) Attribute { 1960 | attr := Attribute{ Data: data, Name: "Onsuspend" } 1961 | if len(templs) == 0 { 1962 | attr.Templ = `{{define "Onsuspend"}}onsuspend="{{.}}"{{end}}` 1963 | } else { 1964 | attr.Templ = `{{define "Onsuspend"}}onsuspend="` + strings.Join(templs, " ") + `"{{end}}` 1965 | } 1966 | return attr 1967 | } 1968 | 1969 | func Onsuspend_(values ...string) Attribute { 1970 | return Onsuspend(nil, values...) 1971 | } 1972 | 1973 | 1974 | func Ontimeupdate(data interface{}, templs ...string) Attribute { 1975 | attr := Attribute{ Data: data, Name: "Ontimeupdate" } 1976 | if len(templs) == 0 { 1977 | attr.Templ = `{{define "Ontimeupdate"}}ontimeupdate="{{.}}"{{end}}` 1978 | } else { 1979 | attr.Templ = `{{define "Ontimeupdate"}}ontimeupdate="` + strings.Join(templs, " ") + `"{{end}}` 1980 | } 1981 | return attr 1982 | } 1983 | 1984 | func Ontimeupdate_(values ...string) Attribute { 1985 | return Ontimeupdate(nil, values...) 1986 | } 1987 | 1988 | 1989 | func Ontoggle(data interface{}, templs ...string) Attribute { 1990 | attr := Attribute{ Data: data, Name: "Ontoggle" } 1991 | if len(templs) == 0 { 1992 | attr.Templ = `{{define "Ontoggle"}}ontoggle="{{.}}"{{end}}` 1993 | } else { 1994 | attr.Templ = `{{define "Ontoggle"}}ontoggle="` + strings.Join(templs, " ") + `"{{end}}` 1995 | } 1996 | return attr 1997 | } 1998 | 1999 | func Ontoggle_(values ...string) Attribute { 2000 | return Ontoggle(nil, values...) 2001 | } 2002 | 2003 | 2004 | func Onunload(data interface{}, templs ...string) Attribute { 2005 | attr := Attribute{ Data: data, Name: "Onunload" } 2006 | if len(templs) == 0 { 2007 | attr.Templ = `{{define "Onunload"}}onunload="{{.}}"{{end}}` 2008 | } else { 2009 | attr.Templ = `{{define "Onunload"}}onunload="` + strings.Join(templs, " ") + `"{{end}}` 2010 | } 2011 | return attr 2012 | } 2013 | 2014 | func Onunload_(values ...string) Attribute { 2015 | return Onunload(nil, values...) 2016 | } 2017 | 2018 | 2019 | func Onvolumechange(data interface{}, templs ...string) Attribute { 2020 | attr := Attribute{ Data: data, Name: "Onvolumechange" } 2021 | if len(templs) == 0 { 2022 | attr.Templ = `{{define "Onvolumechange"}}onvolumechange="{{.}}"{{end}}` 2023 | } else { 2024 | attr.Templ = `{{define "Onvolumechange"}}onvolumechange="` + strings.Join(templs, " ") + `"{{end}}` 2025 | } 2026 | return attr 2027 | } 2028 | 2029 | func Onvolumechange_(values ...string) Attribute { 2030 | return Onvolumechange(nil, values...) 2031 | } 2032 | 2033 | 2034 | func Onwaiting(data interface{}, templs ...string) Attribute { 2035 | attr := Attribute{ Data: data, Name: "Onwaiting" } 2036 | if len(templs) == 0 { 2037 | attr.Templ = `{{define "Onwaiting"}}onwaiting="{{.}}"{{end}}` 2038 | } else { 2039 | attr.Templ = `{{define "Onwaiting"}}onwaiting="` + strings.Join(templs, " ") + `"{{end}}` 2040 | } 2041 | return attr 2042 | } 2043 | 2044 | func Onwaiting_(values ...string) Attribute { 2045 | return Onwaiting(nil, values...) 2046 | } 2047 | 2048 | 2049 | func Onwheel(data interface{}, templs ...string) Attribute { 2050 | attr := Attribute{ Data: data, Name: "Onwheel" } 2051 | if len(templs) == 0 { 2052 | attr.Templ = `{{define "Onwheel"}}onwheel="{{.}}"{{end}}` 2053 | } else { 2054 | attr.Templ = `{{define "Onwheel"}}onwheel="` + strings.Join(templs, " ") + `"{{end}}` 2055 | } 2056 | return attr 2057 | } 2058 | 2059 | func Onwheel_(values ...string) Attribute { 2060 | return Onwheel(nil, values...) 2061 | } 2062 | 2063 | 2064 | func Open(data interface{}, templs ...string) Attribute { 2065 | attr := Attribute{ Data: data, Name: "Open" } 2066 | if len(templs) == 0 { 2067 | attr.Templ = `{{define "Open"}}open="{{.}}"{{end}}` 2068 | } else { 2069 | attr.Templ = `{{define "Open"}}open="` + strings.Join(templs, " ") + `"{{end}}` 2070 | } 2071 | return attr 2072 | } 2073 | 2074 | func Open_(values ...string) Attribute { 2075 | return Open(nil, values...) 2076 | } 2077 | 2078 | 2079 | func Optimum(data interface{}, templs ...string) Attribute { 2080 | attr := Attribute{ Data: data, Name: "Optimum" } 2081 | if len(templs) == 0 { 2082 | attr.Templ = `{{define "Optimum"}}optimum="{{.}}"{{end}}` 2083 | } else { 2084 | attr.Templ = `{{define "Optimum"}}optimum="` + strings.Join(templs, " ") + `"{{end}}` 2085 | } 2086 | return attr 2087 | } 2088 | 2089 | func Optimum_(values ...string) Attribute { 2090 | return Optimum(nil, values...) 2091 | } 2092 | 2093 | 2094 | func Pattern(data interface{}, templs ...string) Attribute { 2095 | attr := Attribute{ Data: data, Name: "Pattern" } 2096 | if len(templs) == 0 { 2097 | attr.Templ = `{{define "Pattern"}}pattern="{{.}}"{{end}}` 2098 | } else { 2099 | attr.Templ = `{{define "Pattern"}}pattern="` + strings.Join(templs, " ") + `"{{end}}` 2100 | } 2101 | return attr 2102 | } 2103 | 2104 | func Pattern_(values ...string) Attribute { 2105 | return Pattern(nil, values...) 2106 | } 2107 | 2108 | 2109 | func Placeholder(data interface{}, templs ...string) Attribute { 2110 | attr := Attribute{ Data: data, Name: "Placeholder" } 2111 | if len(templs) == 0 { 2112 | attr.Templ = `{{define "Placeholder"}}placeholder="{{.}}"{{end}}` 2113 | } else { 2114 | attr.Templ = `{{define "Placeholder"}}placeholder="` + strings.Join(templs, " ") + `"{{end}}` 2115 | } 2116 | return attr 2117 | } 2118 | 2119 | func Placeholder_(values ...string) Attribute { 2120 | return Placeholder(nil, values...) 2121 | } 2122 | 2123 | 2124 | func Poster(data interface{}, templs ...string) Attribute { 2125 | attr := Attribute{ Data: data, Name: "Poster" } 2126 | if len(templs) == 0 { 2127 | attr.Templ = `{{define "Poster"}}poster="{{.}}"{{end}}` 2128 | } else { 2129 | attr.Templ = `{{define "Poster"}}poster="` + strings.Join(templs, " ") + `"{{end}}` 2130 | } 2131 | return attr 2132 | } 2133 | 2134 | func Poster_(values ...string) Attribute { 2135 | return Poster(nil, values...) 2136 | } 2137 | 2138 | 2139 | func Preload(data interface{}, templs ...string) Attribute { 2140 | attr := Attribute{ Data: data, Name: "Preload" } 2141 | if len(templs) == 0 { 2142 | attr.Templ = `{{define "Preload"}}preload="{{.}}"{{end}}` 2143 | } else { 2144 | attr.Templ = `{{define "Preload"}}preload="` + strings.Join(templs, " ") + `"{{end}}` 2145 | } 2146 | return attr 2147 | } 2148 | 2149 | func Preload_(values ...string) Attribute { 2150 | return Preload(nil, values...) 2151 | } 2152 | 2153 | 2154 | func Readonly(data interface{}, templs ...string) Attribute { 2155 | attr := Attribute{ Data: data, Name: "Readonly" } 2156 | if len(templs) == 0 { 2157 | attr.Templ = `{{define "Readonly"}}readonly="{{.}}"{{end}}` 2158 | } else { 2159 | attr.Templ = `{{define "Readonly"}}readonly="` + strings.Join(templs, " ") + `"{{end}}` 2160 | } 2161 | return attr 2162 | } 2163 | 2164 | func Readonly_(values ...string) Attribute { 2165 | return Readonly(nil, values...) 2166 | } 2167 | 2168 | 2169 | func Rel(data interface{}, templs ...string) Attribute { 2170 | attr := Attribute{ Data: data, Name: "Rel" } 2171 | if len(templs) == 0 { 2172 | attr.Templ = `{{define "Rel"}}rel="{{.}}"{{end}}` 2173 | } else { 2174 | attr.Templ = `{{define "Rel"}}rel="` + strings.Join(templs, " ") + `"{{end}}` 2175 | } 2176 | return attr 2177 | } 2178 | 2179 | func Rel_(values ...string) Attribute { 2180 | return Rel(nil, values...) 2181 | } 2182 | 2183 | 2184 | func Required(data interface{}, templs ...string) Attribute { 2185 | attr := Attribute{ Data: data, Name: "Required" } 2186 | if len(templs) == 0 { 2187 | attr.Templ = `{{define "Required"}}required="{{.}}"{{end}}` 2188 | } else { 2189 | attr.Templ = `{{define "Required"}}required="` + strings.Join(templs, " ") + `"{{end}}` 2190 | } 2191 | return attr 2192 | } 2193 | 2194 | func Required_(values ...string) Attribute { 2195 | return Required(nil, values...) 2196 | } 2197 | 2198 | 2199 | func Reversed(data interface{}, templs ...string) Attribute { 2200 | attr := Attribute{ Data: data, Name: "Reversed" } 2201 | if len(templs) == 0 { 2202 | attr.Templ = `{{define "Reversed"}}reversed="{{.}}"{{end}}` 2203 | } else { 2204 | attr.Templ = `{{define "Reversed"}}reversed="` + strings.Join(templs, " ") + `"{{end}}` 2205 | } 2206 | return attr 2207 | } 2208 | 2209 | func Reversed_(values ...string) Attribute { 2210 | return Reversed(nil, values...) 2211 | } 2212 | 2213 | 2214 | func Role(data interface{}, templs ...string) Attribute { 2215 | attr := Attribute{ Data: data, Name: "Role" } 2216 | if len(templs) == 0 { 2217 | attr.Templ = `{{define "Role"}}role="{{.}}"{{end}}` 2218 | } else { 2219 | attr.Templ = `{{define "Role"}}role="` + strings.Join(templs, " ") + `"{{end}}` 2220 | } 2221 | return attr 2222 | } 2223 | 2224 | func Role_(values ...string) Attribute { 2225 | return Role(nil, values...) 2226 | } 2227 | 2228 | 2229 | func Rows(data interface{}, templs ...string) Attribute { 2230 | attr := Attribute{ Data: data, Name: "Rows" } 2231 | if len(templs) == 0 { 2232 | attr.Templ = `{{define "Rows"}}rows="{{.}}"{{end}}` 2233 | } else { 2234 | attr.Templ = `{{define "Rows"}}rows="` + strings.Join(templs, " ") + `"{{end}}` 2235 | } 2236 | return attr 2237 | } 2238 | 2239 | func Rows_(values ...string) Attribute { 2240 | return Rows(nil, values...) 2241 | } 2242 | 2243 | 2244 | func Rowspan(data interface{}, templs ...string) Attribute { 2245 | attr := Attribute{ Data: data, Name: "Rowspan" } 2246 | if len(templs) == 0 { 2247 | attr.Templ = `{{define "Rowspan"}}rowspan="{{.}}"{{end}}` 2248 | } else { 2249 | attr.Templ = `{{define "Rowspan"}}rowspan="` + strings.Join(templs, " ") + `"{{end}}` 2250 | } 2251 | return attr 2252 | } 2253 | 2254 | func Rowspan_(values ...string) Attribute { 2255 | return Rowspan(nil, values...) 2256 | } 2257 | 2258 | 2259 | func Sandbox(data interface{}, templs ...string) Attribute { 2260 | attr := Attribute{ Data: data, Name: "Sandbox" } 2261 | if len(templs) == 0 { 2262 | attr.Templ = `{{define "Sandbox"}}sandbox="{{.}}"{{end}}` 2263 | } else { 2264 | attr.Templ = `{{define "Sandbox"}}sandbox="` + strings.Join(templs, " ") + `"{{end}}` 2265 | } 2266 | return attr 2267 | } 2268 | 2269 | func Sandbox_(values ...string) Attribute { 2270 | return Sandbox(nil, values...) 2271 | } 2272 | 2273 | 2274 | func Scope(data interface{}, templs ...string) Attribute { 2275 | attr := Attribute{ Data: data, Name: "Scope" } 2276 | if len(templs) == 0 { 2277 | attr.Templ = `{{define "Scope"}}scope="{{.}}"{{end}}` 2278 | } else { 2279 | attr.Templ = `{{define "Scope"}}scope="` + strings.Join(templs, " ") + `"{{end}}` 2280 | } 2281 | return attr 2282 | } 2283 | 2284 | func Scope_(values ...string) Attribute { 2285 | return Scope(nil, values...) 2286 | } 2287 | 2288 | 2289 | func Selected(data interface{}, templs ...string) Attribute { 2290 | attr := Attribute{ Data: data, Name: "Selected" } 2291 | if len(templs) == 0 { 2292 | attr.Templ = `{{define "Selected"}}selected="{{.}}"{{end}}` 2293 | } else { 2294 | attr.Templ = `{{define "Selected"}}selected="` + strings.Join(templs, " ") + `"{{end}}` 2295 | } 2296 | return attr 2297 | } 2298 | 2299 | func Selected_(values ...string) Attribute { 2300 | return Selected(nil, values...) 2301 | } 2302 | 2303 | 2304 | func Shape(data interface{}, templs ...string) Attribute { 2305 | attr := Attribute{ Data: data, Name: "Shape" } 2306 | if len(templs) == 0 { 2307 | attr.Templ = `{{define "Shape"}}shape="{{.}}"{{end}}` 2308 | } else { 2309 | attr.Templ = `{{define "Shape"}}shape="` + strings.Join(templs, " ") + `"{{end}}` 2310 | } 2311 | return attr 2312 | } 2313 | 2314 | func Shape_(values ...string) Attribute { 2315 | return Shape(nil, values...) 2316 | } 2317 | 2318 | 2319 | func Size(data interface{}, templs ...string) Attribute { 2320 | attr := Attribute{ Data: data, Name: "Size" } 2321 | if len(templs) == 0 { 2322 | attr.Templ = `{{define "Size"}}size="{{.}}"{{end}}` 2323 | } else { 2324 | attr.Templ = `{{define "Size"}}size="` + strings.Join(templs, " ") + `"{{end}}` 2325 | } 2326 | return attr 2327 | } 2328 | 2329 | func Size_(values ...string) Attribute { 2330 | return Size(nil, values...) 2331 | } 2332 | 2333 | 2334 | func Sizes(data interface{}, templs ...string) Attribute { 2335 | attr := Attribute{ Data: data, Name: "Sizes" } 2336 | if len(templs) == 0 { 2337 | attr.Templ = `{{define "Sizes"}}sizes="{{.}}"{{end}}` 2338 | } else { 2339 | attr.Templ = `{{define "Sizes"}}sizes="` + strings.Join(templs, " ") + `"{{end}}` 2340 | } 2341 | return attr 2342 | } 2343 | 2344 | func Sizes_(values ...string) Attribute { 2345 | return Sizes(nil, values...) 2346 | } 2347 | 2348 | 2349 | func Span(data interface{}, templs ...string) Attribute { 2350 | attr := Attribute{ Data: data, Name: "Span" } 2351 | if len(templs) == 0 { 2352 | attr.Templ = `{{define "Span"}}span="{{.}}"{{end}}` 2353 | } else { 2354 | attr.Templ = `{{define "Span"}}span="` + strings.Join(templs, " ") + `"{{end}}` 2355 | } 2356 | return attr 2357 | } 2358 | 2359 | func Span_(values ...string) Attribute { 2360 | return Span(nil, values...) 2361 | } 2362 | 2363 | 2364 | func Spellcheck(data interface{}, templs ...string) Attribute { 2365 | attr := Attribute{ Data: data, Name: "Spellcheck" } 2366 | if len(templs) == 0 { 2367 | attr.Templ = `{{define "Spellcheck"}}spellcheck="{{.}}"{{end}}` 2368 | } else { 2369 | attr.Templ = `{{define "Spellcheck"}}spellcheck="` + strings.Join(templs, " ") + `"{{end}}` 2370 | } 2371 | return attr 2372 | } 2373 | 2374 | func Spellcheck_(values ...string) Attribute { 2375 | return Spellcheck(nil, values...) 2376 | } 2377 | 2378 | 2379 | func Src(data interface{}, templs ...string) Attribute { 2380 | attr := Attribute{ Data: data, Name: "Src" } 2381 | if len(templs) == 0 { 2382 | attr.Templ = `{{define "Src"}}src="{{.}}"{{end}}` 2383 | } else { 2384 | attr.Templ = `{{define "Src"}}src="` + strings.Join(templs, " ") + `"{{end}}` 2385 | } 2386 | return attr 2387 | } 2388 | 2389 | func Src_(values ...string) Attribute { 2390 | return Src(nil, values...) 2391 | } 2392 | 2393 | 2394 | func Srcdoc(data interface{}, templs ...string) Attribute { 2395 | attr := Attribute{ Data: data, Name: "Srcdoc" } 2396 | if len(templs) == 0 { 2397 | attr.Templ = `{{define "Srcdoc"}}srcdoc="{{.}}"{{end}}` 2398 | } else { 2399 | attr.Templ = `{{define "Srcdoc"}}srcdoc="` + strings.Join(templs, " ") + `"{{end}}` 2400 | } 2401 | return attr 2402 | } 2403 | 2404 | func Srcdoc_(values ...string) Attribute { 2405 | return Srcdoc(nil, values...) 2406 | } 2407 | 2408 | 2409 | func Srclang(data interface{}, templs ...string) Attribute { 2410 | attr := Attribute{ Data: data, Name: "Srclang" } 2411 | if len(templs) == 0 { 2412 | attr.Templ = `{{define "Srclang"}}srclang="{{.}}"{{end}}` 2413 | } else { 2414 | attr.Templ = `{{define "Srclang"}}srclang="` + strings.Join(templs, " ") + `"{{end}}` 2415 | } 2416 | return attr 2417 | } 2418 | 2419 | func Srclang_(values ...string) Attribute { 2420 | return Srclang(nil, values...) 2421 | } 2422 | 2423 | 2424 | func Srcset(data interface{}, templs ...string) Attribute { 2425 | attr := Attribute{ Data: data, Name: "Srcset" } 2426 | if len(templs) == 0 { 2427 | attr.Templ = `{{define "Srcset"}}srcset="{{.}}"{{end}}` 2428 | } else { 2429 | attr.Templ = `{{define "Srcset"}}srcset="` + strings.Join(templs, " ") + `"{{end}}` 2430 | } 2431 | return attr 2432 | } 2433 | 2434 | func Srcset_(values ...string) Attribute { 2435 | return Srcset(nil, values...) 2436 | } 2437 | 2438 | 2439 | func Start(data interface{}, templs ...string) Attribute { 2440 | attr := Attribute{ Data: data, Name: "Start" } 2441 | if len(templs) == 0 { 2442 | attr.Templ = `{{define "Start"}}start="{{.}}"{{end}}` 2443 | } else { 2444 | attr.Templ = `{{define "Start"}}start="` + strings.Join(templs, " ") + `"{{end}}` 2445 | } 2446 | return attr 2447 | } 2448 | 2449 | func Start_(values ...string) Attribute { 2450 | return Start(nil, values...) 2451 | } 2452 | 2453 | 2454 | func Step(data interface{}, templs ...string) Attribute { 2455 | attr := Attribute{ Data: data, Name: "Step" } 2456 | if len(templs) == 0 { 2457 | attr.Templ = `{{define "Step"}}step="{{.}}"{{end}}` 2458 | } else { 2459 | attr.Templ = `{{define "Step"}}step="` + strings.Join(templs, " ") + `"{{end}}` 2460 | } 2461 | return attr 2462 | } 2463 | 2464 | func Step_(values ...string) Attribute { 2465 | return Step(nil, values...) 2466 | } 2467 | 2468 | 2469 | func Style(data interface{}, templs ...string) Attribute { 2470 | attr := Attribute{ Data: data, Name: "Style" } 2471 | if len(templs) == 0 { 2472 | attr.Templ = `{{define "Style"}}style="{{.}}"{{end}}` 2473 | } else { 2474 | attr.Templ = `{{define "Style"}}style="` + strings.Join(templs, " ") + `"{{end}}` 2475 | } 2476 | return attr 2477 | } 2478 | 2479 | func Style_(values ...string) Attribute { 2480 | return Style(nil, values...) 2481 | } 2482 | 2483 | 2484 | func Tabindex(data interface{}, templs ...string) Attribute { 2485 | attr := Attribute{ Data: data, Name: "Tabindex" } 2486 | if len(templs) == 0 { 2487 | attr.Templ = `{{define "Tabindex"}}tabindex="{{.}}"{{end}}` 2488 | } else { 2489 | attr.Templ = `{{define "Tabindex"}}tabindex="` + strings.Join(templs, " ") + `"{{end}}` 2490 | } 2491 | return attr 2492 | } 2493 | 2494 | func Tabindex_(values ...string) Attribute { 2495 | return Tabindex(nil, values...) 2496 | } 2497 | 2498 | 2499 | func Target(data interface{}, templs ...string) Attribute { 2500 | attr := Attribute{ Data: data, Name: "Target" } 2501 | if len(templs) == 0 { 2502 | attr.Templ = `{{define "Target"}}target="{{.}}"{{end}}` 2503 | } else { 2504 | attr.Templ = `{{define "Target"}}target="` + strings.Join(templs, " ") + `"{{end}}` 2505 | } 2506 | return attr 2507 | } 2508 | 2509 | func Target_(values ...string) Attribute { 2510 | return Target(nil, values...) 2511 | } 2512 | 2513 | 2514 | func Title(data interface{}, templs ...string) Attribute { 2515 | attr := Attribute{ Data: data, Name: "Title" } 2516 | if len(templs) == 0 { 2517 | attr.Templ = `{{define "Title"}}title="{{.}}"{{end}}` 2518 | } else { 2519 | attr.Templ = `{{define "Title"}}title="` + strings.Join(templs, " ") + `"{{end}}` 2520 | } 2521 | return attr 2522 | } 2523 | 2524 | func Title_(values ...string) Attribute { 2525 | return Title(nil, values...) 2526 | } 2527 | 2528 | 2529 | func Translate(data interface{}, templs ...string) Attribute { 2530 | attr := Attribute{ Data: data, Name: "Translate" } 2531 | if len(templs) == 0 { 2532 | attr.Templ = `{{define "Translate"}}translate="{{.}}"{{end}}` 2533 | } else { 2534 | attr.Templ = `{{define "Translate"}}translate="` + strings.Join(templs, " ") + `"{{end}}` 2535 | } 2536 | return attr 2537 | } 2538 | 2539 | func Translate_(values ...string) Attribute { 2540 | return Translate(nil, values...) 2541 | } 2542 | 2543 | 2544 | func Type(data interface{}, templs ...string) Attribute { 2545 | attr := Attribute{ Data: data, Name: "Type" } 2546 | if len(templs) == 0 { 2547 | attr.Templ = `{{define "Type"}}type="{{.}}"{{end}}` 2548 | } else { 2549 | attr.Templ = `{{define "Type"}}type="` + strings.Join(templs, " ") + `"{{end}}` 2550 | } 2551 | return attr 2552 | } 2553 | 2554 | func Type_(values ...string) Attribute { 2555 | return Type(nil, values...) 2556 | } 2557 | 2558 | 2559 | func Usemap(data interface{}, templs ...string) Attribute { 2560 | attr := Attribute{ Data: data, Name: "Usemap" } 2561 | if len(templs) == 0 { 2562 | attr.Templ = `{{define "Usemap"}}usemap="{{.}}"{{end}}` 2563 | } else { 2564 | attr.Templ = `{{define "Usemap"}}usemap="` + strings.Join(templs, " ") + `"{{end}}` 2565 | } 2566 | return attr 2567 | } 2568 | 2569 | func Usemap_(values ...string) Attribute { 2570 | return Usemap(nil, values...) 2571 | } 2572 | 2573 | 2574 | func Value(data interface{}, templs ...string) Attribute { 2575 | attr := Attribute{ Data: data, Name: "Value" } 2576 | if len(templs) == 0 { 2577 | attr.Templ = `{{define "Value"}}value="{{.}}"{{end}}` 2578 | } else { 2579 | attr.Templ = `{{define "Value"}}value="` + strings.Join(templs, " ") + `"{{end}}` 2580 | } 2581 | return attr 2582 | } 2583 | 2584 | func Value_(values ...string) Attribute { 2585 | return Value(nil, values...) 2586 | } 2587 | 2588 | 2589 | func Width(data interface{}, templs ...string) Attribute { 2590 | attr := Attribute{ Data: data, Name: "Width" } 2591 | if len(templs) == 0 { 2592 | attr.Templ = `{{define "Width"}}width="{{.}}"{{end}}` 2593 | } else { 2594 | attr.Templ = `{{define "Width"}}width="` + strings.Join(templs, " ") + `"{{end}}` 2595 | } 2596 | return attr 2597 | } 2598 | 2599 | func Width_(values ...string) Attribute { 2600 | return Width(nil, values...) 2601 | } 2602 | 2603 | 2604 | func Wrap(data interface{}, templs ...string) Attribute { 2605 | attr := Attribute{ Data: data, Name: "Wrap" } 2606 | if len(templs) == 0 { 2607 | attr.Templ = `{{define "Wrap"}}wrap="{{.}}"{{end}}` 2608 | } else { 2609 | attr.Templ = `{{define "Wrap"}}wrap="` + strings.Join(templs, " ") + `"{{end}}` 2610 | } 2611 | return attr 2612 | } 2613 | 2614 | func Wrap_(values ...string) Attribute { 2615 | return Wrap(nil, values...) 2616 | } 2617 | 2618 | -------------------------------------------------------------------------------- /elements.go: -------------------------------------------------------------------------------- 1 | package htmlgo 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "strings" 7 | "html" 8 | "html/template" 9 | "bytes" 10 | 11 | a "github.com/julvo/htmlgo/attributes" 12 | ) 13 | 14 | type HTML string 15 | 16 | type JS struct { 17 | templ string 18 | data interface{} 19 | } 20 | 21 | func WriteTo(w io.Writer, h HTML) { 22 | w.Write([]byte(h)) 23 | } 24 | 25 | // Build a slice of type []Attribute for cosmetic purposes 26 | func Attr(attrs ...a.Attribute) []a.Attribute { 27 | return attrs 28 | } 29 | 30 | func prepareAttributes(attrs []a.Attribute) (string, string, map[string]interface{}) { 31 | data := map[string]interface{}{} 32 | templ := "" 33 | defs := "" 34 | 35 | for _, attr := range attrs { 36 | data[attr.Name] = attr.Data 37 | templ += ` {{template "` + attr.Name + `" .` + attr.Name + `}}` 38 | defs += attr.Templ 39 | } 40 | 41 | return templ, defs, data 42 | } 43 | 44 | func insertChildren(children ...HTML) string { 45 | s := "" 46 | for _, c := range children { 47 | s += string(c) 48 | } 49 | return s 50 | } 51 | 52 | func indent(s, indentation string) string { 53 | return strings.Replace(s, "\n", "\n" + indentation, -1) 54 | } 55 | 56 | func buildElement(tag string, attrs []a.Attribute, content string, close_ bool) string { 57 | templ, defs, data := prepareAttributes(attrs) 58 | complTempl := defs + "\n<" + tag + templ + ">" + content 59 | if close_ { 60 | complTempl += "\n" 61 | } 62 | 63 | t, _ := template.New(tag).Parse(complTempl) 64 | 65 | buf := new(bytes.Buffer) 66 | _ = t.Execute(buf, data) 67 | return buf.String() 68 | } 69 | 70 | func Element(tag string, attrs []a.Attribute, children ...HTML) HTML { 71 | return HTML(buildElement(tag, attrs, 72 | indent(insertChildren(children...), " "), true)) 73 | } 74 | 75 | func VoidElement(tag string, attrs []a.Attribute) HTML { 76 | return HTML(buildElement(tag, attrs, "", false)) 77 | } 78 | 79 | // Produce HTML from plain text by escaping 80 | func Text(v interface{}) HTML { 81 | return HTML("\n" + html.EscapeString(fmt.Sprint(v))) 82 | } 83 | 84 | func Text_(s string) HTML { 85 | return HTML(s) 86 | } 87 | 88 | // Begin of manually defined elements 89 | 90 | func Html5(attrs []a.Attribute, children ...HTML) HTML { 91 | return DoctypeHtml5 + Html(attrs, children...) 92 | } 93 | 94 | func Html5_(children ...HTML) HTML { 95 | return Html5(Attr(), children...) 96 | } 97 | 98 | func Doctype(t string) HTML { 99 | return HTML("") 100 | } 101 | 102 | const DoctypeHtml5 HTML = "" 103 | 104 | func Script(attrs []a.Attribute, js JS) HTML { 105 | if js.data == nil { 106 | return Element("script", attrs, HTML("\n" + js.templ)) 107 | } 108 | 109 | complTempl := buildElement("script", attrs, 110 | indent("\n" + js.templ, " "), true) 111 | 112 | // TODO set verbosity level to enable logging 113 | t, err := template.New("_").Delims("{%$", "$%}").Parse(complTempl) 114 | if err != nil { 115 | return Element("script", attrs) 116 | } 117 | 118 | buf := new(bytes.Buffer) 119 | err = t.Execute(buf, js.data) 120 | if err != nil { 121 | return Element("script", attrs) 122 | } 123 | 124 | return HTML(buf.String()) 125 | } 126 | 127 | func Script_(js JS) HTML { 128 | return Script(Attr(), js) 129 | } 130 | 131 | func JavaScript(data interface{}, templs ...string) JS { 132 | js := JS{ data: data } 133 | if len(templs) == 0 { 134 | js.templ = "{%$.$%}" 135 | } else { 136 | js.templ = strings.Replace( 137 | strings.Replace( 138 | strings.Join(templs, "\n"), 139 | "{{", "{%$", -1), 140 | "}}", "$%}", -1) 141 | } 142 | return js 143 | } 144 | 145 | func JavaScript_(templs ...string) JS { 146 | return JavaScript(nil, templs...) 147 | } 148 | 149 | // Begin of generated elements 150 | 151 | 152 | func A(attrs []a.Attribute, children ...HTML) HTML { 153 | return Element("a", attrs, children...) 154 | } 155 | 156 | func A_(children ...HTML) HTML { 157 | return A(Attr(), children...) 158 | } 159 | 160 | func Abbr(attrs []a.Attribute, children ...HTML) HTML { 161 | return Element("abbr", attrs, children...) 162 | } 163 | 164 | func Abbr_(children ...HTML) HTML { 165 | return Abbr(Attr(), children...) 166 | } 167 | 168 | func Acronym(attrs []a.Attribute, children ...HTML) HTML { 169 | return Element("acronym", attrs, children...) 170 | } 171 | 172 | func Acronym_(children ...HTML) HTML { 173 | return Acronym(Attr(), children...) 174 | } 175 | 176 | func Address(attrs []a.Attribute, children ...HTML) HTML { 177 | return Element("address", attrs, children...) 178 | } 179 | 180 | func Address_(children ...HTML) HTML { 181 | return Address(Attr(), children...) 182 | } 183 | 184 | func Applet(attrs []a.Attribute, children ...HTML) HTML { 185 | return Element("applet", attrs, children...) 186 | } 187 | 188 | func Applet_(children ...HTML) HTML { 189 | return Applet(Attr(), children...) 190 | } 191 | 192 | func Article(attrs []a.Attribute, children ...HTML) HTML { 193 | return Element("article", attrs, children...) 194 | } 195 | 196 | func Article_(children ...HTML) HTML { 197 | return Article(Attr(), children...) 198 | } 199 | 200 | func Aside(attrs []a.Attribute, children ...HTML) HTML { 201 | return Element("aside", attrs, children...) 202 | } 203 | 204 | func Aside_(children ...HTML) HTML { 205 | return Aside(Attr(), children...) 206 | } 207 | 208 | func Audio(attrs []a.Attribute, children ...HTML) HTML { 209 | return Element("audio", attrs, children...) 210 | } 211 | 212 | func Audio_(children ...HTML) HTML { 213 | return Audio(Attr(), children...) 214 | } 215 | 216 | func B(attrs []a.Attribute, children ...HTML) HTML { 217 | return Element("b", attrs, children...) 218 | } 219 | 220 | func B_(children ...HTML) HTML { 221 | return B(Attr(), children...) 222 | } 223 | 224 | func Basefont(attrs []a.Attribute, children ...HTML) HTML { 225 | return Element("basefont", attrs, children...) 226 | } 227 | 228 | func Basefont_(children ...HTML) HTML { 229 | return Basefont(Attr(), children...) 230 | } 231 | 232 | func Bdi(attrs []a.Attribute, children ...HTML) HTML { 233 | return Element("bdi", attrs, children...) 234 | } 235 | 236 | func Bdi_(children ...HTML) HTML { 237 | return Bdi(Attr(), children...) 238 | } 239 | 240 | func Bdo(attrs []a.Attribute, children ...HTML) HTML { 241 | return Element("bdo", attrs, children...) 242 | } 243 | 244 | func Bdo_(children ...HTML) HTML { 245 | return Bdo(Attr(), children...) 246 | } 247 | 248 | func Bgsound(attrs []a.Attribute, children ...HTML) HTML { 249 | return Element("bgsound", attrs, children...) 250 | } 251 | 252 | func Bgsound_(children ...HTML) HTML { 253 | return Bgsound(Attr(), children...) 254 | } 255 | 256 | func Big(attrs []a.Attribute, children ...HTML) HTML { 257 | return Element("big", attrs, children...) 258 | } 259 | 260 | func Big_(children ...HTML) HTML { 261 | return Big(Attr(), children...) 262 | } 263 | 264 | func Blink(attrs []a.Attribute, children ...HTML) HTML { 265 | return Element("blink", attrs, children...) 266 | } 267 | 268 | func Blink_(children ...HTML) HTML { 269 | return Blink(Attr(), children...) 270 | } 271 | 272 | func Blockquote(attrs []a.Attribute, children ...HTML) HTML { 273 | return Element("blockquote", attrs, children...) 274 | } 275 | 276 | func Blockquote_(children ...HTML) HTML { 277 | return Blockquote(Attr(), children...) 278 | } 279 | 280 | func Body(attrs []a.Attribute, children ...HTML) HTML { 281 | return Element("body", attrs, children...) 282 | } 283 | 284 | func Body_(children ...HTML) HTML { 285 | return Body(Attr(), children...) 286 | } 287 | 288 | func Button(attrs []a.Attribute, children ...HTML) HTML { 289 | return Element("button", attrs, children...) 290 | } 291 | 292 | func Button_(children ...HTML) HTML { 293 | return Button(Attr(), children...) 294 | } 295 | 296 | func Canvas(attrs []a.Attribute, children ...HTML) HTML { 297 | return Element("canvas", attrs, children...) 298 | } 299 | 300 | func Canvas_(children ...HTML) HTML { 301 | return Canvas(Attr(), children...) 302 | } 303 | 304 | func Caption(attrs []a.Attribute, children ...HTML) HTML { 305 | return Element("caption", attrs, children...) 306 | } 307 | 308 | func Caption_(children ...HTML) HTML { 309 | return Caption(Attr(), children...) 310 | } 311 | 312 | func Center(attrs []a.Attribute, children ...HTML) HTML { 313 | return Element("center", attrs, children...) 314 | } 315 | 316 | func Center_(children ...HTML) HTML { 317 | return Center(Attr(), children...) 318 | } 319 | 320 | func Cite(attrs []a.Attribute, children ...HTML) HTML { 321 | return Element("cite", attrs, children...) 322 | } 323 | 324 | func Cite_(children ...HTML) HTML { 325 | return Cite(Attr(), children...) 326 | } 327 | 328 | func Code(attrs []a.Attribute, children ...HTML) HTML { 329 | return Element("code", attrs, children...) 330 | } 331 | 332 | func Code_(children ...HTML) HTML { 333 | return Code(Attr(), children...) 334 | } 335 | 336 | func Colgroup(attrs []a.Attribute, children ...HTML) HTML { 337 | return Element("colgroup", attrs, children...) 338 | } 339 | 340 | func Colgroup_(children ...HTML) HTML { 341 | return Colgroup(Attr(), children...) 342 | } 343 | 344 | func Datalist(attrs []a.Attribute, children ...HTML) HTML { 345 | return Element("datalist", attrs, children...) 346 | } 347 | 348 | func Datalist_(children ...HTML) HTML { 349 | return Datalist(Attr(), children...) 350 | } 351 | 352 | func Dd(attrs []a.Attribute, children ...HTML) HTML { 353 | return Element("dd", attrs, children...) 354 | } 355 | 356 | func Dd_(children ...HTML) HTML { 357 | return Dd(Attr(), children...) 358 | } 359 | 360 | func Del(attrs []a.Attribute, children ...HTML) HTML { 361 | return Element("del", attrs, children...) 362 | } 363 | 364 | func Del_(children ...HTML) HTML { 365 | return Del(Attr(), children...) 366 | } 367 | 368 | func Details(attrs []a.Attribute, children ...HTML) HTML { 369 | return Element("details", attrs, children...) 370 | } 371 | 372 | func Details_(children ...HTML) HTML { 373 | return Details(Attr(), children...) 374 | } 375 | 376 | func Dfn(attrs []a.Attribute, children ...HTML) HTML { 377 | return Element("dfn", attrs, children...) 378 | } 379 | 380 | func Dfn_(children ...HTML) HTML { 381 | return Dfn(Attr(), children...) 382 | } 383 | 384 | func Dir(attrs []a.Attribute, children ...HTML) HTML { 385 | return Element("dir", attrs, children...) 386 | } 387 | 388 | func Dir_(children ...HTML) HTML { 389 | return Dir(Attr(), children...) 390 | } 391 | 392 | func Div(attrs []a.Attribute, children ...HTML) HTML { 393 | return Element("div", attrs, children...) 394 | } 395 | 396 | func Div_(children ...HTML) HTML { 397 | return Div(Attr(), children...) 398 | } 399 | 400 | func Dl(attrs []a.Attribute, children ...HTML) HTML { 401 | return Element("dl", attrs, children...) 402 | } 403 | 404 | func Dl_(children ...HTML) HTML { 405 | return Dl(Attr(), children...) 406 | } 407 | 408 | func Dt(attrs []a.Attribute, children ...HTML) HTML { 409 | return Element("dt", attrs, children...) 410 | } 411 | 412 | func Dt_(children ...HTML) HTML { 413 | return Dt(Attr(), children...) 414 | } 415 | 416 | func Em(attrs []a.Attribute, children ...HTML) HTML { 417 | return Element("em", attrs, children...) 418 | } 419 | 420 | func Em_(children ...HTML) HTML { 421 | return Em(Attr(), children...) 422 | } 423 | 424 | func Fieldset(attrs []a.Attribute, children ...HTML) HTML { 425 | return Element("fieldset", attrs, children...) 426 | } 427 | 428 | func Fieldset_(children ...HTML) HTML { 429 | return Fieldset(Attr(), children...) 430 | } 431 | 432 | func Figcaption(attrs []a.Attribute, children ...HTML) HTML { 433 | return Element("figcaption", attrs, children...) 434 | } 435 | 436 | func Figcaption_(children ...HTML) HTML { 437 | return Figcaption(Attr(), children...) 438 | } 439 | 440 | func Figure(attrs []a.Attribute, children ...HTML) HTML { 441 | return Element("figure", attrs, children...) 442 | } 443 | 444 | func Figure_(children ...HTML) HTML { 445 | return Figure(Attr(), children...) 446 | } 447 | 448 | func Font(attrs []a.Attribute, children ...HTML) HTML { 449 | return Element("font", attrs, children...) 450 | } 451 | 452 | func Font_(children ...HTML) HTML { 453 | return Font(Attr(), children...) 454 | } 455 | 456 | func Footer(attrs []a.Attribute, children ...HTML) HTML { 457 | return Element("footer", attrs, children...) 458 | } 459 | 460 | func Footer_(children ...HTML) HTML { 461 | return Footer(Attr(), children...) 462 | } 463 | 464 | func Form(attrs []a.Attribute, children ...HTML) HTML { 465 | return Element("form", attrs, children...) 466 | } 467 | 468 | func Form_(children ...HTML) HTML { 469 | return Form(Attr(), children...) 470 | } 471 | 472 | func Frame(attrs []a.Attribute, children ...HTML) HTML { 473 | return Element("frame", attrs, children...) 474 | } 475 | 476 | func Frame_(children ...HTML) HTML { 477 | return Frame(Attr(), children...) 478 | } 479 | 480 | func Frameset(attrs []a.Attribute, children ...HTML) HTML { 481 | return Element("frameset", attrs, children...) 482 | } 483 | 484 | func Frameset_(children ...HTML) HTML { 485 | return Frameset(Attr(), children...) 486 | } 487 | 488 | func H1(attrs []a.Attribute, children ...HTML) HTML { 489 | return Element("h1", attrs, children...) 490 | } 491 | 492 | func H1_(children ...HTML) HTML { 493 | return H1(Attr(), children...) 494 | } 495 | 496 | func H2(attrs []a.Attribute, children ...HTML) HTML { 497 | return Element("h2", attrs, children...) 498 | } 499 | 500 | func H2_(children ...HTML) HTML { 501 | return H2(Attr(), children...) 502 | } 503 | 504 | func H3(attrs []a.Attribute, children ...HTML) HTML { 505 | return Element("h3", attrs, children...) 506 | } 507 | 508 | func H3_(children ...HTML) HTML { 509 | return H3(Attr(), children...) 510 | } 511 | 512 | func H4(attrs []a.Attribute, children ...HTML) HTML { 513 | return Element("h4", attrs, children...) 514 | } 515 | 516 | func H4_(children ...HTML) HTML { 517 | return H4(Attr(), children...) 518 | } 519 | 520 | func H5(attrs []a.Attribute, children ...HTML) HTML { 521 | return Element("h5", attrs, children...) 522 | } 523 | 524 | func H5_(children ...HTML) HTML { 525 | return H5(Attr(), children...) 526 | } 527 | 528 | func H6(attrs []a.Attribute, children ...HTML) HTML { 529 | return Element("h6", attrs, children...) 530 | } 531 | 532 | func H6_(children ...HTML) HTML { 533 | return H6(Attr(), children...) 534 | } 535 | 536 | func Head(attrs []a.Attribute, children ...HTML) HTML { 537 | return Element("head", attrs, children...) 538 | } 539 | 540 | func Head_(children ...HTML) HTML { 541 | return Head(Attr(), children...) 542 | } 543 | 544 | func Header(attrs []a.Attribute, children ...HTML) HTML { 545 | return Element("header", attrs, children...) 546 | } 547 | 548 | func Header_(children ...HTML) HTML { 549 | return Header(Attr(), children...) 550 | } 551 | 552 | func Hgroup(attrs []a.Attribute, children ...HTML) HTML { 553 | return Element("hgroup", attrs, children...) 554 | } 555 | 556 | func Hgroup_(children ...HTML) HTML { 557 | return Hgroup(Attr(), children...) 558 | } 559 | 560 | func Html(attrs []a.Attribute, children ...HTML) HTML { 561 | return Element("html", attrs, children...) 562 | } 563 | 564 | func Html_(children ...HTML) HTML { 565 | return Html(Attr(), children...) 566 | } 567 | 568 | func I(attrs []a.Attribute, children ...HTML) HTML { 569 | return Element("i", attrs, children...) 570 | } 571 | 572 | func I_(children ...HTML) HTML { 573 | return I(Attr(), children...) 574 | } 575 | 576 | func Iframe(attrs []a.Attribute, children ...HTML) HTML { 577 | return Element("iframe", attrs, children...) 578 | } 579 | 580 | func Iframe_(children ...HTML) HTML { 581 | return Iframe(Attr(), children...) 582 | } 583 | 584 | func Ins(attrs []a.Attribute, children ...HTML) HTML { 585 | return Element("ins", attrs, children...) 586 | } 587 | 588 | func Ins_(children ...HTML) HTML { 589 | return Ins(Attr(), children...) 590 | } 591 | 592 | func Isindex(attrs []a.Attribute, children ...HTML) HTML { 593 | return Element("isindex", attrs, children...) 594 | } 595 | 596 | func Isindex_(children ...HTML) HTML { 597 | return Isindex(Attr(), children...) 598 | } 599 | 600 | func Kbd(attrs []a.Attribute, children ...HTML) HTML { 601 | return Element("kbd", attrs, children...) 602 | } 603 | 604 | func Kbd_(children ...HTML) HTML { 605 | return Kbd(Attr(), children...) 606 | } 607 | 608 | func Keygen(attrs []a.Attribute, children ...HTML) HTML { 609 | return Element("keygen", attrs, children...) 610 | } 611 | 612 | func Keygen_(children ...HTML) HTML { 613 | return Keygen(Attr(), children...) 614 | } 615 | 616 | func Label(attrs []a.Attribute, children ...HTML) HTML { 617 | return Element("label", attrs, children...) 618 | } 619 | 620 | func Label_(children ...HTML) HTML { 621 | return Label(Attr(), children...) 622 | } 623 | 624 | func Legend(attrs []a.Attribute, children ...HTML) HTML { 625 | return Element("legend", attrs, children...) 626 | } 627 | 628 | func Legend_(children ...HTML) HTML { 629 | return Legend(Attr(), children...) 630 | } 631 | 632 | func Li(attrs []a.Attribute, children ...HTML) HTML { 633 | return Element("li", attrs, children...) 634 | } 635 | 636 | func Li_(children ...HTML) HTML { 637 | return Li(Attr(), children...) 638 | } 639 | 640 | func Listing(attrs []a.Attribute, children ...HTML) HTML { 641 | return Element("listing", attrs, children...) 642 | } 643 | 644 | func Listing_(children ...HTML) HTML { 645 | return Listing(Attr(), children...) 646 | } 647 | 648 | func Main(attrs []a.Attribute, children ...HTML) HTML { 649 | return Element("main", attrs, children...) 650 | } 651 | 652 | func Main_(children ...HTML) HTML { 653 | return Main(Attr(), children...) 654 | } 655 | 656 | func Map(attrs []a.Attribute, children ...HTML) HTML { 657 | return Element("map", attrs, children...) 658 | } 659 | 660 | func Map_(children ...HTML) HTML { 661 | return Map(Attr(), children...) 662 | } 663 | 664 | func Mark(attrs []a.Attribute, children ...HTML) HTML { 665 | return Element("mark", attrs, children...) 666 | } 667 | 668 | func Mark_(children ...HTML) HTML { 669 | return Mark(Attr(), children...) 670 | } 671 | 672 | func Marquee(attrs []a.Attribute, children ...HTML) HTML { 673 | return Element("marquee", attrs, children...) 674 | } 675 | 676 | func Marquee_(children ...HTML) HTML { 677 | return Marquee(Attr(), children...) 678 | } 679 | 680 | func Menu(attrs []a.Attribute, children ...HTML) HTML { 681 | return Element("menu", attrs, children...) 682 | } 683 | 684 | func Menu_(children ...HTML) HTML { 685 | return Menu(Attr(), children...) 686 | } 687 | 688 | func Meter(attrs []a.Attribute, children ...HTML) HTML { 689 | return Element("meter", attrs, children...) 690 | } 691 | 692 | func Meter_(children ...HTML) HTML { 693 | return Meter(Attr(), children...) 694 | } 695 | 696 | func Nav(attrs []a.Attribute, children ...HTML) HTML { 697 | return Element("nav", attrs, children...) 698 | } 699 | 700 | func Nav_(children ...HTML) HTML { 701 | return Nav(Attr(), children...) 702 | } 703 | 704 | func Nobr(attrs []a.Attribute, children ...HTML) HTML { 705 | return Element("nobr", attrs, children...) 706 | } 707 | 708 | func Nobr_(children ...HTML) HTML { 709 | return Nobr(Attr(), children...) 710 | } 711 | 712 | func Noframes(attrs []a.Attribute, children ...HTML) HTML { 713 | return Element("noframes", attrs, children...) 714 | } 715 | 716 | func Noframes_(children ...HTML) HTML { 717 | return Noframes(Attr(), children...) 718 | } 719 | 720 | func Noscript(attrs []a.Attribute, children ...HTML) HTML { 721 | return Element("noscript", attrs, children...) 722 | } 723 | 724 | func Noscript_(children ...HTML) HTML { 725 | return Noscript(Attr(), children...) 726 | } 727 | 728 | func Object(attrs []a.Attribute, children ...HTML) HTML { 729 | return Element("object", attrs, children...) 730 | } 731 | 732 | func Object_(children ...HTML) HTML { 733 | return Object(Attr(), children...) 734 | } 735 | 736 | func Ol(attrs []a.Attribute, children ...HTML) HTML { 737 | return Element("ol", attrs, children...) 738 | } 739 | 740 | func Ol_(children ...HTML) HTML { 741 | return Ol(Attr(), children...) 742 | } 743 | 744 | func Optgroup(attrs []a.Attribute, children ...HTML) HTML { 745 | return Element("optgroup", attrs, children...) 746 | } 747 | 748 | func Optgroup_(children ...HTML) HTML { 749 | return Optgroup(Attr(), children...) 750 | } 751 | 752 | func Option(attrs []a.Attribute, children ...HTML) HTML { 753 | return Element("option", attrs, children...) 754 | } 755 | 756 | func Option_(children ...HTML) HTML { 757 | return Option(Attr(), children...) 758 | } 759 | 760 | func Output(attrs []a.Attribute, children ...HTML) HTML { 761 | return Element("output", attrs, children...) 762 | } 763 | 764 | func Output_(children ...HTML) HTML { 765 | return Output(Attr(), children...) 766 | } 767 | 768 | func P(attrs []a.Attribute, children ...HTML) HTML { 769 | return Element("p", attrs, children...) 770 | } 771 | 772 | func P_(children ...HTML) HTML { 773 | return P(Attr(), children...) 774 | } 775 | 776 | func Plaintext(attrs []a.Attribute, children ...HTML) HTML { 777 | return Element("plaintext", attrs, children...) 778 | } 779 | 780 | func Plaintext_(children ...HTML) HTML { 781 | return Plaintext(Attr(), children...) 782 | } 783 | 784 | func Pre(attrs []a.Attribute, children ...HTML) HTML { 785 | return Element("pre", attrs, children...) 786 | } 787 | 788 | func Pre_(children ...HTML) HTML { 789 | return Pre(Attr(), children...) 790 | } 791 | 792 | func Progress(attrs []a.Attribute, children ...HTML) HTML { 793 | return Element("progress", attrs, children...) 794 | } 795 | 796 | func Progress_(children ...HTML) HTML { 797 | return Progress(Attr(), children...) 798 | } 799 | 800 | func Q(attrs []a.Attribute, children ...HTML) HTML { 801 | return Element("q", attrs, children...) 802 | } 803 | 804 | func Q_(children ...HTML) HTML { 805 | return Q(Attr(), children...) 806 | } 807 | 808 | func Rp(attrs []a.Attribute, children ...HTML) HTML { 809 | return Element("rp", attrs, children...) 810 | } 811 | 812 | func Rp_(children ...HTML) HTML { 813 | return Rp(Attr(), children...) 814 | } 815 | 816 | func Rt(attrs []a.Attribute, children ...HTML) HTML { 817 | return Element("rt", attrs, children...) 818 | } 819 | 820 | func Rt_(children ...HTML) HTML { 821 | return Rt(Attr(), children...) 822 | } 823 | 824 | func Ruby(attrs []a.Attribute, children ...HTML) HTML { 825 | return Element("ruby", attrs, children...) 826 | } 827 | 828 | func Ruby_(children ...HTML) HTML { 829 | return Ruby(Attr(), children...) 830 | } 831 | 832 | func S(attrs []a.Attribute, children ...HTML) HTML { 833 | return Element("s", attrs, children...) 834 | } 835 | 836 | func S_(children ...HTML) HTML { 837 | return S(Attr(), children...) 838 | } 839 | 840 | func Samp(attrs []a.Attribute, children ...HTML) HTML { 841 | return Element("samp", attrs, children...) 842 | } 843 | 844 | func Samp_(children ...HTML) HTML { 845 | return Samp(Attr(), children...) 846 | } 847 | 848 | func Section(attrs []a.Attribute, children ...HTML) HTML { 849 | return Element("section", attrs, children...) 850 | } 851 | 852 | func Section_(children ...HTML) HTML { 853 | return Section(Attr(), children...) 854 | } 855 | 856 | func Select(attrs []a.Attribute, children ...HTML) HTML { 857 | return Element("select", attrs, children...) 858 | } 859 | 860 | func Select_(children ...HTML) HTML { 861 | return Select(Attr(), children...) 862 | } 863 | 864 | func Small(attrs []a.Attribute, children ...HTML) HTML { 865 | return Element("small", attrs, children...) 866 | } 867 | 868 | func Small_(children ...HTML) HTML { 869 | return Small(Attr(), children...) 870 | } 871 | 872 | func Spacer(attrs []a.Attribute, children ...HTML) HTML { 873 | return Element("spacer", attrs, children...) 874 | } 875 | 876 | func Spacer_(children ...HTML) HTML { 877 | return Spacer(Attr(), children...) 878 | } 879 | 880 | func Span(attrs []a.Attribute, children ...HTML) HTML { 881 | return Element("span", attrs, children...) 882 | } 883 | 884 | func Span_(children ...HTML) HTML { 885 | return Span(Attr(), children...) 886 | } 887 | 888 | func Strike(attrs []a.Attribute, children ...HTML) HTML { 889 | return Element("strike", attrs, children...) 890 | } 891 | 892 | func Strike_(children ...HTML) HTML { 893 | return Strike(Attr(), children...) 894 | } 895 | 896 | func Strong(attrs []a.Attribute, children ...HTML) HTML { 897 | return Element("strong", attrs, children...) 898 | } 899 | 900 | func Strong_(children ...HTML) HTML { 901 | return Strong(Attr(), children...) 902 | } 903 | 904 | func Style(attrs []a.Attribute, children ...HTML) HTML { 905 | return Element("style", attrs, children...) 906 | } 907 | 908 | func Style_(children ...HTML) HTML { 909 | return Style(Attr(), children...) 910 | } 911 | 912 | func Sub(attrs []a.Attribute, children ...HTML) HTML { 913 | return Element("sub", attrs, children...) 914 | } 915 | 916 | func Sub_(children ...HTML) HTML { 917 | return Sub(Attr(), children...) 918 | } 919 | 920 | func Summary(attrs []a.Attribute, children ...HTML) HTML { 921 | return Element("summary", attrs, children...) 922 | } 923 | 924 | func Summary_(children ...HTML) HTML { 925 | return Summary(Attr(), children...) 926 | } 927 | 928 | func Sup(attrs []a.Attribute, children ...HTML) HTML { 929 | return Element("sup", attrs, children...) 930 | } 931 | 932 | func Sup_(children ...HTML) HTML { 933 | return Sup(Attr(), children...) 934 | } 935 | 936 | func Table(attrs []a.Attribute, children ...HTML) HTML { 937 | return Element("table", attrs, children...) 938 | } 939 | 940 | func Table_(children ...HTML) HTML { 941 | return Table(Attr(), children...) 942 | } 943 | 944 | func Tbody(attrs []a.Attribute, children ...HTML) HTML { 945 | return Element("tbody", attrs, children...) 946 | } 947 | 948 | func Tbody_(children ...HTML) HTML { 949 | return Tbody(Attr(), children...) 950 | } 951 | 952 | func Td(attrs []a.Attribute, children ...HTML) HTML { 953 | return Element("td", attrs, children...) 954 | } 955 | 956 | func Td_(children ...HTML) HTML { 957 | return Td(Attr(), children...) 958 | } 959 | 960 | func Textarea(attrs []a.Attribute, children ...HTML) HTML { 961 | return Element("textarea", attrs, children...) 962 | } 963 | 964 | func Textarea_(children ...HTML) HTML { 965 | return Textarea(Attr(), children...) 966 | } 967 | 968 | func Tfoot(attrs []a.Attribute, children ...HTML) HTML { 969 | return Element("tfoot", attrs, children...) 970 | } 971 | 972 | func Tfoot_(children ...HTML) HTML { 973 | return Tfoot(Attr(), children...) 974 | } 975 | 976 | func Th(attrs []a.Attribute, children ...HTML) HTML { 977 | return Element("th", attrs, children...) 978 | } 979 | 980 | func Th_(children ...HTML) HTML { 981 | return Th(Attr(), children...) 982 | } 983 | 984 | func Thead(attrs []a.Attribute, children ...HTML) HTML { 985 | return Element("thead", attrs, children...) 986 | } 987 | 988 | func Thead_(children ...HTML) HTML { 989 | return Thead(Attr(), children...) 990 | } 991 | 992 | func Time(attrs []a.Attribute, children ...HTML) HTML { 993 | return Element("time", attrs, children...) 994 | } 995 | 996 | func Time_(children ...HTML) HTML { 997 | return Time(Attr(), children...) 998 | } 999 | 1000 | func Title(attrs []a.Attribute, children ...HTML) HTML { 1001 | return Element("title", attrs, children...) 1002 | } 1003 | 1004 | func Title_(children ...HTML) HTML { 1005 | return Title(Attr(), children...) 1006 | } 1007 | 1008 | func Tr(attrs []a.Attribute, children ...HTML) HTML { 1009 | return Element("tr", attrs, children...) 1010 | } 1011 | 1012 | func Tr_(children ...HTML) HTML { 1013 | return Tr(Attr(), children...) 1014 | } 1015 | 1016 | func Tt(attrs []a.Attribute, children ...HTML) HTML { 1017 | return Element("tt", attrs, children...) 1018 | } 1019 | 1020 | func Tt_(children ...HTML) HTML { 1021 | return Tt(Attr(), children...) 1022 | } 1023 | 1024 | func U(attrs []a.Attribute, children ...HTML) HTML { 1025 | return Element("u", attrs, children...) 1026 | } 1027 | 1028 | func U_(children ...HTML) HTML { 1029 | return U(Attr(), children...) 1030 | } 1031 | 1032 | func Ul(attrs []a.Attribute, children ...HTML) HTML { 1033 | return Element("ul", attrs, children...) 1034 | } 1035 | 1036 | func Ul_(children ...HTML) HTML { 1037 | return Ul(Attr(), children...) 1038 | } 1039 | 1040 | func Var(attrs []a.Attribute, children ...HTML) HTML { 1041 | return Element("var", attrs, children...) 1042 | } 1043 | 1044 | func Var_(children ...HTML) HTML { 1045 | return Var(Attr(), children...) 1046 | } 1047 | 1048 | func Video(attrs []a.Attribute, children ...HTML) HTML { 1049 | return Element("video", attrs, children...) 1050 | } 1051 | 1052 | func Video_(children ...HTML) HTML { 1053 | return Video(Attr(), children...) 1054 | } 1055 | 1056 | 1057 | // Begin of generated void elements 1058 | 1059 | 1060 | func Area(attrs []a.Attribute) HTML { 1061 | return VoidElement("area", attrs) 1062 | } 1063 | func Area_() HTML { 1064 | return Area(Attr()) 1065 | } 1066 | 1067 | func Base(attrs []a.Attribute) HTML { 1068 | return VoidElement("base", attrs) 1069 | } 1070 | func Base_() HTML { 1071 | return Base(Attr()) 1072 | } 1073 | 1074 | func Br(attrs []a.Attribute) HTML { 1075 | return VoidElement("br", attrs) 1076 | } 1077 | func Br_() HTML { 1078 | return Br(Attr()) 1079 | } 1080 | 1081 | func Col(attrs []a.Attribute) HTML { 1082 | return VoidElement("col", attrs) 1083 | } 1084 | func Col_() HTML { 1085 | return Col(Attr()) 1086 | } 1087 | 1088 | func Embed(attrs []a.Attribute) HTML { 1089 | return VoidElement("embed", attrs) 1090 | } 1091 | func Embed_() HTML { 1092 | return Embed(Attr()) 1093 | } 1094 | 1095 | func Hr(attrs []a.Attribute) HTML { 1096 | return VoidElement("hr", attrs) 1097 | } 1098 | func Hr_() HTML { 1099 | return Hr(Attr()) 1100 | } 1101 | 1102 | func Img(attrs []a.Attribute) HTML { 1103 | return VoidElement("img", attrs) 1104 | } 1105 | func Img_() HTML { 1106 | return Img(Attr()) 1107 | } 1108 | 1109 | func Input(attrs []a.Attribute) HTML { 1110 | return VoidElement("input", attrs) 1111 | } 1112 | func Input_() HTML { 1113 | return Input(Attr()) 1114 | } 1115 | 1116 | func Link(attrs []a.Attribute) HTML { 1117 | return VoidElement("link", attrs) 1118 | } 1119 | func Link_() HTML { 1120 | return Link(Attr()) 1121 | } 1122 | 1123 | func Meta(attrs []a.Attribute) HTML { 1124 | return VoidElement("meta", attrs) 1125 | } 1126 | func Meta_() HTML { 1127 | return Meta(Attr()) 1128 | } 1129 | 1130 | func Param(attrs []a.Attribute) HTML { 1131 | return VoidElement("param", attrs) 1132 | } 1133 | func Param_() HTML { 1134 | return Param(Attr()) 1135 | } 1136 | 1137 | func Source(attrs []a.Attribute) HTML { 1138 | return VoidElement("source", attrs) 1139 | } 1140 | func Source_() HTML { 1141 | return Source(Attr()) 1142 | } 1143 | 1144 | func Track(attrs []a.Attribute) HTML { 1145 | return VoidElement("track", attrs) 1146 | } 1147 | func Track_() HTML { 1148 | return Track(Attr()) 1149 | } 1150 | 1151 | func Wbr(attrs []a.Attribute) HTML { 1152 | return VoidElement("wbr", attrs) 1153 | } 1154 | func Wbr_() HTML { 1155 | return Wbr(Attr()) 1156 | } 1157 | 1158 | -------------------------------------------------------------------------------- /examples/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "net/http" 6 | 7 | . "github.com/julvo/htmlgo" 8 | a "github.com/julvo/htmlgo/attributes" 9 | ) 10 | 11 | func main() { 12 | http.HandleFunc("/", indexHandler) 13 | log.Fatal(http.ListenAndServe(":8080", nil)) 14 | } 15 | 16 | func indexHandler(w http.ResponseWriter, req *http.Request) { 17 | fruit := []string{"Apple", "Banana", "Orange"} 18 | 19 | fruitListItems := HTML("") 20 | for _, f := range fruit { 21 | fruitListItems += Li_(Text(f)) 22 | } 23 | 24 | content := 25 | navbar(false) + 26 | Ul_(fruitListItems) + 27 | footer() 28 | 29 | WriteTo(w, page("Home", content)) 30 | } 31 | 32 | func page(title string, content HTML) HTML { 33 | p := 34 | Html5_( 35 | Head_( 36 | Title_(Text(title)), 37 | Meta(Attr(a.Charset_("utf-8"))), 38 | Meta(Attr(a.Name_("viewport"), a.Content_("width=device-width"), a.InitialScale_("1"))), 39 | Link(Attr(a.Rel_("stylesheet"), a.Href_("/static/css/main.min.css")))), 40 | Body_( 41 | content, 42 | Script(Attr(a.Src_("/static/js/main.min.js")), JS{}))) 43 | 44 | return p 45 | } 46 | 47 | func navbar(isLoggedIn bool) HTML { 48 | var navItems HTML 49 | if !isLoggedIn { 50 | navItems = A(Attr(a.Href_("/login")), Text_("Login")) 51 | } 52 | 53 | nav := 54 | Nav_( 55 | Div_(navItems), 56 | Hr_()) 57 | 58 | return nav 59 | } 60 | 61 | func footer() HTML { 62 | return Footer_( 63 | Hr_(), 64 | Text_("© Acme Ltd, 2019")) 65 | } 66 | -------------------------------------------------------------------------------- /htmlgogen/attr.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | var attributes []string = []string{ 4 | "accept", 5 | "accept-charset", 6 | "accesskey", 7 | "action", 8 | "align", 9 | "alt", 10 | "aria-expanded", 11 | "aria-hidden", 12 | "aria-label", 13 | "async", 14 | "autocomplete", 15 | "autofocus", 16 | "autoplay", 17 | "bgcolor", 18 | "border", 19 | "charset", 20 | "checked", 21 | "cite", 22 | "class", 23 | "color", 24 | "cols", 25 | "colspan", 26 | "content", 27 | "contenteditable", 28 | "controls", 29 | "coords", 30 | "data", 31 | // "data-*", implemented manually 32 | "datetime", 33 | "default", 34 | "defer", 35 | "dir", 36 | "dirname", 37 | "disabled", 38 | "download", 39 | "draggable", 40 | "dropzone", 41 | "enctype", 42 | "for", 43 | "form", 44 | "formaction", 45 | "headers", 46 | "height", 47 | "hidden", 48 | "high", 49 | "href", 50 | "hreflang", 51 | "http-equiv", 52 | "id", 53 | "initial-scale", 54 | "ismap", 55 | "kind", 56 | "label", 57 | "lang", 58 | "list", 59 | "loop", 60 | "low", 61 | "max", 62 | "maxlength", 63 | "media", 64 | "method", 65 | "min", 66 | "multiple", 67 | "muted", 68 | "name", 69 | "novalidate", 70 | "onabort", 71 | "onafterprint", 72 | "onbeforeprint", 73 | "onbeforeunload", 74 | "onblur", 75 | "oncanplay", 76 | "oncanplaythrough", 77 | "onchange", 78 | "onclick", 79 | "oncontextmenu", 80 | "oncopy", 81 | "oncuechange", 82 | "oncut", 83 | "ondblclick", 84 | "ondrag", 85 | "ondragend", 86 | "ondragenter", 87 | "ondragleave", 88 | "ondragover", 89 | "ondragstart", 90 | "ondrop", 91 | "ondurationchange", 92 | "onemptied", 93 | "onended", 94 | "onerror", 95 | "onfocus", 96 | "onhashchange", 97 | "oninput", 98 | "oninvalid", 99 | "onkeydown", 100 | "onkeypress", 101 | "onkeyup", 102 | "onload", 103 | "onloadeddata", 104 | "onloadedmetadata", 105 | "onloadstart", 106 | "onmousedown", 107 | "onmousemove", 108 | "onmouseout", 109 | "onmouseover", 110 | "onmouseup", 111 | "onmousewheel", 112 | "onoffline", 113 | "ononline", 114 | "onpagehide", 115 | "onpageshow", 116 | "onpaste", 117 | "onpause", 118 | "onplay", 119 | "onplaying", 120 | "onpopstate", 121 | "onprogress", 122 | "onratechange", 123 | "onreset", 124 | "onresize", 125 | "onscroll", 126 | "onsearch", 127 | "onseeked", 128 | "onseeking", 129 | "onselect", 130 | "onstalled", 131 | "onstorage", 132 | "onsubmit", 133 | "onsuspend", 134 | "ontimeupdate", 135 | "ontoggle", 136 | "onunload", 137 | "onvolumechange", 138 | "onwaiting", 139 | "onwheel", 140 | "open", 141 | "optimum", 142 | "pattern", 143 | "placeholder", 144 | "poster", 145 | "preload", 146 | "readonly", 147 | "rel", 148 | "required", 149 | "reversed", 150 | "role", 151 | "rows", 152 | "rowspan", 153 | "sandbox", 154 | "scope", 155 | "selected", 156 | "shape", 157 | "size", 158 | "sizes", 159 | "span", 160 | "spellcheck", 161 | "src", 162 | "srcdoc", 163 | "srclang", 164 | "srcset", 165 | "start", 166 | "step", 167 | "style", 168 | "tabindex", 169 | "target", 170 | "title", 171 | "translate", 172 | "type", 173 | "usemap", 174 | "value", 175 | "width", 176 | "wrap", 177 | } 178 | -------------------------------------------------------------------------------- /htmlgogen/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "text/template" 7 | "path/filepath" 8 | "strings" 9 | ) 10 | 11 | type ElementFunc struct { 12 | FuncName string 13 | TagName string 14 | } 15 | 16 | type VoidElementFunc ElementFunc 17 | 18 | type AttributeFunc struct { 19 | FuncName string 20 | AttrName string 21 | } 22 | 23 | type Params struct { 24 | ElementFuncs []ElementFunc 25 | VoidElementFuncs []VoidElementFunc 26 | AttributeFuncs []AttributeFunc 27 | } 28 | 29 | const templDir = "htmlgogen/templates" 30 | // special-cases data-*, doctype 31 | func main() { 32 | templPaths, err := filepath.Glob(filepath.Join(templDir, "*.go")) 33 | check(err) 34 | moreTemplPaths, err := filepath.Glob(filepath.Join(templDir, "/*/*.go")) 35 | check(err) 36 | templPaths = append(templPaths, moreTemplPaths...) 37 | 38 | params := NewParams() 39 | 40 | for _, templPath := range templPaths { 41 | saveAs, err := filepath.Rel(templDir, templPath) 42 | check(err) 43 | 44 | fmt.Printf("Generating %s...\n", saveAs) 45 | 46 | templ, err := template.New(filepath.Base(templPath)). 47 | Delims("[[", "]]"). 48 | ParseFiles(templPath) 49 | check(err) 50 | err = os.MkdirAll(filepath.Dir(saveAs), 0744) 51 | check(err) 52 | 53 | f, err := os.Create(saveAs) 54 | check(err) 55 | defer f.Close() 56 | 57 | err = templ.Execute(f, params) 58 | check(err) 59 | } 60 | 61 | } 62 | 63 | func NewParams() Params { 64 | ps := Params{ 65 | []ElementFunc{}, 66 | []VoidElementFunc{}, 67 | []AttributeFunc{}, 68 | } 69 | 70 | for _, tag := range tags { 71 | if _, ok := selfClosingTags[tag]; ok { 72 | ps.VoidElementFuncs = append(ps.VoidElementFuncs, VoidElementFunc{ 73 | FuncName: GetFuncName(tag), 74 | TagName: tag, 75 | }) 76 | } else { 77 | ps.ElementFuncs = append(ps.ElementFuncs, ElementFunc{ 78 | FuncName: GetFuncName(tag), 79 | TagName: tag, 80 | }) 81 | } 82 | } 83 | for _, attr := range attributes { 84 | ps.AttributeFuncs = append(ps.AttributeFuncs, AttributeFunc{ 85 | FuncName: GetFuncName(attr), 86 | AttrName: attr, 87 | }) 88 | } 89 | return ps 90 | } 91 | 92 | func GetFuncName(s string) string { 93 | parts := strings.Split(s, "-") 94 | for i, p := range parts { 95 | parts[i] = strings.Title(p) 96 | } 97 | return strings.Join(parts, "") 98 | } 99 | 100 | func check(err error) { 101 | if err != nil { 102 | panic(err) 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /htmlgogen/tags.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | var tags []string = []string{ 4 | //"!DOCTYPE", implemented manually 5 | "a", 6 | "abbr", 7 | "acronym", 8 | "address", 9 | "applet", 10 | "area", 11 | "article", 12 | "aside", 13 | "audio", 14 | "b", 15 | "base", 16 | "basefont", 17 | "bdi", 18 | "bdo", 19 | "bgsound", 20 | "big", 21 | "blink", 22 | "blockquote", 23 | "body", 24 | "br", 25 | "button", 26 | "canvas", 27 | "caption", 28 | "center", 29 | "cite", 30 | "code", 31 | "col", 32 | "colgroup", 33 | "datalist", 34 | "dd", 35 | "del", 36 | "details", 37 | "dfn", 38 | "dir", 39 | "div", 40 | "dl", 41 | "dt", 42 | "em", 43 | "embed", 44 | "fieldset", 45 | "figcaption", 46 | "figure", 47 | "font", 48 | "footer", 49 | "form", 50 | "frame", 51 | "frameset", 52 | "h1", 53 | "h2", 54 | "h3", 55 | "h4", 56 | "h5", 57 | "h6", 58 | "head", 59 | "header", 60 | "hgroup", 61 | "hr", 62 | "html", 63 | "i", 64 | "iframe", 65 | "img", 66 | "input", 67 | "ins", 68 | "isindex", 69 | "kbd", 70 | "keygen", 71 | "label", 72 | "legend", 73 | "li", 74 | "link", 75 | "listing", 76 | "main", 77 | "map", 78 | "mark", 79 | "marquee", 80 | "menu", 81 | "meta", 82 | "meter", 83 | "nav", 84 | "nobr", 85 | "noframes", 86 | "noscript", 87 | "object", 88 | "ol", 89 | "optgroup", 90 | "option", 91 | "output", 92 | "p", 93 | "param", 94 | "plaintext", 95 | "pre", 96 | "progress", 97 | "q", 98 | "rp", 99 | "rt", 100 | "ruby", 101 | "s", 102 | "samp", 103 | //"script", Implemented manually 104 | "section", 105 | "select", 106 | "small", 107 | "source", 108 | "spacer", 109 | "span", 110 | "strike", 111 | "strong", 112 | "style", 113 | "sub", 114 | "summary", 115 | "sup", 116 | "table", 117 | "tbody", 118 | "td", 119 | "textarea", 120 | "tfoot", 121 | "th", 122 | "thead", 123 | "time", 124 | "title", 125 | "tr", 126 | "track", 127 | "tt", 128 | "u", 129 | "ul", 130 | "var", 131 | "video", 132 | "wbr", 133 | } 134 | 135 | var selfClosingTags map[string]struct{} = map[string]struct{}{ 136 | "area": struct{}{}, 137 | "base": struct{}{}, 138 | "br": struct{}{}, 139 | "col": struct{}{}, 140 | "embed": struct{}{}, 141 | "hr": struct{}{}, 142 | "img": struct{}{}, 143 | "input": struct{}{}, 144 | "link": struct{}{}, 145 | "meta": struct{}{}, 146 | "param": struct{}{}, 147 | "source": struct{}{}, 148 | "track": struct{}{}, 149 | "wbr": struct{}{}, 150 | } 151 | -------------------------------------------------------------------------------- /htmlgogen/templates/attributes/attributes.go: -------------------------------------------------------------------------------- 1 | package attributes 2 | 3 | import "strings" 4 | 5 | type Attribute struct { 6 | Templ string 7 | Data interface{} 8 | Name string 9 | } 10 | 11 | // Begin of manually implemented attributes 12 | 13 | func Dataset(key, value string) Attribute { 14 | key_ := strings.Replace(key, "-", "_", -1) 15 | return Attribute{ 16 | Data: map[string]string{ 17 | "key": key, 18 | "value": value, 19 | }, 20 | Templ: `{{define "Dataset_`+key_+`"}}data-{{.key}}="{{.value}}"{{end}}`, 21 | Name: "Dataset_"+key_, 22 | } 23 | } 24 | 25 | func Dataset_(key, value string) Attribute { 26 | key_ := strings.Replace(key, "-", "_", -1) 27 | return Attribute{ 28 | Data: map[string]string{ 29 | "value": value, 30 | }, 31 | Templ: `{{define "Dataset_`+key_+`"}}data-`+key+`="{{.value}}"{{end}}`, 32 | Name: "Dataset_"+key_, 33 | } 34 | } 35 | 36 | // Begin of generated attributes 37 | [[ range .AttributeFuncs ]] 38 | 39 | func [[.FuncName]](data interface{}, templs ...string) Attribute { 40 | attr := Attribute{ Data: data, Name: "[[.FuncName]]" } 41 | if len(templs) == 0 { 42 | attr.Templ = `{{define "[[.FuncName]]"}}[[.AttrName]]="{{.}}"{{end}}` 43 | } else { 44 | attr.Templ = `{{define "[[.FuncName]]"}}[[.AttrName]]="` + strings.Join(templs, " ") + `"{{end}}` 45 | } 46 | return attr 47 | } 48 | 49 | func [[.FuncName]]_(values ...string) Attribute { 50 | return [[.FuncName]](nil, values...) 51 | } 52 | [[ end ]] 53 | -------------------------------------------------------------------------------- /htmlgogen/templates/elements.go: -------------------------------------------------------------------------------- 1 | package htmlgo 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "strings" 7 | "html" 8 | "html/template" 9 | "bytes" 10 | 11 | a "github.com/julvo/htmlgo/attributes" 12 | ) 13 | 14 | type HTML string 15 | 16 | type JS struct { 17 | templ string 18 | data interface{} 19 | } 20 | 21 | func WriteTo(w io.Writer, h HTML) { 22 | w.Write([]byte(h)) 23 | } 24 | 25 | // Build a slice of type []Attribute for cosmetic purposes 26 | func Attr(attrs ...a.Attribute) []a.Attribute { 27 | return attrs 28 | } 29 | 30 | func prepareAttributes(attrs []a.Attribute) (string, string, map[string]interface{}) { 31 | data := map[string]interface{}{} 32 | templ := "" 33 | defs := "" 34 | 35 | for _, attr := range attrs { 36 | data[attr.Name] = attr.Data 37 | templ += ` {{template "` + attr.Name + `" .` + attr.Name + `}}` 38 | defs += attr.Templ 39 | } 40 | 41 | return templ, defs, data 42 | } 43 | 44 | func insertChildren(children ...HTML) string { 45 | s := "" 46 | for _, c := range children { 47 | s += string(c) 48 | } 49 | return s 50 | } 51 | 52 | func indent(s, indentation string) string { 53 | return strings.Replace(s, "\n", "\n" + indentation, -1) 54 | } 55 | 56 | func buildElement(tag string, attrs []a.Attribute, content string, close_ bool) string { 57 | templ, defs, data := prepareAttributes(attrs) 58 | complTempl := defs + "\n<" + tag + templ + ">" + content 59 | if close_ { 60 | complTempl += "\n" 61 | } 62 | 63 | t, _ := template.New(tag).Parse(complTempl) 64 | 65 | buf := new(bytes.Buffer) 66 | _ = t.Execute(buf, data) 67 | return buf.String() 68 | } 69 | 70 | func Element(tag string, attrs []a.Attribute, children ...HTML) HTML { 71 | return HTML(buildElement(tag, attrs, 72 | indent(insertChildren(children...), " "), true)) 73 | } 74 | 75 | func VoidElement(tag string, attrs []a.Attribute) HTML { 76 | return HTML(buildElement(tag, attrs, "", false)) 77 | } 78 | 79 | // Produce HTML from plain text by escaping 80 | func Text(v interface{}) HTML { 81 | return HTML("\n" + html.EscapeString(fmt.Sprint(v))) 82 | } 83 | 84 | func Text_(s string) HTML { 85 | return HTML(s) 86 | } 87 | 88 | // Begin of manually defined elements 89 | 90 | func Html5(attrs []a.Attribute, children ...HTML) HTML { 91 | return DoctypeHtml5 + Html(attrs, children...) 92 | } 93 | 94 | func Html5_(children ...HTML) HTML { 95 | return Html5(Attr(), children...) 96 | } 97 | 98 | func Doctype(t string) HTML { 99 | return HTML("") 100 | } 101 | 102 | const DoctypeHtml5 HTML = "" 103 | 104 | func Script(attrs []a.Attribute, js JS) HTML { 105 | if js.data == nil { 106 | return Element("script", attrs, HTML("\n" + js.templ)) 107 | } 108 | 109 | complTempl := buildElement("script", attrs, 110 | indent("\n" + js.templ, " "), true) 111 | 112 | // TODO set verbosity level to enable logging 113 | t, err := template.New("_").Delims("{%$", "$%}").Parse(complTempl) 114 | if err != nil { 115 | return Element("script", attrs) 116 | } 117 | 118 | buf := new(bytes.Buffer) 119 | err = t.Execute(buf, js.data) 120 | if err != nil { 121 | return Element("script", attrs) 122 | } 123 | 124 | return HTML(buf.String()) 125 | } 126 | 127 | func Script_(js JS) HTML { 128 | return Script(Attr(), js) 129 | } 130 | 131 | func JavaScript(data interface{}, templs ...string) JS { 132 | js := JS{ data: data } 133 | if len(templs) == 0 { 134 | js.templ = "{%$.$%}" 135 | } else { 136 | js.templ = strings.Replace( 137 | strings.Replace( 138 | strings.Join(templs, "\n"), 139 | "{{", "{%$", -1), 140 | "}}", "$%}", -1) 141 | } 142 | return js 143 | } 144 | 145 | func JavaScript_(templs ...string) JS { 146 | return JavaScript(nil, templs...) 147 | } 148 | 149 | // Begin of generated elements 150 | 151 | [[ range .ElementFuncs ]] 152 | func [[.FuncName]](attrs []a.Attribute, children ...HTML) HTML { 153 | return Element("[[.TagName]]", attrs, children...) 154 | } 155 | 156 | func [[.FuncName]]_(children ...HTML) HTML { 157 | return [[.FuncName]](Attr(), children...) 158 | } 159 | [[ end ]] 160 | 161 | // Begin of generated void elements 162 | 163 | [[ range .VoidElementFuncs ]] 164 | func [[.FuncName]](attrs []a.Attribute) HTML { 165 | return VoidElement("[[.TagName]]", attrs) 166 | } 167 | func [[.FuncName]]_() HTML { 168 | return [[.FuncName]](Attr()) 169 | } 170 | [[ end ]] 171 | --------------------------------------------------------------------------------