Search in sources :

Example 1 with OutText

use of org.apache.sling.scripting.sightly.compiler.commands.OutText 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 2 with OutText

use of org.apache.sling.scripting.sightly.compiler.commands.OutText in project sling by apache.

the class CoalescingWrites method flushText.

private void flushText() {
    if (builder.length() > 0) {
        outStream.write(new OutText(builder.toString()));
        builder = new StringBuilder();
    }
}
Also used : OutText(org.apache.sling.scripting.sightly.compiler.commands.OutText)

Aggregations

OutText (org.apache.sling.scripting.sightly.compiler.commands.OutText)2 Conditional (org.apache.sling.scripting.sightly.compiler.commands.Conditional)1 OutputVariable (org.apache.sling.scripting.sightly.compiler.commands.OutputVariable)1 VariableBinding (org.apache.sling.scripting.sightly.compiler.commands.VariableBinding)1 ExpressionNode (org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode)1 PushStream (org.apache.sling.scripting.sightly.impl.compiler.PushStream)1