template

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: Apache-2.0 Imports: 7 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
}

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
	ContextData interface{}
	TmplFuncs   map[string]any
}

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

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) (otto.Value, error)
	Set(name string, value interface{}) error
	Compile(filename string, src interface{}) (*otto.Script, error)
	Run(src interface{}) (otto.Value, error)
}

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