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.
()
| 222 | // |
| 223 | // Returns an error if something bad happens, user is responsible to catch it. |
| 224 | func (s *DjangoEngine) Load() error { |
| 225 | // If only custom templates should be loaded. |
| 226 | if (s.fs == nil || context.IsNoOpFS(s.fs)) && len(s.templateCache) > 0 { |
| 227 | return nil |
| 228 | } |
| 229 | |
| 230 | rootDirName := getRootDirName(s.fs) |
| 231 | |
| 232 | return walk(s.fs, "", func(path string, info os.FileInfo, err error) error { |
| 233 | if err != nil { |
| 234 | return err |
| 235 | } |
| 236 | |
| 237 | if info == nil || info.IsDir() { |
| 238 | return nil |
| 239 | } |
| 240 | |
| 241 | if s.extension != "" { |
| 242 | if !strings.HasSuffix(path, s.extension) { |
| 243 | return nil |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | if s.rootDir == rootDirName { |
| 248 | path = strings.TrimPrefix(path, rootDirName) |
| 249 | path = strings.TrimPrefix(path, "/") |
| 250 | } |
| 251 | |
| 252 | contents, err := asset(s.fs, path) |
| 253 | if err != nil { |
| 254 | return err |
| 255 | } |
| 256 | |
| 257 | return s.ParseTemplate(path, contents) |
| 258 | }) |
| 259 | } |
| 260 | |
| 261 | // ParseTemplate adds a custom template from text. |
| 262 | // This parser does not support funcs per template. Use the `AddFunc` instead. |
no test coverage detected