29 lines
604 B
Go
29 lines
604 B
Go
package templates_test
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
|
|
"git.bivouac.wiki/use/templates"
|
|
)
|
|
|
|
//go:embed example_templates
|
|
var tpfs embed.FS
|
|
|
|
func ExampleTemplates() {
|
|
a := templates.NewTemplates(tpfs, "example_templates", "base.html", "nav.html")
|
|
v := struct{}{}
|
|
r := httptest.NewRequest(http.MethodGet, "home.html", nil)
|
|
w := httptest.NewRecorder()
|
|
a.TemplateEnd("home.html", w, r, v)
|
|
res := w.Result()
|
|
defer res.Body.Close()
|
|
data, err := io.ReadAll(res.Body)
|
|
if err != nil {
|
|
fmt.Errorf("expected error to be nil got %v", err)
|
|
}
|
|
fmt.Println(string(data))
|
|
}
|