Load parses the templates to the engine. It is responsible to add the necessary global functions. Returns an error if something bad happens, user is responsible to catch it.
()
| 136 | // |
| 137 | // Returns an error if something bad happens, user is responsible to catch it. |
| 138 | func (s *HandlebarsEngine) Load() error { |
| 139 | // If only custom templates should be loaded. |
| 140 | if (s.fs == nil || context.IsNoOpFS(s.fs)) && len(s.templateCache) > 0 { |
| 141 | return nil |
| 142 | } |
| 143 | |
| 144 | rootDirName := getRootDirName(s.fs) |
| 145 | |
| 146 | return walk(s.fs, "", func(path string, info os.FileInfo, _ error) error { |
| 147 | if info == nil || info.IsDir() { |
| 148 | return nil |
| 149 | } |
| 150 | |
| 151 | if s.extension != "" { |
| 152 | if !strings.HasSuffix(path, s.extension) { |
| 153 | return nil |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | if s.rootDir == rootDirName { |
| 158 | path = strings.TrimPrefix(path, rootDirName) |
| 159 | path = strings.TrimPrefix(path, "/") |
| 160 | } |
| 161 | |
| 162 | contents, err := asset(s.fs, path) |
| 163 | if err != nil { |
| 164 | return err |
| 165 | } |
| 166 | return s.ParseTemplate(path, string(contents), nil) |
| 167 | }) |
| 168 | } |
| 169 | |
| 170 | // ParseTemplate adds a custom template from text. |
| 171 | func (s *HandlebarsEngine) ParseTemplate(name string, contents string, funcs template.FuncMap) error { |
no test coverage detected