badgerenderer

package
Version: v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinTemplates = map[string]badgetemplate.BadgeTemplate{
	"builtin-standard-badge": &standard_badge.Template,
}

BuiltinTemplates is an index of all templates built into ./badges. They are ready to use with Renderer's CompileTemplate method.

View Source
var ErrFontNotFound = errors.New("the requested font was not found")
View Source
var ErrInvalidParams = errors.New("invalid parameters were provided to renderer")
View Source
var ErrTemplateExecutionFailed = errors.New("template execution failed")

Functions

This section is empty.

Types

type CompiledTemplate

type CompiledTemplate struct {
	Template  *template.Template
	ParamSpec paramspec.Tree
}

CompiledTemplate contains a compiled badge template and corresponding parameter specification

type Renderer

type Renderer struct {
	// The loaded fonts
	Fonts map[string]*sfnt.Font
}

The Renderer holds the configuration necessary to render badges

func (*Renderer) BuildTemplateFuncMap

func (r *Renderer) BuildTemplateFuncMap() template.FuncMap

BuildTemplateFuncMap builds the functions that are to be injected into templates when they're being compiled.

func (*Renderer) CompileDefaultTemplate

func (r *Renderer) CompileDefaultTemplate() *CompiledTemplate

CompileDefaultTemplate is a convenience function that compiles the built-in standard badge template against this renderer.

func (*Renderer) CompileTemplate

func (r *Renderer) CompileTemplate(input badgetemplate.BadgeTemplate) (*CompiledTemplate, error)

CompileTemplate compiles a badge template for later use with this Renderer's Render method.

func (*Renderer) Render

func (r *Renderer) Render(template *CompiledTemplate, parameters map[string]interface{}) (string, error)

Render renders a badge template using the Renderer's current configuration and the given parameters The parameters will be converted and validated against the compiled template's parameter specification prior to rendering. Note that the result's leading and trailing spaces will be trimmed.

Jump to

Keyboard shortcuts

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