Files
summercms/internal/build/stubs/plugin.tmpl
Jakub Zych 70e4b4183c feat(build): mark scaffolded files with //summer:make and pass the app to generated commands (quick-261028-pq8)
- model, migration, command, job and admin-controller stubs start with
  //summer:make <kind>; registry.gen.go keeps its generated-code header
- the registry scan accepts the directive and the older header
- command functions may take one *backpack.App; generatedCommands takes a
  variadic app, so plugin.go files calling generatedCommands() still compile
- scaffolded plugins keep the app from Boot and return generatedCommands(p.app)
- make:command notes the nil app for an older plugin.go
- docs, help text and the blog example follow
2026-10-28 19:04:39 +01:00

142 lines
3.8 KiB
Cheetah

{{define "plugin.go"}}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"
"git.golem15.com/golem15/summercms/modules/party"
"github.com/go-gormigrate/gormigrate/v2"
)
var (
_ pact.HasConfig = (*Plugin)(nil)
_ pact.HasLang = (*Plugin)(nil)
_ pact.HasMailTemplates = (*Plugin)(nil)
_ pact.HasModels = (*Plugin)(nil)
_ pact.HasMigrations = (*Plugin)(nil)
_ pact.HasCommands = (*Plugin)(nil)
_ pact.HasJobs = (*Plugin)(nil)
_ pact.HasAdminControllers = (*Plugin)(nil)
)
//go:embed config
var configFS embed.FS
//go:embed lang
var langFS embed.FS
//go:embed views/mail
var mailFS embed.FS
// Plugin is the {{.ID}} plugin.
type Plugin struct {
// app is the application, kept from Boot for the generated commands.
app *backpack.App
}
func (p *Plugin) ID() string { return {{printf "%q" .ID}} }
func (p *Plugin) Requires() []string { return nil }
func (p *Plugin) Register(*backpack.App) error { return nil }
func (p *Plugin) Boot(app *backpack.App) error {
p.app = app
return nil
}
func (p *Plugin) ConfigFS() fs.FS { return configFS }
func (p *Plugin) LangFS() fs.FS { return langFS }
func (p *Plugin) MailTemplatesFS() fs.FS { return mailFS }
func (p *Plugin) MailTemplates() []string { return nil }
func (p *Plugin) MailLayouts() map[string]string { return nil }
func (p *Plugin) Models() []any { return generatedModels() }
func (p *Plugin) Migrations() []*gormigrate.Migration { return generatedMigrations() }
// Commands is collected after Boot, so p.app is set.
func (p *Plugin) Commands() []bonfire.Command { return generatedCommands(p.app) }
func (p *Plugin) Jobs() []pact.Job { return generatedJobs() }
func (p *Plugin) AdminControllers() []pact.AdminController {
return generatedAdminControllers()
}
func init() {
party.Register(&Plugin{})
}
{{end}}
{{define "routes.go"}}package {{.Package}}
{{if .StarterRoute}}
import (
"encoding/json"
"net/http"
"git.golem15.com/golem15/summercms/modules/pact"
)
var _ pact.HasRoutes = (*Plugin)(nil)
// Routes registers the starter route: GET / answers with a JSON greeting
// naming this plugin.
func (p *Plugin) Routes(r pact.Router) error {
r.Get("/{$}", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]string{
"message": "Hello from SummerCMS",
"plugin": p.ID(),
})
})
return nil
}
{{else}}
import "git.golem15.com/golem15/summercms/modules/pact"
var _ pact.HasRoutes = (*Plugin)(nil)
func (p *Plugin) Routes(pact.Router) error { return nil }
{{end}}{{end}}
{{define "go.mod"}}module {{.Module}}
{{.GoVersion}}
{{.Toolchain}}
require {{.Framework}} v0.0.0
{{if .Replace}}
replace {{.Framework}} => {{.Replace}}
{{end}}{{end}}
{{define "models/doc.go"}}// Package models holds GORM models for the {{.ID}} plugin.
package models
{{end}}
{{define "classes/doc.go"}}// Package classes holds services and hooks for the {{.ID}} plugin.
package classes
{{end}}
{{define "controllers/doc.go"}}// Package controllers holds HTTP handlers and admin controllers for the {{.ID}} plugin.
package controllers
{{end}}
{{define "console/doc.go"}}// Package console holds bonfire commands for the {{.ID}} plugin.
package console
{{end}}
{{define "jobs/doc.go"}}// Package jobs holds background jobs for the {{.ID}} plugin.
package jobs
{{end}}
{{define "middleware/doc.go"}}// Package middleware holds named HTTP middleware for the {{.ID}} plugin.
package middleware
{{end}}
{{define "updates/doc.go"}}// Package updates holds the gormigrate set for the {{.ID}} plugin.
package updates
{{end}}