soyjs

package
v0.0.0-...-21d471c Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2015 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package soyjs compiles Soy to javascript.

It fulfills the same interface as the javascript produced by the official Soy compiler and should work as a drop-in replacement. https://developers.google.com/closure/templates/docs/javascript_usage

It is presently alpha quality. See ../TODO for unimplemented features.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("file not found")
View Source
var Funcs = map[string]Func{
	"isNonnull":     {funcIsNonnull, []int{1}},
	"length":        {funcLength, []int{1}},
	"keys":          {builtinFunc("getMapKeys"), []int{1}},
	"augmentMap":    {builtinFunc("augmentMap"), []int{2}},
	"round":         {funcRound, []int{1, 2}},
	"floor":         {funcFloor, []int{1}},
	"ceiling":       {funcCeiling, []int{1}},
	"min":           {funcMin, []int{2}},
	"max":           {funcMax, []int{2}},
	"randomInt":     {funcRandomInt, []int{1}},
	"strContains":   {funcStrContains, []int{2}},
	"hasData":       {funcHasData, []int{0}},
	"bidiGlobalDir": {funcBidiGlobalDir, []int{0}},
	"bidiDirAttr":   {funcBidiDirAttr, []int{0}},
	"bidiStartEdge": {funcBidiStartEdge, []int{0}},
	"bidiEndEdge":   {funcBidiEndEdge, []int{0}},
}

Funcs contains the available soy functions. Callers may add custom functions to this map.

Functions

func Write

func Write(out io.Writer, node ast.Node, options Options) (err error)

Write writes the javascript represented by the given node to the given writer. The first error encountered is returned.

Types

type Func

type Func struct {
	Apply           func(js JSWriter, args []ast.Node)
	ValidArgLengths []int
}

Func represents a soy function that may invoked within a template.

type Generator

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

Generator provides an interface to a template registry capable of generating javascript to execute the embodied templates. The generated javascript requires lib/soyutils.js to already have been loaded.

func NewGenerator

func NewGenerator(registry *template.Registry) *Generator

NewGenerator returns a new javascript generator capable of producing javascript for the templates contained in the given registry.

func (*Generator) WriteFile

func (gen *Generator) WriteFile(out io.Writer, filename string) error

WriteFile generates javascript corresponding to the soy file of the given name.

type JSWriter

type JSWriter interface {
	// Write writes the given arguments into the generated javascript.  It is
	// recommended to only pass strings and ast.Nodes to Write. Other types
	// are printed using their default string representation (fmt.Sprintf("%v")).
	Write(...interface{})
}

JSWriter is provided to functions to write to the generated javascript.

type Options

type Options struct{}

Options for js source generation.

Jump to

Keyboard shortcuts

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