Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion render.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (r *Render) compileTemplatesFromAsset() {

ext := ""
if strings.Contains(rel, ".") {
ext = "." + strings.Join(strings.Split(rel, ".")[1:], ".")
ext = filepath.Ext(rel) // match the directory walker: only the final extension
}

for _, extension := range r.opt.Extensions {
Expand Down
30 changes: 30 additions & 0 deletions render_html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,33 @@ func TestHTMLPerCallContentType(t *testing.T) {
expect(t, res.Header().Get(ContentType), "application/xhtml+xml")
expect(t, res.Body.String(), "<h1>Hello gophers</h1>\n")
}

var dotDirFiles = map[string]string{
"testdata/dotdir/users.tmpl/index.tmpl": "Hello asset",
"testdata/dotdir/a.b.tmpl": "Hello ab",
}

// The asset loader must select templates by the same extension rule as the
// directory walker, including under a dot-named directory and for multi-dot names.
func TestHTMLAssetExtensionMatchesDirectory(t *testing.T) {
names := make([]string, 0, len(dotDirFiles))
for n := range dotDirFiles {
names = append(names, n)
}

dirRender := New(Options{Directory: "testdata/dotdir"})
assetRender := New(Options{
Directory: "testdata/dotdir",
Asset: func(n string) ([]byte, error) { return []byte(dotDirFiles[n]), nil },
AssetNames: func() []string { return names },
})

for _, name := range []string{"users.tmpl/index", "a.b"} {
if dirRender.TemplateLookup(name) == nil {
t.Errorf("directory mode did not load %q", name)
}
if assetRender.TemplateLookup(name) == nil {
t.Errorf("asset mode did not load %q", name)
}
}
}
1 change: 1 addition & 0 deletions testdata/dotdir/a.b.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello ab
1 change: 1 addition & 0 deletions testdata/dotdir/users.tmpl/index.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello asset