You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2019/01/24 20:23:19 UTC

[sling-org-apache-sling-app-cms] branch master updated: SLING-8226 Add isEditor parameter to sightly bindings (#5)

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

dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git


The following commit(s) were added to refs/heads/master by this push:
     new 07d4220  SLING-8226 Add isEditor parameter to sightly bindings (#5)
07d4220 is described below

commit 07d4220196d53c03ca5b653e422706deac57f610
Author: Mahsum Demir <ma...@gmail.com>
AuthorDate: Thu Jan 24 23:23:14 2019 +0300

    SLING-8226 Add isEditor parameter to sightly bindings (#5)
    
    * Create a separate folder for docker and make Dockerfile runnable
    
    * Implement support for json page templates
    
    * SLING-8226
    Add isEditor parameter to sightly bindings
    
    Thanks @mahsumdemir!
---
 core/pom.xml                                       |  4 +++
 .../core/internal/bindings/SightlyBindings.java    | 42 ++++++++++++++++++++++
 pom.xml                                            |  6 ++++
 3 files changed, 52 insertions(+)

diff --git a/core/pom.xml b/core/pom.xml
index 8d807b0..0abcca4 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -232,5 +232,9 @@
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.event.api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.scripting.api</artifactId>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/bindings/SightlyBindings.java b/core/src/main/java/org/apache/sling/cms/core/internal/bindings/SightlyBindings.java
new file mode 100644
index 0000000..37bb227
--- /dev/null
+++ b/core/src/main/java/org/apache/sling/cms/core/internal/bindings/SightlyBindings.java
@@ -0,0 +1,42 @@
+/*
+ * 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.cms.core.internal.bindings;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.scripting.api.BindingsValuesProvider;
+import org.osgi.service.component.annotations.Component;
+
+import javax.script.Bindings;
+
+@Component(
+        property = {"javax.script.name=sightly"}
+)
+public class SightlyBindings implements BindingsValuesProvider {
+    public SightlyBindings(){
+
+    }
+
+    @Override
+    public void addBindings(Bindings bindings) {
+        if (!bindings.containsKey("isEditor") && bindings.containsKey("request")){
+            SlingHttpServletRequest request = ((SlingHttpServletRequest)bindings.get("request"));
+            Object cmsEditEnabled = request.getAttribute("cmsEditEnabled");
+            bindings.put("isEditor", cmsEditEnabled);
+        }
+    }
+
+}
diff --git a/pom.xml b/pom.xml
index c6b5d0d..0d6e228 100644
--- a/pom.xml
+++ b/pom.xml
@@ -207,6 +207,12 @@
                 <version>4.5.5</version>
                 <scope>provided</scope>
             </dependency>
+            <dependency>
+                <groupId>org.apache.sling</groupId>
+                <artifactId>org.apache.sling.scripting.api</artifactId>
+                <version>2.2.0</version>
+                <scope>provided</scope>
+            </dependency>
         </dependencies>
     </dependencyManagement>