Author: radu Date: Mon Mar 16 13:03:32 2015 New Revision: 1666983 URL: http://svn.apache.org/r1666983 Log: SLING-4506 - Java APIs not consistently available in JavaScript
* added getName() and getResourceType() for Resource in addition to name and resourceType properties Added: sling/trunk/contrib/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/jsuse.html sling/trunk/contrib/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/jsuse.js Modified: sling/trunk/contrib/scripting/sightly/js-use-provider/src/main/resources/SLING-INF/libs/sling/sightly/js/internal/resource.js sling/trunk/contrib/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java Modified: sling/trunk/contrib/scripting/sightly/js-use-provider/src/main/resources/SLING-INF/libs/sling/sightly/js/internal/resource.js URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/js-use-provider/src/main/resources/SLING-INF/libs/sling/sightly/js/internal/resource.js?rev=1666983&r1=1666982&r2=1666983&view=diff ============================================================================== --- sling/trunk/contrib/scripting/sightly/js-use-provider/src/main/resources/SLING-INF/libs/sling/sightly/js/internal/resource.js (original) +++ sling/trunk/contrib/scripting/sightly/js-use-provider/src/main/resources/SLING-INF/libs/sling/sightly/js/internal/resource.js Mon Mar 16 13:03:32 2015 @@ -99,6 +99,26 @@ use(['helper.js'], function(helper) { }, /** + * Returns the name of this resource. The name of a resource is the last segment of the path. + * @returns {string} the name of this resource + */ + getName: function () { + var index = this.path.lastIndexOf('/'); + if (index == -1) { + return this.path; + } + return this.path.substring(index + 1); + }, + + /** + * The resource type is meant to point to rendering/processing scripts, editing dialogs, etc. + * @return {string} the resource type of this resource + */ + getResourceType: function () { + return this.nativeResource.resourceType; + }, + + /** * Resolve a path to a resource. The path may be relative * to this path * @param {string} path the requested path @@ -124,11 +144,7 @@ use(['helper.js'], function(helper) { */ name: { get: function() { - var index = this.path.lastIndexOf('/'); - if (index == -1) { - return this.path; - } - return this.path.substring(index + 1); + return this.getName(); } }, @@ -140,7 +156,7 @@ use(['helper.js'], function(helper) { */ resourceType: { get: function() { - return this.nativeResource.resourceType; + return this.getResourceType(); } } }); Added: sling/trunk/contrib/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/jsuse.html URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/jsuse.html?rev=1666983&view=auto ============================================================================== --- sling/trunk/contrib/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/jsuse.html (added) +++ sling/trunk/contrib/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/jsuse.html Mon Mar 16 13:03:32 2015 @@ -0,0 +1,32 @@ +<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ 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. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> +<!DOCTYPE html> +<html> + <head> + <title>Sightly JavaScript Use-API - Sling implementation</title> + </head> + <body> + <section data-sly-use.jsuse="jsuse.js"> + <div id="resource-name">${jsuse.resourceName}</div> + <div id="resource-getName">${jsuse.resourceGetName}</div> + <div id="resource-resourceType">${jsuse.resourceResourceType}</div> + <div id="resource-getResourceType">${jsuse.resourceGetResourceType}</div> + </section> + </body> +</html> \ No newline at end of file Added: sling/trunk/contrib/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/jsuse.js URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/jsuse.js?rev=1666983&view=auto ============================================================================== --- sling/trunk/contrib/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/jsuse.js (added) +++ sling/trunk/contrib/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/jsuse.js Mon Mar 16 13:03:32 2015 @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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. + ******************************************************************************/ +use(function () { + return { + resourceName: sightly.resource.name, + resourceGetName: sightly.resource.getName(), + resourceResourceType: sightly.resource.resourceType, + resourceGetResourceType: sightly.resource.getResourceType() + }; +}); Modified: sling/trunk/contrib/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java?rev=1666983&r1=1666982&r2=1666983&view=diff ============================================================================== --- sling/trunk/contrib/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java (original) +++ sling/trunk/contrib/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java Mon Mar 16 13:03:32 2015 @@ -36,6 +36,7 @@ public class SlingSpecificsSightlyIT { private static final String SLING_RESOURCE = "/sightly/resource.html"; private static final String SLING_TEMPLATE = "/sightly/template.html"; private static final String SLING_TEMPLATE_BAD_IDENTIFIER = "/sightly/template.bad-id.html"; + private static final String SLING_JS_USE = "/sightly/use.jsuse.html"; @BeforeClass public static void init() { @@ -92,4 +93,14 @@ public class SlingSpecificsSightlyIT { assertTrue(pageContent.contains("org.apache.sling.scripting.sightly.impl.compiler.SightlyParsingException")); } + @Test + public void testJSUseAPI() { + String url = launchpadURL + SLING_JS_USE; + String pageContent = client.getStringContent(url, 200); + assertEquals("use", HTMLExtractor.innerHTML(url, pageContent, "#resource-name")); + assertEquals("use", HTMLExtractor.innerHTML(url, pageContent, "#resource-getName")); + assertEquals("/apps/sightly/scripts/use", HTMLExtractor.innerHTML(url, pageContent, "#resource-resourceType")); + assertEquals("/apps/sightly/scripts/use", HTMLExtractor.innerHTML(url, pageContent, "#resource-getResourceType")); + } + }