Skip to content

Commit

Permalink
Merge pull request #740 from trheyi/main
Browse files Browse the repository at this point in the history
chore: Refactor TemplateRender to handle optional request parameters
  • Loading branch information
trheyi authored Aug 23, 2024
2 parents 8c44f63 + 219f71b commit 99b78cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
27 changes: 23 additions & 4 deletions sui/api/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,28 @@ func TemplateRender(process *process.Process) interface{} {
}
}

r := core.Request{Theme: opt["theme"], Locale: opt["locale"]}
if process.NumOfArgs() > 5 {

raw, err := jsoniter.Marshal(process.Args[5])
if err != nil {
exception.New(err.Error(), 500).Throw()
}

err = jsoniter.Unmarshal(raw, &r)
if err != nil {
exception.New(err.Error(), 500).Throw()
}

if r.Theme == "" {
r.Theme = opt["theme"]
}

if r.Locale == "" {
r.Locale = opt["locale"]
}
}

data := process.ArgsMap(3)
option := core.ParserOption{
Theme: opt["theme"],
Expand All @@ -183,10 +205,7 @@ func TemplateRender(process *process.Process) interface{} {
Root: root,
Script: nil,
Imports: imports,
Request: &core.Request{
Theme: opt["theme"],
Locale: opt["locale"],
},
Request: &r,
}

parser := core.NewTemplateParser(core.Data(data), &option)
Expand Down
4 changes: 4 additions & 0 deletions sui/core/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func (script *Script) Call(r *Request, method string, args ...any) (interface{},
return nil, err
}
defer ctx.Close()
if args == nil {
args = []any{}
}
args = append(args, r)

// Set the sid
ctx.Sid = r.Sid
Expand Down

0 comments on commit 99b78cf

Please sign in to comment.