Ace returns a new Ace view engine. It shares the same exactly logic with the html view engine, it uses the same exactly configuration. The given "extension" MUST begin with a dot. Ace minifies the response automatically unless SetIndent() method is set. Read more about the Ace Go Parser: https://gi
(fs interface{}, extension string)
| 37 | // Ace(iris.Dir("./views"), ".ace") or |
| 38 | // Ace(embed.FS, ".ace") or Ace(AssetFile(), ".ace") for embedded data. |
| 39 | func Ace(fs interface{}, extension string) *AceEngine { |
| 40 | s := &AceEngine{HTMLEngine: HTML(fs, extension), indent: ""} |
| 41 | s.name = "Ace" |
| 42 | |
| 43 | funcs := make(map[string]interface{}) |
| 44 | |
| 45 | once := new(sync.Once) |
| 46 | |
| 47 | s.middleware = func(name string, text []byte) (contents string, err error) { |
| 48 | once.Do(func() { // on first template parse, all funcs are given. |
| 49 | for k, v := range s.getBuiltinFuncs(name) { |
| 50 | funcs[k] = v |
| 51 | } |
| 52 | |
| 53 | for k, v := range s.funcs { |
| 54 | funcs[k] = v |
| 55 | } |
| 56 | }) |
| 57 | |
| 58 | // name = path.Join(path.Clean(directory), name) |
| 59 | |
| 60 | src := ace.NewSource( |
| 61 | ace.NewFile(name, text), |
| 62 | ace.NewFile("", []byte{}), |
| 63 | []*ace.File{}, |
| 64 | ) |
| 65 | |
| 66 | if strings.Contains(name, "layout") { |
| 67 | for k, v := range s.layoutFuncs { |
| 68 | funcs[k] = v |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | opts := &ace.Options{ |
| 73 | Extension: extension[1:], |
| 74 | FuncMap: funcs, |
| 75 | DelimLeft: s.left, |
| 76 | DelimRight: s.right, |
| 77 | Indent: s.indent, |
| 78 | } |
| 79 | |
| 80 | rslt, err := ace.ParseSource(src, opts) |
| 81 | if err != nil { |
| 82 | return "", err |
| 83 | } |
| 84 | |
| 85 | t, err := ace.CompileResult(name, rslt, opts) |
| 86 | if err != nil { |
| 87 | return "", err |
| 88 | } |
| 89 | |
| 90 | return t.Lookup(name).Tree.Root.String(), nil |
| 91 | } |
| 92 | |
| 93 | return s |
| 94 | } |