Skip to content

Commit

Permalink
Merge pull request #93 from gobuffalo/fixing-extra-args-handling
Browse files Browse the repository at this point in the history
fixed the bug in the extra args handling
  • Loading branch information
sio4 authored Feb 6, 2023
2 parents e72d518 + 49bd270 commit 931921b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions genny/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package auth
import (
"embed"
"fmt"
"html/template"
"io/fs"
"path/filepath"
"strings"
Expand All @@ -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)
}

Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion genny/auth/templates/migrations/create_users.up.fizz.plush
Original file line number Diff line number Diff line change
Expand Up @@ -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) %>})
<% } %>}

0 comments on commit 931921b

Please sign in to comment.