# README
Jet Template Engine for Go
Jet is a template engine developed to be easy to use, powerful, dynamic, yet secure and very fast.
- simple and familiar syntax
- supports template inheritance (
extends
) and composition (block
/yield
,import
,include
) - descriptive error messages with filename and line number
- auto-escaping
- simple C-like expressions
- very fast execution – Jet can execute templates faster than some pre-compiled template engines
- very light in terms of allocations and memory footprint
v6
Version 6 brings major improvements to the Go API. Make sure to read through the breaking changes before making the jump.
Docs
- Go API
- Syntax Reference
- Built-ins
- Wiki (some things are out of date)
Example application
An example to-do application is available in examples/todos. Clone the repository, then (in the repository root) do:
$ cd examples/todos; go run main.go
IntelliJ Plugin
If you use IntelliJ there is a plugin available at https://github.com/jhsx/GoJetPlugin. There is also a very good Go plugin for IntelliJ – see https://github.com/go-lang-plugin-org/go-lang-idea-plugin. GoJetPlugin + Go-lang-idea-plugin = happiness!
Contributing
All contributions are welcome – if you find a bug please report it.
Contributors
- José Santos (@jhsx)
- Daniel Lohse (@annismckenzie)
- Alexander Willing (@sauerbraten)
# Functions
InDevelopmentMode returns an option function that toggles development mode on, meaning the cache will always be bypassed and every template lookup will go to the loader.
IsEmptyTree reports whether this tree (node) is empty of everything but space.
NewInMemLoader return a new InMemLoader.
NewOSFileSystemLoader returns an initialized OSFileSystemLoader.
NewSet returns a new Set relying on loader.
WithCache returns an option function that sets the cache to use for template parsing results.
WithDelims returns an option function that sets the delimiters to the specified strings.
WithSafeWriter returns an option function that sets the escaping function to use when executing templates.
WithTemplateNameExtensions returns an option function that sets the extensions to try when looking up template names in the cache or loader.
# Constants
A non-control action such as a field evaluation.
No description provided by the author
No description provided by the author
A boolean constant.
No description provided by the author
A sequence of field accesses.
An element of a pipeline.
No description provided by the author
A field or method name.
An identifier; always a function name.
An if action.
NodeWith //A with action.
No description provided by the author
A list of Nodes.
No description provided by the author
No description provided by the author
An untyped nil constant.
No description provided by the author
A numerical constant.
No description provided by the author
A pipeline of commands.
A range action.
No description provided by the author
No description provided by the author
No description provided by the author
A string constant.
No description provided by the author
Plain text.
No description provided by the author
An underscore (discard in assignment, or slot in argument list for piped value).
No description provided by the author
# Structs
ActionNode holds an action (something bounded by delimiters).
AdditiveExprNode represents an add or subtract expression ex: expression ( '+' | '-' ) expression.
Arguments holds the arguments passed to jet.Func.
BlockNode represents a {{block }} action.
No description provided by the author
No description provided by the author
BoolNode holds a boolean constant.
BranchNode is the common representation of if, range, and with.
No description provided by the author
CallExprNode represents a call expression ex: expression '(' (expression (',' expression)* )? ')'.
ChainNode holds a term followed by a chain of field accesses (identifier starting with '.').
CommandNode holds a command (a pipeline inside an evaluating action).
ComparativeExprNode represents a comparative expression ex: expression ( '==' | '!=' ) expression.
FieldNode holds a field (identifier starting with '.').
IdentifierNode holds an identifier.
IfNode represents an {{if}} action and its commands.
IncludeNode represents a {{include }} action.
No description provided by the author
InMemLoader is a simple in-memory loader storing template contents in a simple map.
ListNode holds a sequence of nodes.
LogicalExprNode represents a boolean expression, 'and' or 'or' ex: expression ( '&&' | '||' ) expression.
MultiplicativeExprNode represents a multiplication, division, or module expression ex: expression ( '*' | '/' | '%' ) expression.
NilNode holds the special identifier 'nil' representing an untyped nil constant.
No description provided by the author
NotExprNode represents a negate expression ex: '!' expression.
NumberNode holds a number: signed or unsigned integer, float, or complex.
NumericComparativeExprNode represents a numeric comparative expression ex: expression ( '<' | '>' | '<=' | '>=' ) expression.
OSFileSystemLoader implements Loader interface using OS file system (os.File).
PipeNode holds a pipeline with optional declaration.
RangeNode represents a {{range}} action and its commands.
No description provided by the author
Runtime this type holds the state of the execution of an template.
Set is responsible to load, parse and cache templates.
SetNode represents a set action, ident( ',' ident)* '=' expression ( ',' expression )*.
No description provided by the author
StringNode holds a string constant.
Template is the representation of a single parsed template.
TernaryExprNod represents a ternary expression, ex: expression '?' expression ':' expression.
TextNode holds plain text.
No description provided by the author
UnderscoreNode is used for one of two things: - signals to discard the corresponding right side of an assignment - tells Jet where in a pipelined function call to inject the piped value.
YieldNode represents a {{yield}} action.
# Interfaces
Cache is the interface Jet uses to store and retrieve parsed templates.
No description provided by the author
Loader is a minimal interface required for loading templates.
No description provided by the author
Ranger describes an interface for types that iterate over something.
Renderer is used to detect if a value has its own rendering logic.
# Type aliases
Func function implementing this type is called directly, which is faster than calling through reflect.
NodeType identifies the type of a parse tree node.
Option is the type of option functions that can be used in NewSet().
Pos represents a byte position in the original input text from which this template was parsed.
RendererFunc func implementing interface Renderer.
SafeWriter is a function that writes bytes directly to the render output, without going through Jet's auto-escaping phase.
No description provided by the author