Files
summercms/internal/build/stubs/registry.tmpl
Jakub Zych 8bc18c90b6 feat(build): scaffold working admin controllers with model, AdminFS and delete (quick-261028-pq8)
- make:admin-controller edits the singular of its name (--model overrides):
  ModelName, modelClass and the YAML under models/<model>/
- NewRecord returns &models.<Model>{} when the model exists; otherwise the
  nil body stays and the command says to run make:model
- config_list.yaml offers create and delete with showCheckboxes
- registry.gen.go embeds controllers/*/*.yaml and models/*/*.yaml once they
  exist and exposes generatedAdminFS(); scaffolded plugins implement
  pact.AdminAssets through it, and a plugin without AdminFS gets a note
- blog example moves its YAML to models/post; docs and help text follow
2026-10-28 19:15:23 +01:00

101 lines
2.2 KiB
Cheetah

{{define "registry.go"}}// Code generated by summer make. DO NOT EDIT.
package {{.Package}}
import (
"embed"
"io/fs"
"git.golem15.com/golem15/summercms/modules/backpack"
"git.golem15.com/golem15/summercms/modules/bonfire"
"git.golem15.com/golem15/summercms/modules/pact"
"github.com/go-gormigrate/gormigrate/v2"
{{- range .Imports}}
{{printf "%q" .}}
{{- end}}
)
func generatedModels() []any {
{{- if .Models}}
return []any{
{{- range .Models}}
&{{.Package}}.{{.Ident}}{},
{{- end}}
}
{{- else}}
return nil
{{- end}}
}
func generatedMigrations() []*gormigrate.Migration {
{{- if .Migrations}}
return []*gormigrate.Migration{
{{- range .Migrations}}
{{.Package}}.{{.Ident}}(),
{{- end}}
}
{{- else}}
return nil
{{- end}}
}
// generatedCommands returns the plugin's console commands. Commands that
// take a *backpack.App receive the first app passed in, or nil when none is.
func generatedCommands(app ...*backpack.App) []bonfire.Command {
{{- if .Commands}}
{{- if .AppCommands}}
var bootApp *backpack.App
if len(app) > 0 {
bootApp = app[0]
}
{{- end}}
return []bonfire.Command{
{{- range .Commands}}
{{.Package}}.{{.Ident}}({{if .TakesApp}}bootApp{{end}}),
{{- end}}
}
{{- else}}
return nil
{{- end}}
}
func generatedJobs() []pact.Job {
{{- if .Jobs}}
return []pact.Job{
{{- range .Jobs}}
{{.Package}}.{{.Ident}}(),
{{- end}}
}
{{- else}}
return nil
{{- end}}
}
func generatedAdminControllers() []pact.AdminController {
{{- if .AdminControllers}}
return []pact.AdminController{
{{- range .AdminControllers}}
{{.Package}}.{{.Ident}}(),
{{- end}}
}
{{- else}}
return nil
{{- end}}
}
// generatedAdminTree holds the admin YAML of the plugin: the controller
// configuration and the model fields and columns. Go evaluates the go:embed
// globs at compile time, so YAML files added later in these directories are
// included; the next make: command rewrites the line when a glob starts or
// stops matching a file.
{{- if .AdminPatterns}}
//
//go:embed{{range .AdminPatterns}} {{.}}{{end}}
{{- end}}
var generatedAdminTree embed.FS
// generatedAdminFS returns the admin YAML for pact.AdminAssets: an empty tree
// until the first admin controller is scaffolded.
func generatedAdminFS() fs.FS { return generatedAdminTree }
{{end}}