Skip to content

Commit a01ea90

Browse files
committed
Add subdirectory supports for HTML method
1 parent 3d25f66 commit a01ea90

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package renderer
22
==================
33
[![Build Status](https://travis-ci.org/thedevsaddam/renderer.svg?branch=master)](https://travis-ci.org/thedevsaddam/renderer)
4-
[![Project status](https://img.shields.io/badge/version-1.1-green.svg)](https://github.com/thedevsaddam/renderer/releases)
4+
[![Project status](https://img.shields.io/badge/version-1.2-green.svg)](https://github.com/thedevsaddam/renderer/releases)
55
[![Go Report Card](https://goreportcard.com/badge/github.com/thedevsaddam/renderer)](https://goreportcard.com/report/github.com/thedevsaddam/renderer)
66
[![Coverage Status](https://coveralls.io/repos/github/thedevsaddam/renderer/badge.svg?branch=master)](https://coveralls.io/github/thedevsaddam/renderer?branch=master)
77
[![GoDoc](https://godoc.org/github.com/thedevsaddam/renderer?status.svg)](https://godoc.org/github.com/thedevsaddam/renderer)

renderer.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import (
1717
"html/template"
1818
"io"
1919
"io/ioutil"
20+
"log"
2021
"net/http"
22+
"os"
2123
"path/filepath"
2224
"strings"
2325

@@ -562,5 +564,23 @@ func (r *Render) parseGlob() {
562564
for _, fm := range r.opts.FuncMap {
563565
tmpl.Funcs(fm)
564566
}
565-
r.globTemplates = template.Must(tmpl.ParseGlob(r.opts.ParseGlobPattern))
567+
if !strings.Contains(r.opts.ParseGlobPattern, "*.") {
568+
log.Fatal("renderer: invalid glob pattern!")
569+
}
570+
pf := strings.Split(r.opts.ParseGlobPattern, "*")
571+
fPath := pf[0]
572+
fExt := pf[1]
573+
err := filepath.Walk(fPath, func(path string, info os.FileInfo, err error) error {
574+
if strings.Contains(path, fExt) {
575+
_, err = tmpl.ParseFiles(path)
576+
if err != nil {
577+
log.Println(err)
578+
}
579+
}
580+
return err
581+
})
582+
if err != nil {
583+
log.Fatal(err)
584+
}
585+
r.globTemplates = tmpl
566586
}

0 commit comments

Comments
 (0)