summaryrefslogtreecommitdiff
path: root/cmd/authelia-gen/templates.go
blob: 5d7a0726a11b5ef2e5b27c55ce96805318a54875 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main

import (
	"embed"
	"fmt"
	"text/template"

	"github.com/authelia/authelia/v4/internal/templates"
)

//go:embed templates/*
var templatesFS embed.FS

var (
	tmplCodeConfigurationSchemaKeys = template.Must(newTMPL("internal_configuration_schema_keys.go"))
	tmplGitHubIssueTemplateBug      = template.Must(newTMPL("github_issue_template_bug_report.yml"))
	tmplIssueTemplateFeature        = template.Must(newTMPL("github_issue_template_feature.yml"))
	tmplWebI18NIndex                = template.Must(newTMPL("web_i18n_index.ts"))
	tmplDotCommitLintRC             = template.Must(newTMPL("dot_commitlintrc.cjs"))
	tmplDocsCommitMessageGuidelines = template.Must(newTMPL("docs-contributing-development-commitmsg.md"))
	tmplScriptsGen                  = template.Must(newTMPL("cmd-authelia-scripts-gen.go"))
	tmplServer                      = template.Must(newTMPL("server_gen.go"))
	tmplADR                         = template.Must(newTMPL("docs-architectural_design_record.md"))
)

func newTMPL(name string) (tmpl *template.Template, err error) {
	funcs := templates.FuncMap()

	funcs["joinX"] = templates.FuncStringJoinX

	return template.New(name).Funcs(funcs).Parse(mustLoadTmplFS(name))
}

func mustLoadTmplFS(tmpl string) string {
	var (
		content []byte
		err     error
	)

	if content, err = templatesFS.ReadFile(fmt.Sprintf("templates/%s.tmpl", tmpl)); err != nil {
		panic(err)
	}

	return string(content)
}