Documentation
¶
Overview ¶
Package codelet declares the exposed functions for go/template and starlark built-ins.
Index ¶
- func ToStarlarkModule(app *App) *starlarkstruct.Module
- func ToTemplateFuncmap(a *App) template.FuncMap
- type App
- func (a *App) GetPlugin(pluginName string) plugin.Plugin
- func (a *App) Include(templatePath string, data interface{}) (string, 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()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToStarlarkModule ¶
func ToStarlarkModule(app *App) *starlarkstruct.Module
ToStarlarkModule exposes the App's functions to starlarkstruct.Module.
The module provides the following functions:
- renderFile(filePath: str, templatePath: str, data: any) -> str
- loadValues() -> dict[str, any]
- getPlugin(pluginName: str) -> EeaaoPlugin
due to the limitation of interoperability between Go and Starlark, JSON encoding is used internally.
For example, App.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 ¶
ToTemplateFuncmap converts the helper functions into a template.FuncMap for use with template.
The resulting FuncMap includes the following functions:
- renderFile: App.RenderFile
- loadValues: App.LoadValues
- include: App.Include
- getPlugin: App.GetPlugin
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) Include ¶
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)
func (*App) LoadValues ¶
LoadValues returns the values data from codelet's default values.yaml file and given values file.
func (*App) Render ¶
Render renders the templates. internally, it just runs `render.star` file in the CodeletDir
func (*App) RenderFile ¶
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.