templating

package
v1.0.1-0...-7180b55 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TemplateDefinitionMap = map[string]TemplateDefinition{}
View Source
var Templates map[string]*template.Template

Functions

func GetTemplateContextHash

func GetTemplateContextHash(templateContext any) string

func GetTemplateHash

func GetTemplateHash(template TemplateDefinition) string

func SaveStateFile

func SaveStateFile(path string, stateFile StateFile) error

Types

type Config

type Config struct {
	OutputPath string  `yaml:"output_path,omitempty"`
	FontPath   *string `yaml:"font_path,omitempty"`
	Covers     []Cover `yaml:"covers,omitempty"`
}

func LoadConfig

func LoadConfig(path string) (*Config, error)

type Cover

type Cover struct {
	Meta CoverMeta
	Data any
}

func (Cover) MarshalYAML

func (c Cover) MarshalYAML() (interface{}, error)

func (*Cover) UnmarshalYAML

func (c *Cover) UnmarshalYAML(value *yaml.Node) error

type CoverMeta

type CoverMeta struct {
	Name     string `yaml:"name"`
	Template string `yaml:"template"`
}

type GradientTemplate

type GradientTemplate struct{}

func (*GradientTemplate) DecodeConfig

func (t *GradientTemplate) DecodeConfig(value *yaml.Node) (any, error)

func (*GradientTemplate) ID

func (t *GradientTemplate) ID() string

func (*GradientTemplate) TemplateContext

func (t *GradientTemplate) TemplateContext(cover Cover) any

type GradientTemplateConfig

type GradientTemplateConfig struct {
	HeadingLines *[]string `yaml:"heading_lines,omitempty"`
	Title        *string   `yaml:"title,omitempty"`
	Subtitle     *string   `yaml:"subtitle,omitempty"`
	Font         *string   `yaml:"font,omitempty"`
}

type GradientTemplateContext

type GradientTemplateContext struct {
	GradientTemplateConfig

	Colour1 string
	Colour2 string
}

type State

type State struct {
	DataHash     string `yaml:"data_hash"`
	TemplateHash string `yaml:"template_hash"`
}

func ComputeState

func ComputeState(template TemplateDefinition, cover Cover) State

type StateFile

type StateFile struct {
	GeneratedCovers map[string]State `yaml:"generated_covers"`
}

func LoadStateFile

func LoadStateFile(path string) (StateFile, error)

type TemplateDefinition

type TemplateDefinition interface {
	// ID returns a unique identifier for the template.
	// The value should match the filename for the template, without the .svg extension.
	ID() string

	// DecodeConfig decodes the config for the template from the given yaml.Node.
	// The yaml.Node will be a mapping node.
	DecodeConfig(value *yaml.Node) (any, error)

	// TemplateContext returns the data to be passed to the template for a given cover.
	TemplateContext(cover Cover) any
}

Jump to

Keyboard shortcuts

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