From 230ff2bf372c6951c3c89f38cfdc17947dd695a8 Mon Sep 17 00:00:00 2001 From: Mark Spicer Date: Mon, 31 Jul 2023 10:56:36 -0400 Subject: [PATCH] fix: Cleanup codegen and formatting. (#835) This change fixes issues with code generation and go code formatting. --- docs/widgets.md | 5 +++-- render/image.go | 4 ++-- runtime/gen/header/render.tmpl | 7 ++++--- runtime/modules/hmac/hmac.go | 6 +++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/docs/widgets.md b/docs/widgets.md index 2476de0ef4..70e477fec3 100644 --- a/docs/widgets.md +++ b/docs/widgets.md @@ -160,7 +160,8 @@ render.Column( ## Image -Image renders the image data passed via `src`. `src` accepts a string and supports file URLs, SVG as a string, as well as image binary data. Supported binary data formats include PNG, JPEG and GIF. +Image renders the binary image data passed via `src`. Supported +formats include PNG, JPEG, GIF, and SVG. If `width` or `height` are set, the image will be scaled accordingly, with nearest neighbor interpolation. Otherwise the @@ -173,7 +174,7 @@ the `delay` attribute. #### Attributes | Name | Type | Description | Required | | --- | --- | --- | --- | -| `src` | `str` | Binary image data or svg text | **Y** | +| `src` | `str` | Binary image data or SVG text | **Y** | | `width` | `int` | Scale image to this width | N | | `height` | `int` | Scale image to this height | N | | `delay` | `int` | (Read-only) Frame delay in ms, for animated GIFs | N | diff --git a/render/image.go b/render/image.go index 1bed013adb..7e6536471b 100644 --- a/render/image.go +++ b/render/image.go @@ -21,7 +21,7 @@ import ( ) // Image renders the binary image data passed via `src`. Supported -// formats include PNG, JPEG and GIF. +// formats include PNG, JPEG, GIF, and SVG. // // If `width` or `height` are set, the image will be scaled // accordingly, with nearest neighbor interpolation. Otherwise the @@ -31,7 +31,7 @@ import ( // also be animated. Frame delay (in milliseconds) can be read from // the `delay` attribute. // -// DOC(Src): Binary image data +// DOC(Src): Binary image data or SVG text // DOC(Width): Scale image to this width // DOC(Height): Scale image to this height // DOC(Delay): (Read-only) Frame delay in ms, for animated GIFs diff --git a/runtime/gen/header/render.tmpl b/runtime/gen/header/render.tmpl index 00a5f879c5..5ae7186f14 100644 --- a/runtime/gen/header/render.tmpl +++ b/runtime/gen/header/render.tmpl @@ -23,9 +23,10 @@ var renderModule = RenderModule{} func LoadRenderModule() (starlark.StringDict, error) { renderModule.once.Do(func() { - fnt := starlark.NewDict(len(render.Font)) - for k, _ := range render.Font { - fnt.SetKey(starlark.String(k), starlark.String(k)) + fontList := render.GetFontList() + fnt := starlark.NewDict(len(fontList)) + for _, name := range fontList { + fnt.SetKey(starlark.String(name), starlark.String(name)) } fnt.Freeze() diff --git a/runtime/modules/hmac/hmac.go b/runtime/modules/hmac/hmac.go index 8c0e06783c..6797f64698 100644 --- a/runtime/modules/hmac/hmac.go +++ b/runtime/modules/hmac/hmac.go @@ -47,8 +47,8 @@ func LoadModule() (starlark.StringDict, error) { func fnHmac(hashFunc func() hash.Hash) func(*starlark.Thread, *starlark.Builtin, starlark.Tuple, []starlark.Tuple) (starlark.Value, error) { return func(t *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) { var ( - key starlark.Value - s starlark.String + key starlark.Value + s starlark.String binary bool = false ) if err := starlark.UnpackArgs(fn.Name(), args, kwargs, "key", &key, "s", &s, "binary?", &binary); err != nil { @@ -77,4 +77,4 @@ func fnHmac(hashFunc func() hash.Hash) func(*starlark.Thread, *starlark.Builtin, } return starlark.String(fmt.Sprintf("%x", digest)), nil } -} \ No newline at end of file +}