| Constructor and Description |
|---|
Fragment() |
| Modifier and Type | Method and Description |
|---|---|
abstract Object |
context()
Returns the context object in effect for this fragment.
|
abstract Object |
context(int n)
Like
context() btu returns the nth parent context object. |
String |
decompile()
Decompiles the template inside this lamdba and returns an approximation of
the original template from which it was parsed.
|
abstract StringBuilder |
decompile(StringBuilder into)
Decompiles this fragment into
into. |
String |
execute()
Executes this fragment and returns its result as a string.
|
String |
execute(Object context)
Executes this fragment with the provided context; returns its result as a string.
|
abstract void |
execute(Object context,
Writer out)
Executes this fragment with the provided context; writes its result to
out. |
abstract void |
execute(Writer out)
Executes this fragment; writes its result to
out. |
public abstract void execute(Writer out)
out.public abstract void execute(Object context, Writer out)
out. The
provided context will be nested in the fragment's bound context.public String execute()
public String execute(Object context)
public abstract Object context()
Map or a POJO or something else).public abstract Object context(int n)
context() btu returns the nth parent context object. 0
returns the same value as context(), 1 returns the parent context,
2 returns the grandparent and so forth. Note that if you request a parent that
does not exist an exception will be thrown. You should only use this method when you
know your lambda is run consistently in a context with a particular lineage.public String decompile()
Limitations:
{{ foo.bar }} becomes
{{foo.bar}}.
Compiler are used for all decompilation.
This feature is meant to enable use of lambdas for i18n such that you can recover
the contents of a lambda (so long as they're simple) to use as the lookup key for a
translation string. For example: {{#i18n}}Hello {{user.name}}!{{/i18n}} can be
sent to an i18n lambda which can use decompile to recover the text
Hello {{user.name}}! to be looked up in a translation dictionary. The
translated fragment could then be compiled and cached and then executed in lieu of the
original fragment using context().
public abstract StringBuilder decompile(StringBuilder into)
into. See decompile().into for call chaining.Copyright © 2016. All rights reserved.