github.com/gocaveman/caveman@v0.0.0-20191211162744-0ddf99dbdf6e/tmpl/tmplregistry/tmplregistry.go (about) 1 package tmplregistry 2 3 import ( 4 "github.com/gocaveman/caveman/tmpl" 5 "github.com/gocaveman/caveman/webutil" 6 ) 7 8 const ( 9 SeqTheme float64 = 80.0 10 ) 11 12 // OnlyReadableFromMain determines if `Contents()` can be called from packages other than main. 13 var OnlyReadableFromMain = true 14 15 var reg webutil.NamedSequence 16 17 // MustRegister adds a new tmpl.Store to the registry. 18 func MustRegister(seq float64, name string, store tmpl.Store) { 19 reg = append(reg, webutil.NamedSequenceItem{Sequence: seq, Name: name, Value: store}) 20 } 21 22 // Contents returns the current contents of the registry as a NamedSequence. 23 func Contents() webutil.NamedSequence { 24 if OnlyReadableFromMain { 25 webutil.MainOnly(1) 26 } 27 return reg.SortedCopy() 28 } 29 30 // ContentsStore returns the registry contents as a tmpl.StackedStore. 31 func ContentsStore() tmpl.StackedStore { 32 if OnlyReadableFromMain { 33 webutil.MainOnly(1) 34 } 35 regc := reg.SortedCopy() 36 var ret tmpl.StackedStore 37 for _, item := range regc { 38 ret = append(ret, item.Value.(tmpl.Store)) 39 } 40 return ret 41 }