MCPcopy Create free account
hub / github.com/kataras/iris / Load

Method Load

view/handlebars.go:138–168  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

136//
137// Returns an error if something bad happens, user is responsible to catch it.
138func (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.
171func (s *HandlebarsEngine) ParseTemplate(name string, contents string, funcs template.FuncMap) error {

Callers 1

ExecuteWriterMethod · 0.95

Calls 6

ParseTemplateMethod · 0.95
IsNoOpFSFunction · 0.92
getRootDirNameFunction · 0.85
walkFunction · 0.85
assetFunction · 0.70
IsDirMethod · 0.45

Tested by

no test coverage detected