Search in sources :

Example 1 with OutputVariable

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);
        }
    };
}
Also used : MapLiteral(org.apache.sling.scripting.sightly.compiler.expression.nodes.MapLiteral) PushStream(org.apache.sling.scripting.sightly.impl.compiler.PushStream) RuntimeCall(org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall) Map(java.util.Map) HashMap(java.util.HashMap) VariableBinding(org.apache.sling.scripting.sightly.compiler.commands.VariableBinding) OutputVariable(org.apache.sling.scripting.sightly.compiler.commands.OutputVariable)

Example 2 with OutputVariable

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);
        }
    };
}
Also used : PushStream(org.apache.sling.scripting.sightly.impl.compiler.PushStream) VariableBinding(org.apache.sling.scripting.sightly.compiler.commands.VariableBinding) OutputVariable(org.apache.sling.scripting.sightly.compiler.commands.OutputVariable)

Example 3 with OutputVariable

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);
        }
    };
}
Also used : ExpressionNode(org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode) OutText(org.apache.sling.scripting.sightly.compiler.commands.OutText) PushStream(org.apache.sling.scripting.sightly.impl.compiler.PushStream) Conditional(org.apache.sling.scripting.sightly.compiler.commands.Conditional) VariableBinding(org.apache.sling.scripting.sightly.compiler.commands.VariableBinding) OutputVariable(org.apache.sling.scripting.sightly.compiler.commands.OutputVariable)

Example 4 with OutputVariable

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);
}
Also used : Identifier(org.apache.sling.scripting.sightly.compiler.expression.nodes.Identifier) Expression(org.apache.sling.scripting.sightly.compiler.expression.Expression) BinaryOperation(org.apache.sling.scripting.sightly.compiler.expression.nodes.BinaryOperation) Conditional(org.apache.sling.scripting.sightly.compiler.commands.Conditional) StringConstant(org.apache.sling.scripting.sightly.compiler.expression.nodes.StringConstant) VariableBinding(org.apache.sling.scripting.sightly.compiler.commands.VariableBinding) OutputVariable(org.apache.sling.scripting.sightly.compiler.commands.OutputVariable)

Example 5 with OutputVariable

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);
        }
    };
}
Also used : MapLiteral(org.apache.sling.scripting.sightly.compiler.expression.nodes.MapLiteral) Identifier(org.apache.sling.scripting.sightly.compiler.expression.nodes.Identifier) PushStream(org.apache.sling.scripting.sightly.impl.compiler.PushStream) RuntimeCall(org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall) VariableBinding(org.apache.sling.scripting.sightly.compiler.commands.VariableBinding) OutputVariable(org.apache.sling.scripting.sightly.compiler.commands.OutputVariable)

Aggregations

OutputVariable (org.apache.sling.scripting.sightly.compiler.commands.OutputVariable)7 VariableBinding (org.apache.sling.scripting.sightly.compiler.commands.VariableBinding)7 PushStream (org.apache.sling.scripting.sightly.impl.compiler.PushStream)4 Conditional (org.apache.sling.scripting.sightly.compiler.commands.Conditional)3 Identifier (org.apache.sling.scripting.sightly.compiler.expression.nodes.Identifier)3 RuntimeCall (org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall)3 Expression (org.apache.sling.scripting.sightly.compiler.expression.Expression)2 ExpressionNode (org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode)2 BinaryOperation (org.apache.sling.scripting.sightly.compiler.expression.nodes.BinaryOperation)2 MapLiteral (org.apache.sling.scripting.sightly.compiler.expression.nodes.MapLiteral)2 StringConstant (org.apache.sling.scripting.sightly.compiler.expression.nodes.StringConstant)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 OutText (org.apache.sling.scripting.sightly.compiler.commands.OutText)1 MarkupContext (org.apache.sling.scripting.sightly.compiler.expression.MarkupContext)1