core/plugin/block_registry.go
Alex Dunmow 13d741979a fix: rename module path from ninja/core to block/core
Matches the actual Gitea repo location at block/core.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-01 09:39:10 +08:00

33 lines
956 B
Go

package plugin
import (
"io/fs"
"git.dev.alexdunmow.com/block/core/blocks"
)
// PluginBlockRegistry wraps a BlockRegistry to auto-prefix block keys with the plugin name.
type PluginBlockRegistry struct {
inner blocks.BlockRegistry
prefix string
}
// NewPluginBlockRegistry creates a block registry that auto-prefixes keys.
func NewPluginBlockRegistry(inner blocks.BlockRegistry, pluginName string) *PluginBlockRegistry {
return &PluginBlockRegistry{inner: inner, prefix: pluginName}
}
func (r *PluginBlockRegistry) Register(meta blocks.BlockMeta, fn blocks.BlockFunc) {
meta.Key = r.prefix + ":" + meta.Key
meta.Source = r.prefix
r.inner.Register(meta, fn)
}
func (r *PluginBlockRegistry) RegisterTemplateOverride(templateKey, blockKey string, fn blocks.BlockFunc) {
r.inner.RegisterTemplateOverride(templateKey, blockKey, fn)
}
func (r *PluginBlockRegistry) LoadSchemasFromFS(fsys fs.FS) error {
return r.inner.LoadSchemasFromFS(fsys)
}