Documentation
¶
Overview ¶
Package codelet declares the exposed functions for go/template and starlark built-ins.
Index ¶
- func ToStarlarkModule(h HelperFuncs) *starlarkstruct.Module
- func ToTemplateFuncmap(h HelperFuncs) template.FuncMap
- type App
- func (a *App) Include(templatePath string, data interface{}) (string, error)
- func (a *App) LoadSpecFile(pluginName string, filePath string) (plugin.SpecData, error)
- func (a *App) LoadSpecsGlob(pluginName string, glob string) (map[string]plugin.SpecData, error)
- func (a *App) LoadValues() map[string]any
- func (a *App) Render() error
- func (a *App) RenderFile(filePath string, templatePath string, data any) (dst string, err error)
- func (a *App) RunShell()
- type HelperFuncs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToStarlarkModule ¶
func ToStarlarkModule(h HelperFuncs) *starlarkstruct.Module
ToStarlarkModule exposes the helper functions to starlarkstruct.Module.
The module provides the following functions:
- loadSpecFile(pluginName: str, filepath: str) -> any
- loadSpecsGlob(pluginName: str, glob: str) -> dict[str, any]
- renderFile(filePath: str, templatePath: str, data: any) -> str
- loadValues() -> dict[str, any]
due to the limitation of interoperability between Go and Starlark, JSON encoding is used internally.
For example, HelperFuncs.LoadValues() returns a map[string]any. When `eeaao_codegen.loadValues` is called in starlark script, the map[string]any is first encoded using json.Marshal and then decoded as starlark.Dict by `json.decode`.
func ToTemplateFuncmap ¶
func ToTemplateFuncmap(h HelperFuncs) template.FuncMap
ToTemplateFuncmap converts the helper functions into a template.FuncMap for use with template.
The resulting FuncMap includes the following functions:
- loadSpecFile: HelperFuncs.LoadSpecFile
- loadSpecsGlob: HelperFuncs.LoadSpecsGlob
- renderFile: HelperFuncs.RenderFile
- loadValues: HelperFuncs.LoadValues
Additionally, it incorporates the sprig.FuncMap for extended functionality.
Types ¶
type App ¶
type App struct {
OutDir string
CodeletDir string
Values map[string]any
// contains filtered or unexported fields
}
func NewApp ¶
NewApp creates a new App instance specDir: directory for specifications outDir: directory for output codeletDir: directory for codelet valuesFile: file path of external values file. if empty, it will be ignored.
func (*App) LoadSpecFile ¶
func (*App) LoadSpecsGlob ¶
func (*App) LoadValues ¶
func (*App) Render ¶
Render renders the templates. internally, it just runs `render.star` file in the CodeletDir
func (*App) RenderFile ¶
type HelperFuncs ¶
type HelperFuncs interface {
// LoadSpecFile loads plugin.SpecData from filePath with plugin of pluginName
// filePath is relative path from spec directory
LoadSpecFile(pluginName string, filePath string) (plugin.SpecData, error)
// LoadSpecsGlob loads specs from the given glob pattern in the spec directory.
// pluginName: the plugin name to load the specs
// glob: the glob pattern to search for specs
// returns a map of spec file path and spec content as json encoded string.
LoadSpecsGlob(pluginName string, glob string) (specs map[string]plugin.SpecData, err error)
// RenderFile renders a file with the given template and data
// filePath: the file path to render. The path is relative to the output directory.
// templatePath: the template path. The path is relative to the ${codeletdir}/templates directory.
// data: the data to render
// returns the destination file path.
RenderFile(filePath string, templatePath string, data any) (dst string, err error)
// LoadValues returns the values data from codelet's default values.yaml file and given values file.
LoadValues() (config map[string]any)
// Include renders a template with the given data.
//
// Drop-in replacement for template pipeline, but with a string return value so that it can be treated as a string in the template.
//
// Inspired by [helm include function](https://helm.sh/docs/chart_template_guide/named_templates/#the-include-function)
Include(templatePath string, data interface{}) (string, error)
}
HelperFuncs defines the helper functions for codelet. The functions should be exposed to go/template and starlark built-ins for codelet.