renderer

package
v0.94.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 17 Imported by: 1 module, 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 renderer defines renderer interfaces used to format analyzed proposals.

Implementing a Renderer

A renderer must implement:

  • ID() string: unique renderer identifier.
  • RenderTo(io.Writer, RenderRequest, AnalyzedProposal) error

Example custom plain-text renderer:

import (
	"fmt"
	"io"

	"github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalanalysis"
	"github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalanalysis/renderer"
)

type PlainRenderer struct{}

func (PlainRenderer) ID() string {
	return "plain"
}

func (PlainRenderer) RenderTo(
	w io.Writer,
	req renderer.RenderRequest,
	proposal renderer.AnalyzedProposal,
) error {
	if _, err := fmt.Fprintf(
		w,
		"domain=%s env=%s batches=%d\n",
		req.Domain,
		req.EnvironmentName,
		len(proposal.BatchOperations()),
	); err != nil {
		return err
	}

	for _, batch := range proposal.BatchOperations() {
		if _, err := fmt.Fprintf(
			w,
			"- chain=%d calls=%d\n",
			batch.ChainSelector(),
			len(batch.Calls()),
		); err != nil {
			return err
		}
	}

	return nil
}

Registering with the engine

eng := proposalanalysis.NewAnalyzerEngine()
if err := eng.RegisterRenderer(PlainRenderer{}); err != nil {
	return err
}

To render output, call `eng.RenderTo(...)` with the renderer ID and a `renderer.RenderRequest`.

Index

Constants

View Source
const IDMarkdown = "markdown"

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalyzedBatchOperation added in v0.85.1

type AnalyzedBatchOperation = analyzer.AnalyzedBatchOperation

Analyzed proposal graph types consumed by renderers.

type AnalyzedBatchOperationNode added in v0.85.1

type AnalyzedBatchOperationNode = analyzer.AnalyzedBatchOperationNode

Analyzed proposal graph types consumed by renderers.

func NewAnalyzedBatchOperationNode added in v0.85.1

func NewAnalyzedBatchOperationNode(chainSelector uint64, calls AnalyzedCalls) *AnalyzedBatchOperationNode

type AnalyzedBatchOperations added in v0.85.1

type AnalyzedBatchOperations = analyzer.AnalyzedBatchOperations

Analyzed proposal graph types consumed by renderers.

type AnalyzedCall added in v0.85.1

type AnalyzedCall = analyzer.AnalyzedCall

Analyzed proposal graph types consumed by renderers.

type AnalyzedCallNode added in v0.85.1

type AnalyzedCallNode = analyzer.AnalyzedCallNode

Analyzed proposal graph types consumed by renderers.

func NewAnalyzedCallNode added in v0.85.1

func NewAnalyzedCallNode(
	to string,
	name string,
	inputs AnalyzedParameters,
	outputs AnalyzedParameters,
	data []byte,
	contractType string,
	contractVersion string,
	additional map[string]any,
) *AnalyzedCallNode

type AnalyzedCalls added in v0.85.1

type AnalyzedCalls = analyzer.AnalyzedCalls

Analyzed proposal graph types consumed by renderers.

type AnalyzedParameter added in v0.85.1

type AnalyzedParameter = analyzer.AnalyzedParameter

Analyzed proposal graph types consumed by renderers.

type AnalyzedParameterNode added in v0.85.1

type AnalyzedParameterNode = analyzer.AnalyzedParameterNode

Analyzed proposal graph types consumed by renderers.

func NewAnalyzedParameterNode added in v0.85.1

func NewAnalyzedParameterNode(name, atype string, value any) *AnalyzedParameterNode

type AnalyzedParameters added in v0.85.1

type AnalyzedParameters = analyzer.AnalyzedParameters

Analyzed proposal graph types consumed by renderers.

type AnalyzedProposal added in v0.85.1

type AnalyzedProposal = analyzer.AnalyzedProposal

Analyzed proposal graph types consumed by renderers.

type AnalyzedProposalNode added in v0.85.1

type AnalyzedProposalNode = analyzer.AnalyzedProposalNode

Analyzed proposal graph types consumed by renderers.

func NewAnalyzedProposalNode added in v0.85.1

func NewAnalyzedProposalNode(batchOps AnalyzedBatchOperations) *AnalyzedProposalNode

type Option added in v0.84.0

type Option func(*config)

Option configures a TemplateRenderer.

func WithTemplateDir added in v0.84.0

func WithTemplateDir(dir string) Option

WithTemplateDir loads templates from a filesystem directory instead of the embedded defaults. The directory should contain *.tmpl files whose {{define}} names match the default set: proposal, batchOperation, call, parameter, annotations.

func WithTemplateFuncs added in v0.84.0

func WithTemplateFuncs(funcs template.FuncMap) Option

WithTemplateFuncs adds extra template functions to the renderer's func map. These are merged with the built-in functions; caller-provided functions take precedence over built-ins if keys collide.

func WithTemplates added in v0.84.0

func WithTemplates(templates map[string]string) Option

WithTemplates provides in-memory template overrides keyed by any name. Each value must contain a valid {{define "name"}} block -- the key itself is used only as a template set label and does not need to match the define name. Useful for testing or programmatic template generation.

type Registry added in v0.81.0

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages renderer registration and lookup

func NewRegistry added in v0.81.0

func NewRegistry() *Registry

NewRegistry creates a new renderer registry

func (*Registry) Get added in v0.81.0

func (r *Registry) Get(id string) (Renderer, bool)

Get retrieves a renderer by ID

func (*Registry) List added in v0.81.0

func (r *Registry) List() []string

List returns all registered renderer IDs

func (*Registry) Register added in v0.81.0

func (r *Registry) Register(renderer Renderer) error

Register adds a renderer to the registry. Returns an error if: - renderer is nil - renderer ID is empty - a renderer with the same ID is already registered

type RenderRequest

type RenderRequest struct {
	Domain          string
	EnvironmentName string
}

RenderRequest encapsulates the domain and environment name

type Renderer

type Renderer interface {
	ID() string
	RenderTo(w io.Writer, req RenderRequest, proposal AnalyzedProposal) error
}

Renderer transforms an AnalyzedProposal into a specific output format

type TemplateRenderer added in v0.84.0

type TemplateRenderer struct {
	// contains filtered or unexported fields
}

TemplateRenderer renders an AnalyzedProposal using Go text/template.

func NewMarkdownRenderer added in v0.84.0

func NewMarkdownRenderer(opts ...Option) (*TemplateRenderer, error)

NewMarkdownRenderer creates a TemplateRenderer with embedded markdown templates.

func (*TemplateRenderer) ID added in v0.84.0

func (r *TemplateRenderer) ID() string

func (*TemplateRenderer) RenderTo added in v0.84.0

func (r *TemplateRenderer) RenderTo(w io.Writer, req RenderRequest, proposal AnalyzedProposal) error

Jump to

Keyboard shortcuts

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