Refactor SUI core to copy the script pointer to the request for page backend script execution

This commit is contained in:
Max 2024-07-25 19:07:50 +08:00
parent 0dbdc0b99b
commit 7706439f8f
5 changed files with 12 additions and 3 deletions

View file

@ -127,6 +127,8 @@ func (r *Request) Render() (string, int, error) {
if !dataHitCache {
// Request the data
// Copy the script pointer to the request For page backend script execution
r.Request.Script = c.Script
data = r.Request.NewData()
if c.Data != "" {
err = r.Request.ExecStringMerge(data, c.Data)

View file

@ -50,7 +50,7 @@ func (ctx *BuildContext) GetComponents() []string {
return []string{}
}
components := []string{}
for name := range ctx.components {
for _, name := range ctx.components {
components = append(components, name)
}
return components

View file

@ -302,7 +302,7 @@ func (parser *TemplateParser) parseElementComponent(sel *goquery.Selection) {
parser.errors = append(parser.errors, err)
setError(sel, err)
}
parser.sequence = parser.sequence + 1
parser.sequence = compParser.sequence + 1
}
func (parser *TemplateParser) clone(script *Script) *TemplateParser {
@ -365,7 +365,7 @@ func (parser *TemplateParser) transElementNode(sel *goquery.Selection) {
}
}
// 替换转义字符
// Escape the text
func (parser *TemplateParser) escapeText(content string) string {
matches := stmtRe.FindAllStringSubmatch(content, -1)
newContent := content

View file

@ -285,6 +285,12 @@ func (r *Request) call(p interface{}) (interface{}, error) {
return nil, fmt.Errorf("process name is empty")
}
// Call the backend script
if r.Script != nil && strings.HasPrefix(processName, "@") {
method := processName[1:]
return r.Script.Call(r, method, processArgs...)
}
process, err := process.Of(processName, processArgs...)
if err != nil {
return nil, err

View file

@ -282,6 +282,7 @@ type Request struct {
Sid string `json:"sid,omitempty"`
Theme any `json:"theme,omitempty"`
Locale any `json:"locale,omitempty"`
Script *Script `json:"-"`
}
// RequestSource is the struct for the request