From f5478f396d6a15f29dee3915132af99e84716f4a Mon Sep 17 00:00:00 2001 From: tjpcc Date: Tue, 10 Oct 2023 17:02:49 -0600 Subject: support showyourwork template override directories on git directives fixes #5 --- parse.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'parse.go') diff --git a/parse.go b/parse.go index d087e95..15c5877 100644 --- a/parse.go +++ b/parse.go @@ -8,8 +8,10 @@ import ( "io" "net" "os/user" + "path/filepath" "strconv" "strings" + "text/template" "github.com/go-kit/log/level" "tildegit.org/tjp/sliderule/gemini" @@ -448,12 +450,36 @@ func parseModifiers(text string) (Modifiers, string, error) { mod.titanName = text[0:idx] text = text[idx+1:] } + case "templates": + if sep != " " { + return mod, "", errors.New("invalid 'templates' clause") + } + text = strings.TrimLeft(text, " \t") + idx = strings.IndexAny(text, " \t,") + var err error + if idx == 0 { + return mod, "", errors.New("invalid 'templates' clause") + } else if idx < 0 { + mod.Templates, err = loadTemplates(text) + text = "" + } else { + mod.Templates, err = loadTemplates(text[0:idx]) + text = text[idx+1:] + } + + if err != nil { + return mod, "", err + } default: return mod, text, nil } } } +func loadTemplates(dirpath string) (*template.Template, error) { + return template.ParseGlob(filepath.Join(dirpath, "*")) +} + func parseAuth(text string) (string, string, error) { spl := strings.SplitN(text, " ", 2) switch len(spl) { -- cgit v1.2.3