template

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package template contains methods that will template go text/templates files that may contain sjs snippets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Global         any
	Local          any
	GlobalComputed goja.Value
	LocalComputed  goja.Value
}

Context is the context that is passed templates or js.

type ReadFunc

type ReadFunc func(string) ([]byte, error)

ReadFunc represents a function that reads a file.

type Templator

type Templator struct {
	WriteFunc WriteFunc
	ReadFunc  ReadFunc
	TmplFuncs map[string]any
	// contains filtered or unexported fields
}

Templator extends the go text/template package to allow for sjs snippets.

func (*Templator) SetContextData added in v0.4.0

func (t *Templator) SetContextData(contextData any, globalComputed goja.Value)

SetContextData allows the setting of global context for templating.

func (*Templator) TemplateFile

func (t *Templator) TemplateFile(vm VM, templateFile, outFile string, inputData any) error

TemplateFile will template a file and write the output to outFile.

func (*Templator) TemplateString

func (t *Templator) TemplateString(vm VM, templatePath string, inputData any) (out string, err error)

TemplateString will template a string and return the output.

type VM

type VM interface {
	Get(name string) goja.Value
	Set(name string, value any) error
	Compile(name string, src string, strict bool) (*goja.Program, error)
	RunProgram(p *goja.Program) (result goja.Value, err error)
	RunString(script string) (result goja.Value, err error)
	GetObject(val goja.Value) *goja.Object
}

VM represents a virtual machine that can be used to run js.

type WriteFunc

type WriteFunc func(string, []byte) error

WriteFunc represents a function that writes a file.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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