scaffold

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2019 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package scaffold parses JSON data, matches it to known template components and controls rendering of the resultant image.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseColour

type BaseColour struct {
	// Red is the red channel.
	Red string `json:"R"`
	// Green is the green channel.
	Green string `json:"G"`
	// Blue is the blue channel.
	Blue string `json:"B"`
	// Alpha is the alpha channel.
	Alpha string `json:"A"`
}

BaseColour is the template format of the base colour settings.

type BaseImage

type BaseImage struct {
	// FileName is the file to load the base image from.
	FileName string `json:"fileName"`
	// Data is the base64-encoded data to load the base image from.
	Data string `json:"data"`
	// BaseColour is the pure colour to use as a base image.
	BaseColour BaseColour `json:"baseColour"`
	// BaseWidth is the width to use for pure colour.
	BaseWidth string `json:"width"`
	// BaseHeight is the height to use for pure colour.
	BaseHeight string `json:"height"`
	// PPI is the pixels per inch to set in the canvas.
	PPI string `json:"ppi"`
}

BaseImage is the template format of the base image settings.

type Builder

type Builder interface {
	GetCanvas() render.Canvas
	SetCanvas(newCanvas render.Canvas) Builder
	GetComponents() []render.Component
	SetComponents(components []ToggleableComponent) Builder
	GetNamedPropertiesList() render.NamedProperties
	SetNamedProperties(properties render.NamedProperties) (Builder, error)
	ApplyComponents() (Builder, error)
	LoadComponentsFile(fileName string) (Builder, error)
	LoadComponentsData(fileData []byte) (Builder, error)
	WriteToBMP() ([]byte, error)
}

Builder manipulates Canvas objects and outputs to a bitmap.

func NewBuilder

func NewBuilder(fs vfs.FileSystem) Builder

NewBuilder generates a new ImageBuilder with an internal canvas of the specified width and height, and optionally the specified starting colour. No provided colour will result in defaults for Image.

type ComponentTemplate

type ComponentTemplate struct {
	// Type is the type of the component, such as Rectangle or Barcode.
	Type string `json:"type"`
	// Conditional is the condition(s) on which the component will render.
	Conditional render.ComponentConditional `json:"conditional"`
	// Properties are the raw, unprocessed JSON data for the component to parse
	Properties json.RawMessage `json:"properties"`
}

ComponentTemplate is a partial unmarshalled Component, with its properties left in raw form to be handled by each known type of Component.

type ImageBuilder

type ImageBuilder struct {
	// Canvas is the canvas on which the image is drawn.
	Canvas render.Canvas
	// Components are the components to render.
	Components []ToggleableComponent
	// NamedProperties are the user/application defined variables
	NamedProperties render.NamedProperties
	// contains filtered or unexported fields
}

ImageBuilder uses golang's native Image package to implement the Builder interface.

func (ImageBuilder) ApplyComponents

func (builder ImageBuilder) ApplyComponents() (Builder, error)

ApplyComponents iterates over the internal Component array, applying each in turn to the Canvas.

func (ImageBuilder) GetCanvas

func (builder ImageBuilder) GetCanvas() render.Canvas

GetCanvas returns the internal Canvas object.

func (ImageBuilder) GetComponents

func (builder ImageBuilder) GetComponents() []render.Component

GetComponents gets the internal Component array.

func (ImageBuilder) GetNamedPropertiesList

func (builder ImageBuilder) GetNamedPropertiesList() render.NamedProperties

GetNamedPropertiesList returns the list of named properties in the builder object.

func (ImageBuilder) LoadComponentsData

func (builder ImageBuilder) LoadComponentsData(fileData []byte) (Builder, error)

LoadComponentsData sets the internal component array based on the contents of the specified JSON data.

func (ImageBuilder) LoadComponentsFile

func (builder ImageBuilder) LoadComponentsFile(fileName string) (Builder, error)

LoadComponentsFile sets the internal Component array based on the contents of the specified JSON file.

func (ImageBuilder) SetCanvas

func (builder ImageBuilder) SetCanvas(newCanvas render.Canvas) Builder

SetCanvas sets the internal Canvas object.

func (ImageBuilder) SetComponents

func (builder ImageBuilder) SetComponents(components []ToggleableComponent) Builder

SetComponents sets the internal Component array.

func (ImageBuilder) SetNamedProperties

func (builder ImageBuilder) SetNamedProperties(properties render.NamedProperties) (Builder, error)

SetNamedProperties sets the values of names properties in all components and conditionals in the builder.

func (ImageBuilder) WriteToBMP

func (builder ImageBuilder) WriteToBMP() ([]byte, error)

WriteToBMP outputs the contents of the builder to a BMP byte array.

type Template

type Template struct {
	// BaseImage is the bottom layer of the canvas, on which to draw everything else.
	BaseImage BaseImage `json:"baseImage"`
	// Components are all other elements to be rendered.
	Components []ComponentTemplate `json:"components"`
}

Template is the format of the JSON file used as a template for building images. See samples.json for examples, each element in the samples array is a complete and valid template object.

type ToggleableComponent

type ToggleableComponent struct {
	// Conditional is the condition(s) on which the component will render.
	Conditional render.ComponentConditional
	// Component is the component to render.
	Component render.Component
}

ToggleableComponent is a component with its conditional.

Jump to

Keyboard shortcuts

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