include css in test files
parent
c21a6a5b3b
commit
d1e1991fe4
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -9,20 +10,25 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
all := []string{}
|
||||||
always := []string{}
|
always := []string{}
|
||||||
if err := recursePwd(func(p string) error {
|
if err := recursePwd(func(p string) error {
|
||||||
switch path.Ext(p) {
|
switch path.Ext(p) {
|
||||||
case ".ctmpl":
|
case ".ctmpl":
|
||||||
if path.Base(p)[0] == '_' {
|
if path.Base(p)[0] == '_' {
|
||||||
always = append(always, p)
|
all = append(all, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
switch path.Base(p) {
|
||||||
|
case "_import.ctmpl":
|
||||||
|
always = append(always, strings.TrimSuffix(path.Base(p), path.Ext(p)))
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
t := func(p ...string) *template.Template {
|
t := func(p ...string) *template.Template {
|
||||||
p = append(always, p...)
|
p = append(all, p...)
|
||||||
oneT, err := template.ParseFiles(p...)
|
oneT, err := template.ParseFiles(p...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
@ -45,8 +51,18 @@ func main() {
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
templateToExecute := strings.TrimSuffix(path.Base(p), path.Ext(p))
|
templateToExecute := strings.TrimSuffix(path.Base(p), path.Ext(p))
|
||||||
|
tmpl := t(p)
|
||||||
defer log.Printf("rendering %s (...%s) as %s", templateToExecute, path.Join(path.Base(path.Dir(p)), path.Base(p)), target)
|
defer log.Printf("rendering %s (...%s) as %s", templateToExecute, path.Join(path.Base(path.Dir(p)), path.Base(p)), target)
|
||||||
return t(p).Lookup(templateToExecute).Execute(f, data)
|
if strings.HasPrefix(templateToExecute, "_") {
|
||||||
|
testTemplate := `{{ define "test" }}`
|
||||||
|
for _, subtemplate := range always {
|
||||||
|
testTemplate += fmt.Sprintf(`{{ template %q . }}`, subtemplate)
|
||||||
|
}
|
||||||
|
testTemplate += fmt.Sprintf(`{{ template %q . }}{{ end }}`, templateToExecute)
|
||||||
|
tmpl = template.Must(tmpl.Parse(testTemplate))
|
||||||
|
templateToExecute = "test"
|
||||||
|
}
|
||||||
|
return tmpl.Lookup(templateToExecute).Execute(f, data)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue