This is an automated email from the ASF dual-hosted git repository.

radu pushed a commit to branch issue/SLING-7681
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler.git


The following commit(s) were added to refs/heads/issue/SLING-7681 by this push:
     new 7b025fa  SLING-7709 - [HTL] Implement the data-sly-set block element
7b025fa is described below

commit 7b025fa2207ed5eddf953f5e26b4aafcddd2ea3f
Author: Radu Cotescu <[email protected]>
AuthorDate: Wed Jun 6 15:33:42 2018 +0200

    SLING-7709 - [HTL] Implement the data-sly-set block element
---
 .../sightly/compiler/SightlyCompiler.java          |  2 +
 .../sightly/impl/filter/ExpressionContext.java     |  1 +
 .../scripting/sightly/impl/plugin/SetPlugin.java   | 62 ++++++++++++++++++++++
 3 files changed, 65 insertions(+)

diff --git 
a/src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java
 
b/src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java
index 7c14e0e..6aeecde 100644
--- 
a/src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java
+++ 
b/src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java
@@ -54,6 +54,7 @@ import 
org.apache.sling.scripting.sightly.impl.plugin.ListPlugin;
 import org.apache.sling.scripting.sightly.impl.plugin.Plugin;
 import org.apache.sling.scripting.sightly.impl.plugin.RepeatPlugin;
 import org.apache.sling.scripting.sightly.impl.plugin.ResourcePlugin;
+import org.apache.sling.scripting.sightly.impl.plugin.SetPlugin;
 import org.apache.sling.scripting.sightly.impl.plugin.TemplatePlugin;
 import org.apache.sling.scripting.sightly.impl.plugin.TestPlugin;
 import org.apache.sling.scripting.sightly.impl.plugin.TextPlugin;
@@ -96,6 +97,7 @@ public final class SightlyCompiler {
         plugins.add(new ResourcePlugin());
         plugins.add(new TemplatePlugin());
         plugins.add(new TestPlugin());
+        plugins.add(new SetPlugin());
         plugins.add(new TextPlugin());
         plugins.add(new UnwrapPlugin());
         plugins.add(new UsePlugin());
diff --git 
a/src/main/java/org/apache/sling/scripting/sightly/impl/filter/ExpressionContext.java
 
b/src/main/java/org/apache/sling/scripting/sightly/impl/filter/ExpressionContext.java
index b9cc06c..531e813 100644
--- 
a/src/main/java/org/apache/sling/scripting/sightly/impl/filter/ExpressionContext.java
+++ 
b/src/main/java/org/apache/sling/scripting/sightly/impl/filter/ExpressionContext.java
@@ -30,6 +30,7 @@ public enum ExpressionContext {
     PLUGIN_DATA_SLY_ATTRIBUTE,
     PLUGIN_DATA_SLY_ELEMENT,
     PLUGIN_DATA_SLY_TEST,
+    PLUGIN_DATA_SLY_SET,
     PLUGIN_DATA_SLY_LIST,
     PLUGIN_DATA_SLY_REPEAT,
     PLUGIN_DATA_SLY_INCLUDE,
diff --git 
a/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/SetPlugin.java 
b/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/SetPlugin.java
new file mode 100644
index 0000000..010918b
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/SetPlugin.java
@@ -0,0 +1,62 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+package org.apache.sling.scripting.sightly.impl.plugin;
+
+import org.apache.sling.scripting.sightly.compiler.SightlyCompilerException;
+import org.apache.sling.scripting.sightly.compiler.commands.VariableBinding;
+import org.apache.sling.scripting.sightly.compiler.expression.Expression;
+import org.apache.sling.scripting.sightly.impl.compiler.PushStream;
+import 
org.apache.sling.scripting.sightly.impl.compiler.frontend.CompilerContext;
+
+/**
+ * Implementation for the {@code data-sly-set} plugin
+ */
+public class SetPlugin extends AbstractPlugin {
+
+    public SetPlugin() {
+        name = "set";
+        priority = 1;
+    }
+
+    @Override
+    public PluginInvoke invoke(final Expression expressionNode, final 
PluginCallInfo callInfo, final CompilerContext compilerContext) {
+
+        final String variableName = decodeVariableName(callInfo);
+
+        return new DefaultPluginInvoke() {
+
+            @Override
+            public void beforeElement(PushStream stream, String tagName) {
+                stream.write(new VariableBinding.Global(variableName, 
expressionNode.getRoot()));
+            }
+
+
+        };
+    }
+
+    private String decodeVariableName(PluginCallInfo callInfo) {
+        String[] arguments = callInfo.getArguments();
+        if (arguments.length == 0) {
+            throw new SightlyCompilerException("Identifier name was not 
provided.");
+        }
+        return arguments[0];
+    }
+
+
+}

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to