Add support for pipes in templates #53
The goal is to be able to modify values of variables used in templates. It enables future functionality such as escaping, inlining etc. It adds support applying predefined pipes to variables. Pipes can be applied to variable substitution in with and parameter substitution expressions. They work in similar way to piping in Unix where each pipe applied to the compiled result of pipe before. It adds support for using pipes in `with` and parameter substitution expressions. It also refactors how their regex is build to reuse more of the logic by abstracting regex building into a new class. Finally, it separates and extends documentation for templating.
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { ExpressionPosition } from '@/application/Parser/Script/Compiler/Expressions/Expression/ExpressionPosition';
|
||||
import { IExpression } from '@/application/Parser/Script/Compiler/Expressions/Expression/IExpression';
|
||||
import { IReadOnlyFunctionCallArgumentCollection } from '@/application/Parser/Script/Compiler/FunctionCall/Argument/IFunctionCallArgumentCollection';
|
||||
import { IReadOnlyFunctionParameterCollection } from '@/application/Parser/Script/Compiler/Function/Parameter/IFunctionParameterCollection';
|
||||
import { FunctionParameterCollectionStub } from './FunctionParameterCollectionStub';
|
||||
import { IExpressionEvaluationContext } from '@/application/Parser/Script/Compiler/Expressions/Expression/ExpressionEvaluationContext';
|
||||
|
||||
export class ExpressionStub implements IExpression {
|
||||
public callHistory = new Array<IReadOnlyFunctionCallArgumentCollection>();
|
||||
public callHistory = new Array<IExpressionEvaluationContext>();
|
||||
public position = new ExpressionPosition(0, 5);
|
||||
public parameters: IReadOnlyFunctionParameterCollection = new FunctionParameterCollectionStub();
|
||||
private result: string;
|
||||
@@ -26,8 +26,9 @@ export class ExpressionStub implements IExpression {
|
||||
this.result = result;
|
||||
return this;
|
||||
}
|
||||
public evaluate(args: IReadOnlyFunctionCallArgumentCollection): string {
|
||||
this.callHistory.push(args);
|
||||
public evaluate(context: IExpressionEvaluationContext): string {
|
||||
const args = context.args;
|
||||
this.callHistory.push(context);
|
||||
const result = this.result || `[expression-stub] args: ${args ? Object.keys(args).map((key) => `${key}: ${args[key]}`).join('", "') : 'none'}`;
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user