|
@@ -3,6 +3,7 @@ package isokit
|
3
|
3
|
import (
|
4
|
4
|
"bytes"
|
5
|
5
|
"encoding/gob"
|
|
6
|
+ "html/template"
|
6
|
7
|
|
7
|
8
|
"honnef.co/go/js/xhr"
|
8
|
9
|
)
|
|
@@ -36,3 +37,34 @@ func FetchTemplateBundle(templateSetChannel chan *TemplateSet) {
|
36
|
37
|
|
37
|
38
|
templateSetChannel <- templateSet
|
38
|
39
|
}
|
|
40
|
+
|
|
41
|
+func FetchTemplateBundleWithSuppliedFunctionMap(templateSetChannel chan *TemplateSet, funcMap template.FuncMap) {
|
|
42
|
+
|
|
43
|
+ data, err := xhr.Send("POST", "/template-bundle", nil)
|
|
44
|
+ if err != nil {
|
|
45
|
+ println("Encountered error: ", err)
|
|
46
|
+ println(err)
|
|
47
|
+ }
|
|
48
|
+ var templateBundleMap map[string]string
|
|
49
|
+ var templateBundleMapBuffer bytes.Buffer
|
|
50
|
+
|
|
51
|
+ dec := gob.NewDecoder(&templateBundleMapBuffer)
|
|
52
|
+ templateBundleMapBuffer = *bytes.NewBuffer(data)
|
|
53
|
+ err = dec.Decode(&templateBundleMap)
|
|
54
|
+
|
|
55
|
+ if err != nil {
|
|
56
|
+ println("Encountered error: ", err)
|
|
57
|
+ panic(err)
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ templateSet := NewTemplateSet()
|
|
61
|
+ templateSet.Funcs = funcMap
|
|
62
|
+ err = templateSet.ImportTemplatesFromMap(templateBundleMap)
|
|
63
|
+
|
|
64
|
+ if err != nil {
|
|
65
|
+ println("Encountered import error: ", err)
|
|
66
|
+ panic(err)
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ templateSetChannel <- templateSet
|
|
70
|
+}
|