|
@@ -48,7 +48,7 @@ private typedef ExprToken = {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- Template provides a basic templating mechanism to replace values in a source
|
|
|
|
|
|
+ `Template` provides a basic templating mechanism to replace values in a source
|
|
String, and to have some basic logic.
|
|
String, and to have some basic logic.
|
|
|
|
|
|
A complete documentation of the supported syntax is available at:
|
|
A complete documentation of the supported syntax is available at:
|
|
@@ -62,8 +62,8 @@ class Template {
|
|
static var expr_float = ~/^([+-]?)(?=\d|,\d)\d*(,\d*)?([Ee]([+-]?\d+))?$/;
|
|
static var expr_float = ~/^([+-]?)(?=\d|,\d)\d*(,\d*)?([Ee]([+-]?\d+))?$/;
|
|
|
|
|
|
/**
|
|
/**
|
|
- Global replacements which are used across all Template instances. This
|
|
|
|
- has lower priority than the context argument of execute().
|
|
|
|
|
|
+ Global replacements which are used across all `Template` instances. This
|
|
|
|
+ has lower priority than the context argument of `execute()`.
|
|
**/
|
|
**/
|
|
public static var globals:Dynamic = {};
|
|
public static var globals:Dynamic = {};
|
|
|
|
|
|
@@ -77,14 +77,14 @@ class Template {
|
|
var buf:StringBuf;
|
|
var buf:StringBuf;
|
|
|
|
|
|
/**
|
|
/**
|
|
- Creates a new Template instance from `str`.
|
|
|
|
|
|
+ Creates a new `Template` instance from `str`.
|
|
|
|
|
|
`str` is parsed into tokens, which are stored for internal use. This
|
|
`str` is parsed into tokens, which are stored for internal use. This
|
|
- means that multiple execute() operations on a single Template instance
|
|
|
|
- are more efficient than one execute() operations on multiple Template
|
|
|
|
|
|
+ means that multiple `execute()` operations on a single `Template` instance
|
|
|
|
+ are more efficient than one `execute()` operations on multiple `Template`
|
|
instances.
|
|
instances.
|
|
|
|
|
|
- If `str` is null, the result is unspecified.
|
|
|
|
|
|
+ If `str` is `null`, the result is unspecified.
|
|
**/
|
|
**/
|
|
public function new(str:String) {
|
|
public function new(str:String) {
|
|
var tokens = parseTokens(str);
|
|
var tokens = parseTokens(str);
|
|
@@ -94,19 +94,19 @@ class Template {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- Executes `this` Template, taking into account `context` for
|
|
|
|
|
|
+ Executes `this` `Template`, taking into account `context` for
|
|
replacements and `macros` for callback functions.
|
|
replacements and `macros` for callback functions.
|
|
|
|
|
|
- If `context` has a field 'name', its value replaces all occurrences of
|
|
|
|
- ::name:: in the Template. Otherwise Template.globals is checked instead,
|
|
|
|
- If 'name' is not a field of that either, ::name:: is replaced with null.
|
|
|
|
|
|
+ If `context` has a field `name`, its value replaces all occurrences of
|
|
|
|
+ `::name::` in the `Template`. Otherwise `Template.globals` is checked instead,
|
|
|
|
+ If `name` is not a field of that either, `::name::` is replaced with `null`.
|
|
|
|
|
|
- If `macros` has a field 'name', all occurrences of $$name(args) are
|
|
|
|
|
|
+ If `macros` has a field `name`, all occurrences of `$$name(args)` are
|
|
replaced with the result of calling that field. The first argument is
|
|
replaced with the result of calling that field. The first argument is
|
|
- always the resolve() method, followed by the given arguments.
|
|
|
|
|
|
+ always the `resolve()` method, followed by the given arguments.
|
|
If `macros` has no such field, the result is unspecified.
|
|
If `macros` has no such field, the result is unspecified.
|
|
|
|
|
|
- If `context` is null, the result is unspecified. If `macros` is null,
|
|
|
|
|
|
+ If `context` is `null`, the result is unspecified. If `macros` is `null`,
|
|
no macros are used.
|
|
no macros are used.
|
|
**/
|
|
**/
|
|
public function execute(context:Dynamic, ?macros:Dynamic):String {
|
|
public function execute(context:Dynamic, ?macros:Dynamic):String {
|