Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make bindata static build parse builtin templates correctly #24003

Merged
merged 1 commit into from
Apr 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 11 additions & 10 deletions modules/templates/htmlrenderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ func (h *HTMLRender) TemplateLookup(name string) (*template.Template, error) {

func (h *HTMLRender) CompileTemplates() error {
dirPrefix := "templates/"
extSuffix := ".tmpl"
tmpls := template.New("")
for _, path := range GetTemplateAssetNames() {
name := path[len(dirPrefix):]
name = strings.TrimSuffix(name, ".tmpl")
if !strings.HasSuffix(path, extSuffix) {
continue
}
name := strings.TrimPrefix(path, dirPrefix)
name = strings.TrimSuffix(name, extSuffix)
tmpl := tmpls.New(filepath.ToSlash(name))
for _, fm := range NewFuncMap() {
tmpl.Funcs(fm)
Expand Down Expand Up @@ -101,7 +105,11 @@ func HTMLRenderer(ctx context.Context) (context.Context, *HTMLRender) {

renderer := &HTMLRender{}
if err := renderer.CompileTemplates(); err != nil {
handleFatalError(err)
wrapFatal(handleNotDefinedPanicError(err))
wrapFatal(handleUnexpected(err))
wrapFatal(handleExpectedEnd(err))
wrapFatal(handleGenericTemplateError(err))
log.Fatal("HTMLRenderer error: %v", err)
}
if !setting.IsProd {
watcher.CreateWatcher(ctx, "HTML Templates", &watcher.CreateWatcherOpts{
Expand All @@ -116,13 +124,6 @@ func HTMLRenderer(ctx context.Context) (context.Context, *HTMLRender) {
return context.WithValue(ctx, rendererKey, renderer), renderer
}

func handleFatalError(err error) {
wrapFatal(handleNotDefinedPanicError(err))
wrapFatal(handleUnexpected(err))
wrapFatal(handleExpectedEnd(err))
wrapFatal(handleGenericTemplateError(err))
}

func wrapFatal(format string, args []interface{}) {
if format == "" {
return
Expand Down