parseCaddyfile sets up the handler from Caddyfile tokens. Syntax: templates [<matcher>] { mime <types...> between <open_delim> <close_delim> root <path> }
(h httpcaddyfile.Helper)
| 34 | // root <path> |
| 35 | // } |
| 36 | func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) { |
| 37 | h.Next() // consume directive name |
| 38 | t := new(Templates) |
| 39 | for h.NextBlock(0) { |
| 40 | switch h.Val() { |
| 41 | case "mime": |
| 42 | t.MIMETypes = h.RemainingArgs() |
| 43 | if len(t.MIMETypes) == 0 { |
| 44 | return nil, h.ArgErr() |
| 45 | } |
| 46 | case "between": |
| 47 | t.Delimiters = h.RemainingArgs() |
| 48 | if len(t.Delimiters) != 2 { |
| 49 | return nil, h.ArgErr() |
| 50 | } |
| 51 | case "root": |
| 52 | if !h.Args(&t.FileRoot) { |
| 53 | return nil, h.ArgErr() |
| 54 | } |
| 55 | case "extensions": |
| 56 | if h.NextArg() { |
| 57 | return nil, h.ArgErr() |
| 58 | } |
| 59 | if t.ExtensionsRaw != nil { |
| 60 | return nil, h.Err("extensions already specified") |
| 61 | } |
| 62 | for nesting := h.Nesting(); h.NextBlock(nesting); { |
| 63 | extensionModuleName := h.Val() |
| 64 | modID := "http.handlers.templates.functions." + extensionModuleName |
| 65 | unm, err := caddyfile.UnmarshalModule(h.Dispenser, modID) |
| 66 | if err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | cf, ok := unm.(CustomFunctions) |
| 70 | if !ok { |
| 71 | return nil, h.Errf("module %s (%T) does not provide template functions", modID, unm) |
| 72 | } |
| 73 | if t.ExtensionsRaw == nil { |
| 74 | t.ExtensionsRaw = make(caddy.ModuleMap) |
| 75 | } |
| 76 | t.ExtensionsRaw[extensionModuleName] = caddyconfig.JSON(cf, nil) |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | return t, nil |
| 81 | } |
nothing calls this directly
no test coverage detected