Documentation
¶
Index ¶
- Constants
- Variables
- func AddRenderDiagnosticVMHelperTiming(ctx hctx.Context, name string, duration time.Duration)
- func AddRenderDiagnosticVMPartialTiming(ctx hctx.Context, name string, duration time.Duration)
- func BuffaloRenderer(input string, data map[string]interface{}, helpers map[string]interface{}) (string, error)
- func BuffaloRendererWithContext(input string, data map[string]interface{}, helpers map[string]interface{}, ...) (string, error)
- func CachePunchHoleSkeleton(filename string, ctx hctx.Context, skeleton string, holes []HoleMarker, ...)
- func CachePunchHoleSkeletonWithSource(filename string, ctx hctx.Context, skeleton string, holes []HoleMarker, ...)
- func CacheVMBytecode(filename string, ctx hctx.Context, program *ast.Program, bytecode interface{})
- func CacheVMBytecodeForCleanFilename(filename string, program *ast.Program, bytecode interface{})
- func CacheVMBytecodeForCleanFilenameWithSource(filename string, program *ast.Program, bytecode interface{}, source string)
- func CacheVMBytecodeForFilename(filename string, program *ast.Program, bytecode interface{})
- func CacheVMBytecodeForFilenameWithSource(filename string, program *ast.Program, bytecode interface{}, source string)
- func CachedASTProgram(filename string, ctx hctx.Context) (*ast.Program, bool)
- func CachedASTProgramWithSource(filename string, ctx hctx.Context, source string) (*ast.Program, bool)
- func CachedVMBytecode(filename string, ctx hctx.Context) (interface{}, bool)
- func CachedVMBytecodeForCleanFilename(filename string) (interface{}, bool)
- func CachedVMBytecodeForCleanFilenameWithSource(filename string, source string) (interface{}, bool)
- func CachedVMBytecodeForFilename(filename string) (interface{}, bool)
- func CachedVMBytecodeForFilenameWithSource(filename string, source string) (interface{}, bool)
- func ClearTemplateCache()
- func DisableRenderVMHotspotDiagnostics(ctx hctx.Context)
- func EnableRenderVMHotspotDiagnostics(ctx hctx.Context)
- func FillPunchHoles(rendered string, holes []HoleMarker) (string, error)
- func GenerateASTKey(filename string) string
- func GenerateASTKeyFromCleanFilename(cleanFilename string) string
- func GetPunchHoleConcurrencyLimit() int
- func GroupByHelper(size int, underlying interface{}) (*groupBy, error)
- func InterpreterPartialRenderEnabled(ctx hctx.Context) bool
- func IsHoleRender(ctx hctx.Context) bool
- func IsPlushTemplateFile(filename string) bool
- func IsPunchHoleCacheExpired(err error) bool
- func IsVMBytecodeCacheableTemplateFile(filename string) bool
- func PartialHelper(name string, data map[string]interface{}, help HelperContext) (template.HTML, error)
- func PlushCacheSetup(ts TemplateCache)
- func PunchHoleMarkerName(index int) string
- func PunchHoleTemplateFilename(ctx hctx.Context) string
- func RegisterVMRenderer(renderer RenderFunc)
- func Render(input string, ctx hctx.Context) (string, error)
- func RenderDiagnosticsRootActive(ctx hctx.Context) bool
- func RenderFromPunchHoleCache(filename string, ctx hctx.Context) (string, error)
- func RenderFromPunchHoleCacheWithSource(filename string, source string, ctx hctx.Context) (string, error)
- func RenderInterpreter(input string, ctx hctx.Context) (string, error)
- func RenderR(input io.Reader, ctx hctx.Context) (string, error)
- func RenderVMHotspotDiagnosticsEnabled(ctx hctx.Context) bool
- func RenderWithBudget(input string, limit int64, ctx *Context) (string, error)
- func RenderWithBudgetConfig(input string, limit int64, costs BudgetCosts, ctx *Context) (string, error)
- func RunScript(input string, ctx hctx.Context) error
- func SetPunchHoleConcurrencyLimit(limit int) int
- func SetRenderDiagnostics(ctx hctx.Context, diagnostics RenderDiagnostics)
- func SetRenderDiagnosticsRootActive(ctx hctx.Context, active bool) func()
- func SetRenderVMHotspotDiagnostics(ctx hctx.Context, enabled bool)
- func SetVMGenericFallback(enabled bool) bool
- func UpdateRenderDiagnostics(ctx hctx.Context, update func(*RenderDiagnostics))
- func UpdateRenderDiagnosticsForTemplate(ctx hctx.Context, filename string, update func(*RenderDiagnostics))
- func VMGenericFallbackEnabled() bool
- type Budget
- func (b *Budget) Costs() BudgetCosts
- func (b *Budget) Remaining() int64
- func (b *Budget) SpendAssignment() error
- func (b *Budget) SpendCondition() error
- func (b *Budget) SpendFilter() error
- func (b *Budget) SpendFunctionCall(name string) error
- func (b *Budget) SpendHelperCall() error
- func (b *Budget) SpendLoop() error
- func (b *Budget) SpendObjectTraversal(segments int) error
- func (b *Budget) SpendSubRender() error
- func (b *Budget) Stats() BudgetStats
- func (b *Budget) Used() int64
- func (b *Budget) WithCosts(costs BudgetCosts) *Budget
- type BudgetCosts
- type BudgetStats
- type Context
- func (c *Context) Budget() *Budget
- func (c *Context) Has(key string) bool
- func (c *Context) InternID(key string) int
- func (c *Context) InternIDs(keys []string, ids []int)
- func (c *Context) Lookup(key string) (interface{}, bool)
- func (c *Context) LookupID(id int) (interface{}, bool)
- func (c *Context) New() hctx.Context
- func (c *Context) Set(key string, value interface{})
- func (c *Context) SetID(id int, value interface{})
- func (c *Context) Update(key string, value interface{}) bool
- func (c *Context) UpdateID(id int, value interface{}) bool
- func (c *Context) Value(key interface{}) interface{}
- func (c *Context) WithBudget(b *Budget) *Context
- type ErrUnknownIdentifier
- type HTMLer
- type HelperContext
- type HoleMarker
- func FinalizePunchHolePositions(rendered string, holes []HoleMarker) []HoleMarker
- func NewHoleMarker(markerName, input string, start, end int) HoleMarker
- func RenderPunchHolesConcurrently(holes []HoleMarker, ctx hctx.Context) []HoleMarker
- func RenderPunchHolesConcurrentlyWith(holes []HoleMarker, ctx hctx.Context, ...) []HoleMarker
- type InternTable
- type Iterator
- type PartialFeeder
- type RenderDiagnostics
- func (d RenderDiagnostics) EngineDurationMilliseconds() float64
- func (d RenderDiagnostics) FastPlanHelperNamesHeader() string
- func (d RenderDiagnostics) FastPlanPartialNamesHeader() string
- func (d RenderDiagnostics) VMHelperDurationMilliseconds() float64
- func (d RenderDiagnostics) VMHelperHotspotsHeader() string
- func (d RenderDiagnostics) VMPartialDurationMilliseconds() float64
- func (d RenderDiagnostics) VMPartialHotspotsHeader() string
- type RenderFastPlanDiagnostics
- type RenderFunc
- type RenderMode
- type RenderVMHotspot
- type RenderVMHotspotDiagnostics
- type SymbolTable
- func (s *SymbolTable) Assign(name string, value interface{}) bool
- func (s *SymbolTable) AssignID(id int, value interface{}) bool
- func (s *SymbolTable) Declare(name string, value interface{})
- func (s *SymbolTable) DeclareID(id int, value interface{})
- func (s *SymbolTable) Has(name string) bool
- func (s *SymbolTable) Resolve(name string) (interface{}, bool)
- func (s *SymbolTable) ResolveID(id int) (interface{}, bool)
- func (s *SymbolTable) SymbolName(id int) (string, bool)
- type Template
- type TemplateCache
Examples ¶
Constants ¶
const ( RenderModeNameInterpreter = "interpreter" RenderModeNameVM = "vm" VMBytecodeCacheDisabled = "disabled" VMBytecodeCacheHit = "hit" VMBytecodeCacheHitStatic = "hit-static" VMBytecodeCacheHitSource = "hit-source" VMBytecodeCacheMiss = "miss" VMBytecodeCacheMissStore = "miss-store" VMBytecodeCacheMissStoreSource = "miss-store-source" VMBytecodeCacheDirect = "compiled-template" RenderFastPathStatic = "static" RenderFastPathFast = "fast" RenderFastPathGeneric = "generic" RenderFastPathInterpreterFallback = "interpreter-fallback" PunchHoleCacheDisabled = "disabled" PunchHoleCacheHit = "hit" PunchHoleCacheMiss = "miss" )
Variables ¶
var DefaultTimeFormat = "January 02, 2006 15:04:05 -0700"
DefaultTimeFormat is the default way of formatting a time.Time type. This a **GLOBAL** variable, so if you change it, it will change for templates rendered through the `plush` package. If you want to set a specific time format for a particular call to `Render` you can set the `TIME_FORMAT` in the context.
ctx.Set("TIME_FORMAT", "2006-02-Jan")
s, err = Render(input, ctx)
var ErrBudgetExceeded = errors.New("render budget exceeded")
ErrBudgetExceeded is returned when a render exhausts its budget.
var ErrVMRendererNotRegistered = errors.New("plush VM renderer is not registered")
var Helpers = helpers.NewMap(map[string]interface{}{})
Helpers contains all of the default helpers for These will be available to all templates. You should add any custom global helpers to this list.
var PunchHoleCacheLifetime = 1 * time.Minute
Functions ¶
func AddRenderDiagnosticVMHelperTiming ¶ added in v5.0.12
func AddRenderDiagnosticVMPartialTiming ¶ added in v5.0.12
func BuffaloRenderer ¶
func BuffaloRenderer(input string, data map[string]interface{}, helpers map[string]interface{}) (string, error)
BuffaloRenderer implements the render.TemplateEngine interface allowing velvet to be used as a template engine for Buffalo
func BuffaloRendererWithContext ¶ added in v5.0.12
func BuffaloRendererWithContext(input string, data map[string]interface{}, helpers map[string]interface{}, configure func(*Context)) (string, error)
BuffaloRendererWithContext is BuffaloRenderer with an optional context configuration hook. The hook runs after data/helpers are loaded and before rendering, so callers can attach per-render options such as VM fast helpers.
func CachePunchHoleSkeleton ¶ added in v5.0.12
func CachePunchHoleSkeletonWithSource ¶ added in v5.0.12
func CacheVMBytecode ¶ added in v5.0.12
func CacheVMBytecodeForCleanFilename ¶ added in v5.0.12
func CacheVMBytecodeForCleanFilenameWithSource ¶ added in v5.0.12
func CacheVMBytecodeForFilename ¶ added in v5.0.12
func CacheVMBytecodeForFilenameWithSource ¶ added in v5.0.12
func CachedASTProgram ¶ added in v5.0.12
func CachedASTProgramWithSource ¶ added in v5.0.12
func CachedVMBytecode ¶ added in v5.0.12
func CachedVMBytecodeForCleanFilename ¶ added in v5.0.12
func CachedVMBytecodeForCleanFilenameWithSource ¶ added in v5.0.12
func CachedVMBytecodeForFilename ¶ added in v5.0.12
func CachedVMBytecodeForFilenameWithSource ¶ added in v5.0.12
func ClearTemplateCache ¶ added in v5.0.8
func ClearTemplateCache()
func DisableRenderVMHotspotDiagnostics ¶ added in v5.0.12
func EnableRenderVMHotspotDiagnostics ¶ added in v5.0.12
func FillPunchHoles ¶ added in v5.0.12
func FillPunchHoles(rendered string, holes []HoleMarker) (string, error)
func GenerateASTKey ¶ added in v5.0.10
func GenerateASTKeyFromCleanFilename ¶ added in v5.0.12
func GetPunchHoleConcurrencyLimit ¶ added in v5.0.12
func GetPunchHoleConcurrencyLimit() int
func GroupByHelper ¶
func InterpreterPartialRenderEnabled ¶ added in v5.0.12
InterpreterPartialRenderEnabled reports whether partials should stay on the interpreter path for the current render.
func IsHoleRender ¶ added in v5.0.12
func IsPlushTemplateFile ¶ added in v5.0.12
func IsPunchHoleCacheExpired ¶ added in v5.0.12
func IsVMBytecodeCacheableTemplateFile ¶ added in v5.0.12
func PartialHelper ¶
func PlushCacheSetup ¶ added in v5.0.8
func PlushCacheSetup(ts TemplateCache)
func PunchHoleMarkerName ¶ added in v5.0.12
func PunchHoleTemplateFilename ¶ added in v5.0.12
func RegisterVMRenderer ¶ added in v5.0.12
func RegisterVMRenderer(renderer RenderFunc)
func Render ¶
Render a string using the given context.
Example ¶
ExampleRender using `if`, `for`, `else`, functions, etc...
package main
import (
"fmt"
"log"
"github.com/gobuffalo/plush/v5"
)
func main() {
html := `<html>
<%= if (names && len(names) > 0) { %>
<ul>
<%= for (n) in names { %>
<li><%= capitalize(n) %></li>
<% } %>
</ul>
<% } else { %>
<h1>Sorry, no names. :(</h1>
<% } %>
</html>`
ctx := plush.NewContext()
ctx.Set("names", []string{"john", "paul", "george", "ringo"})
s, err := plush.Render(html, ctx)
if err != nil {
log.Fatal(err)
}
fmt.Print(s)
}
Output: <html> <ul> <li>John</li> <li>Paul</li> <li>George</li> <li>Ringo</li> </ul> </html>
Example (CustomHelperFunctions) ¶
package main
import (
"fmt"
"html/template"
"log"
"github.com/gobuffalo/plush/v5"
)
func main() {
html := `<p><%= one() %></p>
<p><%= greet("mark")%></p>
<%= can("update") { %>
<p>i can update</p>
<% } %>
<%= can("destroy") { %>
<p>i can destroy</p>
<% } %>
`
ctx := plush.NewContext()
ctx.Set("one", func() int {
return 1
})
ctx.Set("greet", func(s string) string {
return fmt.Sprintf("Hi %s", s)
})
ctx.Set("can", func(s string, help plush.HelperContext) (template.HTML, error) {
if s == "update" {
h, err := help.Block()
return template.HTML(h), err
}
return "", nil
})
s, err := plush.Render(html, ctx)
if err != nil {
log.Fatal(err)
}
fmt.Print(s)
}
Output: <p>1</p> <p>Hi mark</p> <p>i can update</p>
Example (ForIterator) ¶
package main
import (
"fmt"
"log"
"github.com/gobuffalo/plush/v5"
)
func main() {
html := `<%= for (v) in between(3,6) { %><%=v%><% } %>`
s, err := plush.Render(html, plush.NewContext())
if err != nil {
log.Fatal(err)
}
fmt.Print(s)
}
Output: 45
Example (ScripletTags) ¶
package main
import (
"fmt"
"log"
"github.com/gobuffalo/plush/v5"
)
func main() {
html := `<%
let h = {name: "mark"}
let greet = fn(n) {
return "hi " + n
}
%>
<h1><%= greet(h["name"]) %></h1>`
s, err := plush.Render(html, plush.NewContext())
if err != nil {
log.Fatal(err)
}
fmt.Print(s)
}
Output: <h1>hi mark</h1>
func RenderDiagnosticsRootActive ¶ added in v5.0.12
func RenderFromPunchHoleCache ¶ added in v5.0.12
func RenderFromPunchHoleCacheWithSource ¶ added in v5.0.12
func RenderInterpreter ¶ added in v5.0.12
func RenderVMHotspotDiagnosticsEnabled ¶ added in v5.0.12
func RenderWithBudget ¶ added in v5.0.12
RenderWithBudget renders a template and enforces a work-unit limit. Returns ErrBudgetExceeded if the template exhausts the budget. Existing Render() is completely unchanged.
func RenderWithBudgetConfig ¶ added in v5.0.12
func RenderWithBudgetConfig(input string, limit int64, costs BudgetCosts, ctx *Context) (string, error)
RenderWithBudgetConfig renders with a fully custom cost configuration.
func SetPunchHoleConcurrencyLimit ¶ added in v5.0.12
func SetRenderDiagnostics ¶ added in v5.0.12
func SetRenderDiagnostics(ctx hctx.Context, diagnostics RenderDiagnostics)
func SetRenderDiagnosticsRootActive ¶ added in v5.0.12
func SetRenderVMHotspotDiagnostics ¶ added in v5.0.12
func SetVMGenericFallback ¶ added in v5.0.12
func UpdateRenderDiagnostics ¶ added in v5.0.12
func UpdateRenderDiagnostics(ctx hctx.Context, update func(*RenderDiagnostics))
func UpdateRenderDiagnosticsForTemplate ¶ added in v5.0.12
func UpdateRenderDiagnosticsForTemplate(ctx hctx.Context, filename string, update func(*RenderDiagnostics))
func VMGenericFallbackEnabled ¶ added in v5.0.12
func VMGenericFallbackEnabled() bool
Types ¶
type Budget ¶ added in v5.0.12
type Budget struct {
// contains filtered or unexported fields
}
Budget tracks render work units during template evaluation. A nil Budget is always unlimited — zero breaking changes.
func NewBudgetWithCosts ¶ added in v5.0.12
func NewBudgetWithCosts(limit int64, costs BudgetCosts) *Budget
NewBudgetWithCosts creates a Budget with fully custom per-operation costs.
func (*Budget) Costs ¶ added in v5.0.12
func (b *Budget) Costs() BudgetCosts
Costs returns the active cost configuration.
func (*Budget) SpendAssignment ¶ added in v5.0.12
SpendAssignment spends the assignment cost.
func (*Budget) SpendCondition ¶ added in v5.0.12
SpendCondition spends the condition check cost.
func (*Budget) SpendFilter ¶ added in v5.0.12
SpendFilter spends the filter call cost.
func (*Budget) SpendFunctionCall ¶ added in v5.0.12
SpendFunctionCall spends the cost for a named function call. Uses FunctionCosts[name] if set, otherwise falls back to HelperCall cost.
func (*Budget) SpendHelperCall ¶ added in v5.0.12
SpendHelperCall spends the helper call cost.
func (*Budget) SpendObjectTraversal ¶ added in v5.0.12
SpendObjectTraversal spends ObjectTraversal * segments units. e.g. product.variants.first = 3 segments → costs ObjectTraversal * 3
func (*Budget) SpendSubRender ¶ added in v5.0.12
SpendSubRender spends the sub-render cost.
func (*Budget) Stats ¶ added in v5.0.12
func (b *Budget) Stats() BudgetStats
Stats returns a snapshot of work units consumed per operation category. Safe to call at any point during or after rendering.
func (*Budget) WithCosts ¶ added in v5.0.12
func (b *Budget) WithCosts(costs BudgetCosts) *Budget
WithCosts replaces the cost configuration. Returns self for chaining.
type BudgetCosts ¶ added in v5.0.12
type BudgetCosts struct {
// LoopIteration is spent once per for-loop iteration.
// Default: 1
LoopIteration int64
// HelperCall is spent each time a registered helper is invoked.
// Default: 5
HelperCall int64
// FilterCall is spent per filter applied (sort, map, where).
// Default: 3
FilterCall int64
// SubRender is spent each time a partial/snippet is rendered.
// Default: 10
SubRender int64
// ConditionCheck is spent per if/unless/case evaluation.
// Default: 1
ConditionCheck int64
// Assignment is spent per variable assignment.
// Default: 0 (free — rarely the bottleneck)
Assignment int64
// ObjectTraversal is spent per dot-notation segment accessed.
// e.g. product.variants.first = 3 segments = 3 units
// Default: 1
ObjectTraversal int64
// FunctionCosts overrides the default HelperCall cost for specific named
// functions. The key is the function name as registered in the context.
// If a name is present here, its cost is used instead of HelperCall.
// e.g. costs.FunctionCosts = map[string]int64{"expensiveQuery": 50}
FunctionCosts map[string]int64
}
BudgetCosts defines the work-unit cost for each operation type.
func DefaultBudgetCosts ¶ added in v5.0.12
func DefaultBudgetCosts() BudgetCosts
DefaultBudgetCosts returns recommended production defaults.
func ZeroCosts ¶ added in v5.0.12
func ZeroCosts() BudgetCosts
ZeroCosts returns all-zero costs. Useful for isolating one operation type in tests.
type BudgetStats ¶ added in v5.0.12
type BudgetStats struct {
// TotalUsed is the sum of all units spent (equals b.Used()).
TotalUsed int64
// LoopIterations is total units charged by loop iterations.
LoopIterations int64
// FunctionCalls is total units charged by all function/helper calls.
FunctionCalls int64
// FilterCalls is total units charged by filter calls.
FilterCalls int64
// SubRenders is total units charged by partial/snippet renders.
SubRenders int64
// ConditionChecks is total units charged by if/unless evaluations.
ConditionChecks int64
// Assignments is total units charged by variable assignments.
Assignments int64
// ObjectTraversals is total units charged by dot-notation traversal.
ObjectTraversals int64
// ByFunction breaks FunctionCalls down by name for calls made via
// SpendFunctionCall. Functions without a FunctionCosts override appear
// here using the generic HelperCall cost.
ByFunction map[string]int64
}
BudgetStats is a snapshot of work units consumed per operation category. Retrieve it after rendering via b.Stats().
type Context ¶
Context holds all of the data for the template that is being rendered.
func NewContextWith ¶
NewContextWith returns a fully formed context using the data provided.
func NewContextWithContext ¶
NewContextWithContext returns a new plush.Context given another context
func NewContextWithOuter ¶
NewContextWith returns a fully formed context using the data provided and setting the outer context with the passed seccond argument.
func (*Context) Budget ¶ added in v5.0.12
Budget returns the active budget, walking up the outer chain. Returns nil if no budget is set (unlimited).
func (*Context) New ¶
New context containing the current context. Values set on the new context will not be set onto the original context, however, the original context's values will be available to the new context.
func (*Context) Value ¶
func (c *Context) Value(key interface{}) interface{}
Value from the context, or it's parent's context if one exists.
func (*Context) WithBudget ¶ added in v5.0.12
WithBudget attaches a Budget to this context. Returns self for chaining.
type ErrUnknownIdentifier ¶
func (*ErrUnknownIdentifier) Error ¶
func (e *ErrUnknownIdentifier) Error() string
type HelperContext ¶
HelperContext is an optional last argument to helpers that provides the current context of the call, and access to an optional "block" of code that can be executed from within the helper.
func NewHelperContext ¶ added in v5.0.12
NewHelperContext returns a HelperContext that can execute an optional block using the supplied runner. It is used by alternate execution engines that need to interoperate with helpers accepting plush.HelperContext.
func (HelperContext) Block ¶
func (h HelperContext) Block() (string, error)
Block executes the block of template associated with the helper, think the block inside of an "if" or "each" statement.
func (HelperContext) BlockWith ¶
func (h HelperContext) BlockWith(hc hctx.Context) (string, error)
BlockWith executes the block of template associated with the helper, think the block inside of an "if" or "each" statement, but with it's own context.
func (HelperContext) HasBlock ¶
func (h HelperContext) HasBlock() bool
HasBlock returns true if a block is associated with the helper function
type HoleMarker ¶ added in v5.0.8
type HoleMarker struct {
// contains filtered or unexported fields
}
func FinalizePunchHolePositions ¶ added in v5.0.12
func FinalizePunchHolePositions(rendered string, holes []HoleMarker) []HoleMarker
func NewHoleMarker ¶ added in v5.0.12
func NewHoleMarker(markerName, input string, start, end int) HoleMarker
func RenderPunchHolesConcurrently ¶ added in v5.0.12
func RenderPunchHolesConcurrently(holes []HoleMarker, ctx hctx.Context) []HoleMarker
func RenderPunchHolesConcurrentlyWith ¶ added in v5.0.12
func RenderPunchHolesConcurrentlyWith(holes []HoleMarker, ctx hctx.Context, renderer func(string, hctx.Context) (string, error)) []HoleMarker
func (HoleMarker) Content ¶ added in v5.0.12
func (h HoleMarker) Content() string
func (HoleMarker) End ¶ added in v5.0.12
func (h HoleMarker) End() int
func (HoleMarker) Err ¶ added in v5.0.12
func (h HoleMarker) Err() error
func (HoleMarker) Input ¶ added in v5.0.12
func (h HoleMarker) Input() string
func (HoleMarker) MarkerName ¶ added in v5.0.12
func (h HoleMarker) MarkerName() string
func (HoleMarker) Start ¶ added in v5.0.12
func (h HoleMarker) Start() int
type InternTable ¶ added in v5.0.4
type InternTable struct {
// contains filtered or unexported fields
}
func NewInternTable ¶ added in v5.0.4
func NewInternTable() *InternTable
func (*InternTable) Intern ¶ added in v5.0.4
func (it *InternTable) Intern(name string) int
func (*InternTable) SymbolName ¶ added in v5.0.4
func (it *InternTable) SymbolName(id int) string
type Iterator ¶
type Iterator interface {
Next() interface{}
}
Iterator type can be implemented and used by the `for` command to build loops in templates
type PartialFeeder ¶
PartialFeeder is callback function should implemented on application side.
type RenderDiagnostics ¶ added in v5.0.12
type RenderDiagnostics struct {
Mode string
TemplateFilename string
VMBytecodeCache string
FastPath string
FastRejectLine int
FastReject string
PunchHoleCache string
EngineDuration time.Duration
FastPlan RenderFastPlanDiagnostics
VMHotspots RenderVMHotspotDiagnostics
}
func RenderDiagnosticsFromContext ¶ added in v5.0.12
func RenderDiagnosticsFromContext(ctx hctx.Context) (RenderDiagnostics, bool)
func RenderDiagnosticsFromData ¶ added in v5.0.12
func RenderDiagnosticsFromData(data map[string]interface{}) (RenderDiagnostics, bool)
func (RenderDiagnostics) EngineDurationMilliseconds ¶ added in v5.0.12
func (d RenderDiagnostics) EngineDurationMilliseconds() float64
func (RenderDiagnostics) FastPlanHelperNamesHeader ¶ added in v5.0.12
func (d RenderDiagnostics) FastPlanHelperNamesHeader() string
func (RenderDiagnostics) FastPlanPartialNamesHeader ¶ added in v5.0.12
func (d RenderDiagnostics) FastPlanPartialNamesHeader() string
func (RenderDiagnostics) VMHelperDurationMilliseconds ¶ added in v5.0.12
func (d RenderDiagnostics) VMHelperDurationMilliseconds() float64
func (RenderDiagnostics) VMHelperHotspotsHeader ¶ added in v5.0.12
func (d RenderDiagnostics) VMHelperHotspotsHeader() string
func (RenderDiagnostics) VMPartialDurationMilliseconds ¶ added in v5.0.12
func (d RenderDiagnostics) VMPartialDurationMilliseconds() float64
func (RenderDiagnostics) VMPartialHotspotsHeader ¶ added in v5.0.12
func (d RenderDiagnostics) VMPartialHotspotsHeader() string
type RenderFastPlanDiagnostics ¶ added in v5.0.12
type RenderMode ¶ added in v5.0.12
type RenderMode int32
const ( RenderModeInterpreter RenderMode = iota RenderModeVM )
func GetRenderMode ¶ added in v5.0.12
func GetRenderMode() RenderMode
func SetRenderMode ¶ added in v5.0.12
func SetRenderMode(mode RenderMode) RenderMode
type RenderVMHotspot ¶ added in v5.0.12
type RenderVMHotspotDiagnostics ¶ added in v5.0.12
type RenderVMHotspotDiagnostics struct {
HelperCalls int
HelperDuration time.Duration
PartialCalls int
PartialDuration time.Duration
Helpers []RenderVMHotspot
Partials []RenderVMHotspot
}
type SymbolTable ¶ added in v5.0.4
type SymbolTable struct {
// contains filtered or unexported fields
}
SymbolTable represents a scope
func NewScope ¶ added in v5.0.4
func NewScope(parent *SymbolTable) *SymbolTable
NewScope creates a new scope with an optional parent
func (*SymbolTable) Assign ¶ added in v5.0.4
func (s *SymbolTable) Assign(name string, value interface{}) bool
Assign searches outer scopes and updates an existing variable
func (*SymbolTable) AssignID ¶ added in v5.0.12
func (s *SymbolTable) AssignID(id int, value interface{}) bool
func (*SymbolTable) Declare ¶ added in v5.0.4
func (s *SymbolTable) Declare(name string, value interface{})
Declare adds or updates a variable in the current scope
func (*SymbolTable) DeclareID ¶ added in v5.0.12
func (s *SymbolTable) DeclareID(id int, value interface{})
func (*SymbolTable) Has ¶ added in v5.0.4
func (s *SymbolTable) Has(name string) bool
Has finds the value of a variable
func (*SymbolTable) Resolve ¶ added in v5.0.4
func (s *SymbolTable) Resolve(name string) (interface{}, bool)
Resolve finds the value of a variable
func (*SymbolTable) ResolveID ¶ added in v5.0.12
func (s *SymbolTable) ResolveID(id int) (interface{}, bool)
func (*SymbolTable) SymbolName ¶ added in v5.0.12
func (s *SymbolTable) SymbolName(id int) (string, bool)
type Template ¶
type Template struct {
Input string
Program *ast.Program
PunchHole []HoleMarker
Skeleton string
VMBytecode interface{}
SourceHash string
IsCache bool
LastCached time.Time
}
Template represents an input and helpers to be used to evaluate and render the input.
func NewTemplate ¶
NewTemplate from the input string. Adds all of the global helper functions from "Helpers", this function does not cache the template.
func (*Template) Clone ¶
Clone a template. This is useful for defining helpers on per "instance" of the template.
Source Files
¶
- budget.go
- budget_config.go
- compiler.go
- context.go
- generate_cache_key.go
- helper_context.go
- helper_scope.go
- helpers.go
- intern.go
- iterators.go
- numeric.go
- objects.go
- partial_helper.go
- plush.go
- punch_hole.go
- render_diagnostics.go
- render_mode.go
- source_hash.go
- symbol_table.go
- template.go
- template_cache.go
- trim_tags.go
- user_function.go