use of org.apache.sling.scripting.sightly.compiler.commands.OutputVariable in project sling by apache.
the class ResourcePlugin method invoke.
@Override
public PluginInvoke invoke(final Expression expression, final PluginCallInfo callInfo, final CompilerContext compilerContext) {
return new DefaultPluginInvoke() {
private Map<String, ExpressionNode> expressionOptions = new HashMap<>(expression.getOptions());
@Override
public void beforeChildren(PushStream stream) {
String resourceVar = compilerContext.generateVariable("resourceContent");
stream.write(new VariableBinding.Start(resourceVar, new RuntimeCall(RuntimeFunction.RESOURCE, expression.getRoot(), new MapLiteral(expressionOptions))));
stream.write(new OutputVariable(resourceVar));
stream.write(VariableBinding.END);
Patterns.beginStreamIgnore(stream);
}
@Override
public void afterChildren(PushStream stream) {
Patterns.endStreamIgnore(stream);
}
};
}
use of org.apache.sling.scripting.sightly.compiler.commands.OutputVariable in project sling by apache.
the class TextPlugin method invoke.
@Override
public PluginInvoke invoke(final Expression expression, PluginCallInfo callInfo, final CompilerContext compilerContext) {
return new DefaultPluginInvoke() {
@Override
public void beforeChildren(PushStream stream) {
String variable = compilerContext.generateVariable("textContent");
stream.write(new VariableBinding.Start(variable, compilerContext.adjustToContext(expression, MarkupContext.TEXT, ExpressionContext.TEXT).getRoot()));
stream.write(new OutputVariable(variable));
stream.write(VariableBinding.END);
Patterns.beginStreamIgnore(stream);
}
@Override
public void afterChildren(PushStream stream) {
Patterns.endStreamIgnore(stream);
}
};
}
use of org.apache.sling.scripting.sightly.compiler.commands.OutputVariable in project sling by apache.
the class ElementPlugin method invoke.
@Override
public PluginInvoke invoke(final Expression expression, final PluginCallInfo callInfo, final CompilerContext compilerContext) {
return new DefaultPluginInvoke() {
private final ExpressionNode node = adjustContext(compilerContext, expression, MarkupContext.ELEMENT_NAME, ExpressionContext.ELEMENT).getRoot();
private String tagVar = compilerContext.generateVariable("tagVar");
@Override
public void beforeElement(PushStream stream, String tagName) {
stream.write(new VariableBinding.Start(tagVar, node));
}
@Override
public void beforeTagOpen(PushStream stream) {
stream.write(new Conditional.Start(tagVar, true));
stream.write(new OutText("<"));
stream.write(new OutputVariable(tagVar));
stream.write(Conditional.END);
stream.write(new Conditional.Start(tagVar, false));
}
@Override
public void beforeAttributes(PushStream stream) {
stream.write(Conditional.END);
}
@Override
public void beforeTagClose(PushStream stream, boolean isSelfClosing) {
if (!isSelfClosing) {
stream.write(new Conditional.Start(tagVar, true));
stream.write(new OutText("</"));
stream.write(new OutputVariable(tagVar));
stream.write(new OutText(">"));
stream.write(Conditional.END);
}
stream.write(new Conditional.Start(tagVar, false));
}
@Override
public void afterTagClose(PushStream stream, boolean isSelfClosing) {
stream.write(Conditional.END);
}
@Override
public void afterElement(PushStream stream) {
stream.write(VariableBinding.END);
}
};
}
use of org.apache.sling.scripting.sightly.compiler.commands.OutputVariable in project sling by apache.
the class MarkupHandler method emitMultipleFragment.
private void emitMultipleFragment(String name, Interpolation interpolation, char quoteChar, PluginInvoke invoke) {
// Simplified algorithm for attribute output, which works when the interpolation is not of size 1. In this
// case we are certain that the attribute value cannot be the boolean value true, so we can skip this test
// altogether
Expression expression = expressionWrapper.transform(interpolation, getAttributeMarkupContext(name), ExpressionContext.ATTRIBUTE);
String attrContent = symbolGenerator.next("attrContent");
String shouldDisplayAttr = symbolGenerator.next("shouldDisplayAttr");
stream.write(new VariableBinding.Start(attrContent, expression.getRoot()));
stream.write(new VariableBinding.Start(shouldDisplayAttr, new BinaryOperation(BinaryOperator.OR, new Identifier(attrContent), new BinaryOperation(BinaryOperator.EQ, new StringConstant("false"), new Identifier(attrContent)))));
stream.write(new Conditional.Start(shouldDisplayAttr, true));
emitAttributeStart(name);
invoke.beforeAttributeValue(stream, name, expression.getRoot());
emitAttributeValueStart(quoteChar);
stream.write(new OutputVariable(attrContent));
emitAttributeEnd(quoteChar);
invoke.afterAttributeValue(stream, name);
stream.write(Conditional.END);
stream.write(VariableBinding.END);
stream.write(VariableBinding.END);
}
use of org.apache.sling.scripting.sightly.compiler.commands.OutputVariable in project sling by apache.
the class IncludePlugin method invoke.
@Override
public PluginInvoke invoke(final Expression expression, final PluginCallInfo callInfo, final CompilerContext compilerContext) {
return new DefaultPluginInvoke() {
@Override
public void beforeChildren(PushStream stream) {
String includedContentVar = compilerContext.generateVariable("includedResult");
String pathVar = compilerContext.generateVariable("includePath");
stream.write(new VariableBinding.Start(pathVar, expression.getRoot()));
stream.write(new VariableBinding.Start(includedContentVar, new RuntimeCall(RuntimeFunction.INCLUDE, new Identifier(pathVar), new MapLiteral(expression.getOptions()))));
stream.write(new OutputVariable(includedContentVar));
//end includedContentVar
stream.write(VariableBinding.END);
//end pathVar
stream.write(VariableBinding.END);
Patterns.beginStreamIgnore(stream);
}
@Override
public void afterChildren(PushStream stream) {
Patterns.endStreamIgnore(stream);
}
};
}
Aggregations