providers/import: Add panic function
This commit is contained in:
parent
b654829428
commit
6f04353512
@ -1,5 +1,7 @@
|
||||
package impor
|
||||
|
||||
import "fmt"
|
||||
import "errors"
|
||||
import "strings"
|
||||
import "html/template"
|
||||
import "git.tebibyte.media/sashakoshka/step"
|
||||
@ -22,6 +24,7 @@ func (this *Provider) FuncMapFor (document *step.Document) template.FuncMap {
|
||||
document: document,
|
||||
}
|
||||
return template.FuncMap {
|
||||
"panic": stat.funcPanic,
|
||||
"execute": stat.funcExecute,
|
||||
"include": stat.funcInclude,
|
||||
"includeHTML": stat.funcIncludeHTML,
|
||||
@ -32,6 +35,14 @@ type state struct {
|
||||
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) {
|
||||
document, err := this.document.Environment().Parse(name)
|
||||
if err != nil { return step.ExecutionResult { }, err }
|
||||
|
Loading…
Reference in New Issue
Block a user