templates

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package templates defines the Template contract used by the engine to render a request into one of the supported output formats. The concrete templates (classic, repository) implement this interface from their own packages; the registry below is how they advertise themselves to the engine.

Index

Constants

This section is empty.

Variables

View Source
var AllowedFormats = map[string]struct{}{
	"svg":  {},
	"png":  {},
	"jpeg": {},
	"json": {},
}

AllowedFormats is the M1 set of output formats. terminal/markdown templates are NOT adopted in this spec (constitution principle III).

Functions

func CheckAccount

func CheckAccount(meta *config.TemplateMetadata, account string) error

CheckAccount returns nil when account is in meta.Supports, or an InputError otherwise. Templates that need additional shape checks (e.g. "repository" template requires q[repo]) layer their own logic on top of this helper.

func CheckFormat

func CheckFormat(meta *config.TemplateMetadata, format string) error

CheckFormat returns an UnsupportedFormatError when format is not in the supported set declared by metadata. Templates may invoke this from their own Check methods to share the validation.

func Each

func Each(fn func(name string, t Template) error) error

Each iterates registered templates in name-sorted order.

func Register

func Register(t Template)

Register adds t to the registry. Duplicate names panic, matching the plugin registry's contract.

func Reset

func Reset()

Reset clears the registry. Tests only.

Types

type PartialContext

type PartialContext struct {
	Settings *config.Settings
	Inputs   map[string]any
	Logger   *slog.Logger
	Data     *plugins.Data
	Metadata *config.MetadataLoader
}

PartialContext carries the data a partial needs to render its slice of the SVG/Markdown output. Helpers (octicon/twemoji/gemoji) land in M3; the field is nil-safe for M1 callers.

type PartialFunc

type PartialFunc func(ctx context.Context, pc *PartialContext) (string, error)

PartialFunc is the signature each partial (header, activity, repositories, ...) implements. Functions are meant to be idempotent.

type Template

type Template interface {
	Name() string
	Metadata() *config.TemplateMetadata
	FS() fs.FS
	Check(q map[string]any, account, format string) error
	Run(ctx context.Context, pc *PartialContext) (string, error)
}

Template is the contract every renderer implements.

func Get

func Get(name string) (Template, bool)

Get returns the registered template by name.

func MustGet

func MustGet(name string) (Template, error)

MustGet returns the template or a *NotFoundError so callers can branch with errors.As. Used by engine.Compute (T057).

Directories

Path Synopsis
Package classic implements the M2 "classic" template — the default upstream GitHub-visual-identity SVG layout.
Package classic implements the M2 "classic" template — the default upstream GitHub-visual-identity SVG layout.
partials
Package partials hosts the partial functions assembled by the classic template.
Package partials hosts the partial functions assembled by the classic template.
Package repository implements the M7 "repository" template — the upstream-equivalent SVG layout focused on a single repository instead of a user profile.
Package repository implements the M7 "repository" template — the upstream-equivalent SVG layout focused on a single repository instead of a user profile.
partials
Package partials hosts the repository-template-specific partials the M7 layout needs.
Package partials hosts the repository-template-specific partials the M7 layout needs.

Jump to

Keyboard shortcuts

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