core/templates/pongo/loader.go
Alex Dunmow d94c979731 chore(templates): migrate pongo2/v6 -> block/ninjatpl v1.0.1
The legacy templates/pongo host runtime now uses the in-house ninjatpl
fork. Mechanical import/ident swap — these files only use NewSet /
TemplateLoader / Context / Must / Template, all identical in ninjatpl;
no custom filters/tags or *Error signatures involved.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-05 12:24:27 +08:00

44 lines
918 B
Go

package pongo
import (
"fmt"
"io"
"io/fs"
"git.dev.alexdunmow.com/block/ninjatpl"
)
// fsLoader adapts an fs.FS to pongo2's TemplateLoader interface.
type fsLoader struct {
fsys fs.FS
}
func (l *fsLoader) Abs(base, name string) string {
return name
}
func (l *fsLoader) Get(path string) (io.Reader, error) {
return l.fsys.Open(path)
}
// multiLoader chains multiple loaders, returning the first hit.
// Plugin templates can {% extends "base.html" %} where base.html
// lives in the core embedded FS rather than the plugin FS.
type multiLoader struct {
loaders []ninjatpl.TemplateLoader
}
func (l *multiLoader) Abs(base, name string) string {
return name
}
func (l *multiLoader) Get(path string) (io.Reader, error) {
for _, loader := range l.loaders {
r, err := loader.Get(path)
if err == nil {
return r, nil
}
}
return nil, fmt.Errorf("pongo: template %q not found in any loader", path)
}