blocks

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package blocks defines the fixed library of display building blocks used to compose a template's rendered layout. A Block is a discriminated union: Type selects the payload shape and Data holds the matching json.RawMessage, produced by a New* constructor and read back with the matching As* accessor.

Index

Constants

This section is empty.

Variables

View Source
var ErrBlockTypeMismatch = errors.New("block type mismatch")

Functions

This section is empty.

Types

type Block

type Block struct {
	Type BlockType       `json:"type"`
	Data json.RawMessage `json:"data"`
}

Block is a discriminated union over the display building blocks. Data holds the payload matching Type, as json.RawMessage.

func NewChart

func NewChart(
	kind string,
	labels []string,
	values []float64,
) Block

func NewCode

func NewCode(lang, content string) Block

func NewHeading

func NewHeading(level int, text string) Block

func NewKeyValue

func NewKeyValue(pairs []KVPair) Block

func NewList

func NewList(ordered bool, items []string) Block

func NewMetric

func NewMetric(label, value, unit string) Block

func NewTable

func NewTable(
	columns []string,
	rows [][]string,
	footer []string,
) Block

func NewText

func NewText(markdown string) Block

func (Block) AsChart

func (b Block) AsChart() (Chart, error)

func (Block) AsCode

func (b Block) AsCode() (Code, error)

func (Block) AsHeading

func (b Block) AsHeading() (Heading, error)

func (Block) AsKeyValue

func (b Block) AsKeyValue() (KeyValue, error)

func (Block) AsList

func (b Block) AsList() (List, error)

func (Block) AsMetric

func (b Block) AsMetric() (Metric, error)

func (Block) AsTable

func (b Block) AsTable() (Table, error)

func (Block) AsText

func (b Block) AsText() (Text, error)

type BlockType

type BlockType string

BlockType identifies which payload shape a Block's Data holds.

const (
	BlockTypeHeading  BlockType = "heading"
	BlockTypeText     BlockType = "text"
	BlockTypeList     BlockType = "list"
	BlockTypeTable    BlockType = "table"
	BlockTypeKeyValue BlockType = "keyvalue"
	BlockTypeMetric   BlockType = "metric"
	BlockTypeCode     BlockType = "code"
	BlockTypeChart    BlockType = "chart"
)

type Chart

type Chart struct {
	Kind   string    `json:"kind"`
	Labels []string  `json:"labels"`
	Values []float64 `json:"values"`
}

type Code

type Code struct {
	Lang    string `json:"lang"`
	Content string `json:"content"`
}

type Document

type Document = []Block

Document is an ordered sequence of Blocks composing a rendered layout.

type Heading

type Heading struct {
	Level int    `json:"level"`
	Text  string `json:"text"`
}

type KVPair

type KVPair struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type KeyValue

type KeyValue struct {
	Pairs []KVPair `json:"pairs"`
}

type List

type List struct {
	Ordered bool     `json:"ordered"`
	Items   []string `json:"items"`
}

type Metric

type Metric struct {
	Label string `json:"label"`
	Value string `json:"value"`
	Unit  string `json:"unit"`
}

type Table

type Table struct {
	Columns []string   `json:"columns"`
	Rows    [][]string `json:"rows"`
	Footer  []string   `json:"footer"`
}

type Text

type Text struct {
	Markdown string `json:"markdown"`
}

Jump to

Keyboard shortcuts

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