demokit

package
v0.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package demokit - the part of the module SDK a module's demo step uses (app install -demo, docs/modules/write-a-module.md): the step's registration, its texts by language, a block and a menu link of the core's, and the install transaction for the module's own ent client. Light like manifestkit: a manifest registers the step.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Content

func Content(env Env, fsys fs.FS, v any) error

Content reads the step's content into v: a demo set's for the module (app install -demo-set), else demo/<lang>.json of fsys (Load). A set's content has the format of the module's demo/<lang>.json.

func CreateComments

func CreateComments(ctx context.Context, env Env, nodeID int, list []Comment, at time.Time) (int, time.Time, error)

CreateComments adds the comments (and their replies) to node nodeID, from at on; it returns how many and the last one's time.

func CreateNode

func CreateNode(ctx context.Context, env Env, n Node) (int, error)

CreateNode creates a demo material of the module's content type.

func Driver

func Driver(env Env) dialect.Driver

Driver - the install transaction as an ent driver, for the module's own client (its generated NewClient(Driver(…))): its rows go in with the core's, seeing them, and nothing stays if the install fails.

func ImageFile

func ImageFile(ctx context.Context, env Env, rel string, w, h, i int, alt string, at time.Time) (int, error)

ImageFile draws a demo picture (palette i, w×h) at rel under the public files directory and stores its file row: its ID.

func IndexTerm

func IndexTerm(ctx context.Context, env Env, nodeID, tid int, at time.Time) error

IndexTerm files node nodeID under term tid (the terms index), at.

func Load

func Load(fsys fs.FS, lang string, v any) error

Load reads demo/<lang>.json of fsys into v (demo/en.json for a language without its own).

func MenuLink(ctx context.Context, env Env, menuID int, title, url string, nodeID, weight int) error

MenuLink adds a link to the menu (Env.MainMenu, Env.FooterMenu): to url, or to the node nodeID when url is "". Menu 0 (a demo set names none) - no link.

func PlacePlugin

func PlacePlugin(ctx context.Context, env Env, plugin manifestkit.PluginBlockID, config map[string]string, p Placement) error

PlacePlugin places the plugin block (the module's) with its settings.

func PlaceView

func PlaceView(ctx context.Context, env Env, v ViewBlock, p Placement) error

PlaceView creates the block View v (a list of content: say, the module's Views field and sort for a top list) and places it.

func Register

func Register(set string, run Step)

Register sets the module's demo step (its manifest's RegisterSteps).

func SetPicture

func SetPicture(ctx context.Context, env Env, rel, file, alt string, at time.Time) (int, error)

SetPicture stores a picture of the demo set's own - file, a path in its directory (a theme's demo/), as the set's content names it ({file: …}) - at rel under the public files directory with its file row: its ID. A JPEG, a PNG or a WebP.

func Term

func Term(ctx context.Context, env Env, vid int, name, description, path string, parent *int, weight int) (int, error)

Term creates a demo term of vocabulary vid (its address path; parent - nil for a top one): its ID.

func Vocabulary

func Vocabulary(ctx context.Context, env Env, name, slug, prefix string) (int, error)

Vocabulary creates a demo vocabulary (its terms' addresses under prefix): its ID.

Types

type Comment

type Comment = demo.Comment

Comment - a demo comment and its replies (CreateComments).

type Env

type Env struct {
	Lang      string
	CreatedBy int // the administrator
	// Users - the demo users by name, the authors of comments and votes.
	Users map[string]int
	// Articles - the demo articles' node IDs, the newest first.
	Articles []int
	// Theme - the block placement key of the site's theme.
	Theme string
	// MainMenu and FooterMenu - the IDs of the menus in the header and
	// the footer.
	MainMenu, FooterMenu int
	Now                  time.Time
	// contains filtered or unexported fields
}

Env - what a demo step works with: the site's language, the administrator, the demo users and articles, the theme, the menus; the core's rows it adds through this package's helpers (in the install's transaction).

func (Env) Node

func (env Env) Node(key string) (int, error)

Node - the ID of a demo set's node by its key (the keys its content names).

func (Env) User

func (env Env) User(name string) (int, error)

User - the ID of the demo user name.

type Node

type Node = demo.Node

Node - a demo material (CreateNode).

type Placement

type Placement = demo.Placement

Placement - where PlacePlugin and PlaceView put a block.

type Step

type Step func(ctx context.Context, env Env) error

Step - a module's demo step.

type ViewBlock

type ViewBlock = demo.ViewBlock

ViewBlock - a block View of content (PlaceView): its fields, filters and sorts, built-in or a module's ("<module>.<key>").

type ViewBlockField

type ViewBlockField = demo.ViewBlockField

ViewBlockField - a ViewBlock's field.

type ViewBlockFilter

type ViewBlockFilter = demo.ViewBlockFilter

ViewBlockFilter - a ViewBlock's filter.

type ViewBlockSort

type ViewBlockSort = demo.ViewBlockSort

ViewBlockSort - a ViewBlock's sort.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL