-
Notifications
You must be signed in to change notification settings - Fork 55
/
plugin.go
34 lines (28 loc) · 1.06 KB
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package booklit
import "github.com/sirupsen/logrus"
// Plugin is an arbitrary object which is initialized with the Section that is
// using the plugin.
//
// Methods on the plugin object will be invoked during the "evaluation" stage
// by function calling syntax in Booklit documents.
//
// See https://booklit.page/plugins.html for more information.
type Plugin interface {
// methods are dynamically invoked
}
// PluginFactory constructs a Plugin for a given Section.
type PluginFactory func(*Section) Plugin
var plugins = map[string]PluginFactory{}
// RegisterPlugin registers a PluginFactory under a name. Booklit sections can
// then use the plugin by calling \use-plugin with the same name.
//
// This is typically called by a plugin package's init() function.
func RegisterPlugin(name string, factory PluginFactory) {
plugins[name] = factory
logrus.WithField("plugin", name).Info("plugin registered")
}
// LookupPlugin looks up the given plugin factory.
func LookupPlugin(name string) (PluginFactory, bool) {
plugin, found := plugins[name]
return plugin, found
}