Merge pull request #740 from trheyi/main
chore: Refactor TemplateRender to handle optional request parameters
This commit is contained in:
commit
99b78cfe98
2 changed files with 27 additions and 4 deletions
|
|
@ -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)
|
data := process.ArgsMap(3)
|
||||||
option := core.ParserOption{
|
option := core.ParserOption{
|
||||||
Theme: opt["theme"],
|
Theme: opt["theme"],
|
||||||
|
|
@ -183,10 +205,7 @@ func TemplateRender(process *process.Process) interface{} {
|
||||||
Root: root,
|
Root: root,
|
||||||
Script: nil,
|
Script: nil,
|
||||||
Imports: imports,
|
Imports: imports,
|
||||||
Request: &core.Request{
|
Request: &r,
|
||||||
Theme: opt["theme"],
|
|
||||||
Locale: opt["locale"],
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parser := core.NewTemplateParser(core.Data(data), &option)
|
parser := core.NewTemplateParser(core.Data(data), &option)
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,10 @@ func (script *Script) Call(r *Request, method string, args ...any) (interface{},
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer ctx.Close()
|
defer ctx.Close()
|
||||||
|
if args == nil {
|
||||||
|
args = []any{}
|
||||||
|
}
|
||||||
|
args = append(args, r)
|
||||||
|
|
||||||
// Set the sid
|
// Set the sid
|
||||||
ctx.Sid = r.Sid
|
ctx.Sid = r.Sid
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue