mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-23 12:44:05 -08:00
Add 'tmpl', a 'template' for non-string literal names.
Change-Id: I6a03a5c5d20029cf414562efa7745ed6c53b2731
This commit is contained in:
parent
f525ca5d9e
commit
144d5bb9fd
|
@ -259,7 +259,15 @@ func (te templateExpander) ExpandHTML(templateFiles []string) (result string, re
|
|||
}()
|
||||
|
||||
var buffer bytes.Buffer
|
||||
tmpl, err := html_template.New(te.name).Funcs(html_template.FuncMap(te.funcMap)).Parse(te.text)
|
||||
tmpl := html_template.New(te.name).Funcs(html_template.FuncMap(te.funcMap))
|
||||
tmpl.Funcs(html_template.FuncMap{
|
||||
"tmpl": func(name string, data interface{}) (html_template.HTML, error) {
|
||||
var buffer bytes.Buffer
|
||||
err := tmpl.ExecuteTemplate(&buffer, name, data)
|
||||
return html_template.HTML(buffer.String()), err
|
||||
},
|
||||
})
|
||||
tmpl, err := tmpl.Parse(te.text)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Error parsing template %v: %v", te.name, err)
|
||||
}
|
||||
|
|
|
@ -147,6 +147,12 @@ func TestTemplateExpansion(t *testing.T) {
|
|||
text: "{{ tableLink \"up\" }}",
|
||||
output: "/graph#%5B%7B%22expr%22%3A%22up%22%2C%22tab%22%3A1%7D%5D",
|
||||
},
|
||||
{
|
||||
// tmpl.
|
||||
text: "{{ define \"a\" }}x{{ end }}{{ $name := \"a\"}}{{ tmpl $name . }}",
|
||||
output: "x",
|
||||
html: true,
|
||||
},
|
||||
}
|
||||
|
||||
time := clientmodel.Timestamp(0)
|
||||
|
|
Loading…
Reference in a new issue