From 49bd270462b7aee1d46b93d0ff3921a3a3b0abd7 Mon Sep 17 00:00:00 2001 From: Yonghwan SO Date: Sun, 5 Feb 2023 01:12:56 +0900 Subject: [PATCH] fixed the bug in the extra args handling --- genny/auth/auth.go | 13 ++++++++++--- .../templates/migrations/create_users.up.fizz.plush | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/genny/auth/auth.go b/genny/auth/auth.go index 781e067..df05638 100644 --- a/genny/auth/auth.go +++ b/genny/auth/auth.go @@ -3,6 +3,7 @@ package auth import ( "embed" "fmt" + "html/template" "io/fs" "path/filepath" "strings" @@ -29,13 +30,13 @@ func extraAttrs(args []string) []string { var result = []string{} for _, field := range args { at, _ := attrs.Parse(field) - field = at.Name.Underscore().String() + name := at.Name.Underscore().String() - if names[field] != "" { + if names[name] != "" { continue } - names[field] = field + names[name] = name result = append(result, field) } @@ -65,6 +66,12 @@ func New(args []string) (*genny.Generator, error) { ctx := plush.NewContext() ctx.Set("app", meta.New(".")) ctx.Set("attrs", fields) + ctx.Set("option", func(attr attrs.Attr) template.HTML { + if strings.HasPrefix(attr.GoType(), "nulls.") { + return "\"null\": true" + } + return "" + }) g.Transformer(plushgen.Transformer(ctx)) g.Transformer(genny.NewTransformer(".html", newUserHTMLTransformer)) diff --git a/genny/auth/templates/migrations/create_users.up.fizz.plush b/genny/auth/templates/migrations/create_users.up.fizz.plush index 56564c2..011bdb5 100644 --- a/genny/auth/templates/migrations/create_users.up.fizz.plush +++ b/genny/auth/templates/migrations/create_users.up.fizz.plush @@ -2,5 +2,5 @@ create_table("users"){ t.Column("id", "uuid", {"primary": true}) t.Column("email", "string", {}) t.Column("password_hash", "string", {}) -<%= for (attr) in attrs { %> t.Column("<%= attr.Name.Underscore() %>", "<%= attr.CommonType() %>", {}) +<%= for (attr) in attrs { %> t.Column("<%= attr.Name.Underscore() %>", "<%= attr.CommonType() %>", {<%= option(attr) %>}) <% } %>}