Skip to content

Commit

Permalink
Merge pull request #710 from trheyi/main
Browse files Browse the repository at this point in the history
[feat] SUI supports calling from backend functions
  • Loading branch information
trheyi authored Jul 25, 2024
2 parents cd08013 + 7706439 commit e7290f7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions sui/api/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sui/core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sui/core/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions sui/core/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions sui/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e7290f7

Please sign in to comment.