Silly idea I had
This commit is contained in:
parent
8084b7749a
commit
a2680c40d2
@ -35,9 +35,16 @@ type Environment struct {
|
||||
func (this *Environment) Init (ctx context.Context) error {
|
||||
this.documents = usync.NewLocker(make(map[string] *Document))
|
||||
this.funcMap = make(template.FuncMap)
|
||||
for _, provider := range this.Providers {
|
||||
if provider, ok := provider.(ConfigProcessor); ok {
|
||||
err := provider.ProcessConfig(this.Conf)
|
||||
if err != nil { return err }
|
||||
}
|
||||
}
|
||||
for _, provider := range this.Providers {
|
||||
if provider, ok := provider.(Configurable); ok {
|
||||
provider.Configure(this.Conf)
|
||||
err := provider.Configure(this.Conf)
|
||||
if err != nil { return err }
|
||||
}
|
||||
if provider, ok := provider.(FuncProvider); ok {
|
||||
funcMap := provider.FuncMap()
|
||||
|
25
provider.go
25
provider.go
@ -5,6 +5,23 @@ import "html/template"
|
||||
// Provider is an object which provides extra functionality to an environment.
|
||||
type Provider any
|
||||
|
||||
// Configurable is an object that can be configured according to metadata.
|
||||
type Configurable interface {
|
||||
Provider
|
||||
// Configure uses config to configure the object. It must not modify
|
||||
// config. Keys are namespaced with a '.' and are written in kebab case.
|
||||
Configure (config Meta) error
|
||||
}
|
||||
|
||||
// ConfigProcessor is an object that can alter the environment configuration
|
||||
// before other providers are configured in order to provide a sort of macro
|
||||
// system.
|
||||
type ConfigProcessor interface {
|
||||
// ProcessConfig analyzes and makes necessary changes to config. Unlike
|
||||
// Configurable.Configure, it can modify config.
|
||||
ProcessConfig (config Meta) error
|
||||
}
|
||||
|
||||
// FuncProvider provides a template.FuncMap.
|
||||
type FuncProvider interface {
|
||||
Provider
|
||||
@ -21,11 +38,3 @@ type FuncProviderFor interface {
|
||||
// may return nil, in which case its result is simply not considered.
|
||||
FuncMapFor (*Document) template.FuncMap
|
||||
}
|
||||
|
||||
// Configurable is an object that can be configured according to metadata.
|
||||
type Configurable interface {
|
||||
Provider
|
||||
// Configure uses config to configure the object. It must not modify
|
||||
// config. Keys are namespaced with a '.' and are written in kebab case.
|
||||
Configure (config Meta) error
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user