providers/import: Add panic function

This commit is contained in:
Sasha Koshka 2024-12-08 01:00:50 -05:00
parent b654829428
commit 6f04353512

View File

@ -1,5 +1,7 @@
package impor package impor
import "fmt"
import "errors"
import "strings" import "strings"
import "html/template" import "html/template"
import "git.tebibyte.media/sashakoshka/step" import "git.tebibyte.media/sashakoshka/step"
@ -22,6 +24,7 @@ func (this *Provider) FuncMapFor (document *step.Document) template.FuncMap {
document: document, document: document,
} }
return template.FuncMap { return template.FuncMap {
"panic": stat.funcPanic,
"execute": stat.funcExecute, "execute": stat.funcExecute,
"include": stat.funcInclude, "include": stat.funcInclude,
"includeHTML": stat.funcIncludeHTML, "includeHTML": stat.funcIncludeHTML,
@ -32,6 +35,14 @@ type state struct {
document *step.Document document *step.Document
} }
func (this *state) funcPanic (message any) (string, error) {
if err, ok := message.(error); ok {
return "", err
} else {
return "", errors.New(fmt.Sprint(message))
}
}
func (this *state) funcExecute (name string, data any) (step.ExecutionResult, error) { func (this *state) funcExecute (name string, data any) (step.ExecutionResult, error) {
document, err := this.document.Environment().Parse(name) document, err := this.document.Environment().Parse(name)
if err != nil { return step.ExecutionResult { }, err } if err != nil { return step.ExecutionResult { }, err }