- 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
161 lines
4.1 KiB
Cheetah
161 lines
4.1 KiB
Cheetah
{{define "model.go"}}//summer:make model
|
|
|
|
package models
|
|
|
|
import "time"
|
|
|
|
// {{.Ident}} is a generated GORM model for {{.PluginID}}.
|
|
type {{.Ident}} struct {
|
|
ID uint `gorm:"primaryKey"`
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
func ({{.Ident}}) TableName() string { return {{printf "%q" .Table}} }
|
|
{{end}}
|
|
|
|
{{define "migration.go"}}//summer:make migration
|
|
|
|
package updates
|
|
|
|
import (
|
|
"github.com/go-gormigrate/gormigrate/v2"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// {{.Func}} returns the {{.MigrationID}} gormigrate entry.
|
|
func {{.Func}}() *gormigrate.Migration {
|
|
return &gormigrate.Migration{
|
|
ID: {{printf "%q" .MigrationID}},
|
|
Migrate: func(tx *gorm.DB) error {
|
|
return tx.Exec({{printf "%q" .UpSQL}}).Error
|
|
},
|
|
Rollback: func(tx *gorm.DB) error {
|
|
return tx.Exec({{printf "%q" .DownSQL}}).Error
|
|
},
|
|
}
|
|
}
|
|
{{end}}
|
|
|
|
{{define "command.go"}}//summer:make command
|
|
|
|
package console
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/backpack"
|
|
"git.golem15.com/golem15/summercms/modules/bonfire"
|
|
)
|
|
|
|
// {{.Func}} returns the {{.CommandName}} console command. app is the
|
|
// application the plugin kept from Boot: it gives the command the config and
|
|
// the services plugins publish (app.Lookup).
|
|
func {{.Func}}(app *backpack.App) bonfire.Command {
|
|
return bonfire.Command{
|
|
Name: {{printf "%q" .CommandName}},
|
|
Description: {{printf "%q" .Description}},
|
|
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
|
|
out.Printf({{printf "%q" .CommandName}} + "\n")
|
|
return nil
|
|
},
|
|
}
|
|
}
|
|
{{end}}
|
|
|
|
{{define "job.go"}}//summer:make job
|
|
|
|
package jobs
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/conga"
|
|
"git.golem15.com/golem15/summercms/modules/pact"
|
|
)
|
|
|
|
// {{.Ident}}Args is the typed payload for {{.Kind}}.
|
|
type {{.Ident}}Args struct{}
|
|
|
|
func ({{.Ident}}Args) Kind() string { return {{printf "%q" .Kind}} }
|
|
|
|
// {{.Func}} returns the {{.Kind}} job.
|
|
func {{.Func}}() pact.Job {
|
|
return conga.Job(func(ctx context.Context, args {{.Ident}}Args) error {
|
|
return nil
|
|
})
|
|
}
|
|
{{end}}
|
|
|
|
{{define "admin_controller.go"}}//summer:make admin-controller
|
|
|
|
package controllers
|
|
|
|
import "git.golem15.com/golem15/summercms/modules/pact"
|
|
|
|
var (
|
|
_ pact.AdminController = {{.Worker}}{}
|
|
_ pact.AdminRecordSource = {{.Worker}}{}
|
|
_ pact.AdminPermissioned = {{.Worker}}{}
|
|
)
|
|
|
|
type {{.Worker}} struct{}
|
|
|
|
func ({{.Worker}}) ID() string { return {{printf "%q" .Kind}} }
|
|
func ({{.Worker}}) ModelName() string { return {{printf "%q" .Ident}} }
|
|
func ({{.Worker}}) ConfigDir() string { return {{printf "%q" .ConfigDir}} }
|
|
|
|
// NewRecord returns the model the generic admin handlers query and fill.
|
|
// TODO: return a pointer to the plugin's model, such as &models.{{.Ident}}{}.
|
|
// Until then the list and every write answer 500, so nothing is exposed.
|
|
func ({{.Worker}}) NewRecord() any { return nil }
|
|
|
|
// RequiredPermissions is checked before any schema or record is served. Keep
|
|
// it: a controller without one is open to every administrator. Declare the
|
|
// code in the plugin's Permissions() (pact.HasPermissions), or the admin API
|
|
// refuses to start with an unknown-permission error that names this controller.
|
|
func ({{.Worker}}) RequiredPermissions() []string {
|
|
return []string{ {{printf "%q" .Permission}} }
|
|
}
|
|
|
|
// {{.Func}} returns the {{.Kind}} admin controller.
|
|
func {{.Func}}() pact.AdminController { return {{.Worker}}{} }
|
|
{{end}}
|
|
|
|
{{define "config_form.yaml"}}name: {{.Ident}}
|
|
form: ~/plugins/{{.PluginPath}}/models/{{.Snake}}/fields.yaml
|
|
modelClass: {{.Ident}}
|
|
defaultRedirect: {{.PluginPath}}/{{.Snake}}
|
|
|
|
create:
|
|
redirect: {{.PluginPath}}/{{.Snake}}/update/:id
|
|
redirectClose: {{.PluginPath}}/{{.Snake}}
|
|
|
|
update:
|
|
redirect: {{.PluginPath}}/{{.Snake}}
|
|
redirectClose: {{.PluginPath}}/{{.Snake}}
|
|
{{end}}
|
|
|
|
{{define "config_list.yaml"}}list: ~/plugins/{{.PluginPath}}/models/{{.Snake}}/columns.yaml
|
|
modelClass: {{.Ident}}
|
|
title: {{.Ident}}
|
|
recordsPerPage: 20
|
|
toolbar:
|
|
buttons: [create]
|
|
search:
|
|
prompt: backend::lang.list.search_prompt
|
|
{{end}}
|
|
|
|
{{define "fields.yaml"}}fields:
|
|
id:
|
|
label: ID
|
|
span: auto
|
|
type: number
|
|
{{end}}
|
|
|
|
{{define "columns.yaml"}}columns:
|
|
id:
|
|
label: ID
|
|
searchable: true
|
|
{{end}}
|