You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2016/04/19 16:25:27 UTC

svn commit: r1739935 - /sling/site/trunk/content/documentation/bundles/scripting/scripting-sightly.mdtext

Author: radu
Date: Tue Apr 19 14:25:27 2016
New Revision: 1739935

URL: http://svn.apache.org/viewvc?rev=1739935&view=rev
Log:
CMS commit to sling by radu

Modified:
    sling/site/trunk/content/documentation/bundles/scripting/scripting-sightly.mdtext

Modified: sling/site/trunk/content/documentation/bundles/scripting/scripting-sightly.mdtext
URL: http://svn.apache.org/viewvc/sling/site/trunk/content/documentation/bundles/scripting/scripting-sightly.mdtext?rev=1739935&r1=1739934&r2=1739935&view=diff
==============================================================================
--- sling/site/trunk/content/documentation/bundles/scripting/scripting-sightly.mdtext (original)
+++ sling/site/trunk/content/documentation/bundles/scripting/scripting-sightly.mdtext Tue Apr 19 14:25:27 2016
@@ -27,7 +27,7 @@ The Sling implementation is comprised of
 1. [`org.apache.sling.scripting.sightly`](https://github.com/apache/sling/tree/trunk/bundles/scripting/sightly/engine) - the core Sightly Scripting Engine bundle
 2. [`org.apache.sling.scripting.sightly.js.provider`](https://github.com/apache/sling/tree/trunk/bundles/scripting/sightly/js-use-provider) - the Sightly JavaScript Use Provider, implementing support for the `use` JavaScript function
 3. [`org.apache.sling.scripting.sightly.models.provider`](https://github.com/apache/sling/tree/trunk/bundles/scripting/sightly/models-use-provider) - [Sling Models](https://sling.apache.org/documentation/bundles/models.html) Use Provider
-4. [`org.apache.sling.scripting.sightly.repl`](https://github.com/apache/sling/tree/trunk/bundles/scripting/sightly/repl) - Sightly Read-Eval-Print Loop Environment (REPL)
+4. [`org.apache.sling.scripting.sightly.repl`](https://github.com/apache/sling/tree/trunk/bundles/scripting/sightly/repl) - Sightly Read-Eval-Print Loop Environment (REPL), useful for quickly prototyping scripts
 
 # The Use-API
 
@@ -81,6 +81,23 @@ A full Sightly installation provides the
 
 The `service.ranking` value of each Use Provider is configurable, allowing for fine tuning of the order in which the providers are queried when `data-sly-use` is called. However, in order to not affect core functionality the `RenderUnitProvider` should always have the highest ranking. If you need to configure the providers' service ranking head over to the configuration console at [http://localhost:8080/system/console/configMgr](http://localhost:8080/system/console/configMgr).
 
+### Global Objects
+
+The following global objects are available to all Use objects, either as a request attribute or as a property made available in the `javax.script.Bindings` map or attached to the `this` context of the `use` function:
+
+        currentNode         // javax.jcr.Node
+        currentSession      // javax.jcr.Session
+        log                 // org.slf4j.Logger
+        out                 // java.io.PrintWriter
+        properties          // org.apache.sling.api.resource.ValueMap
+        reader              // java.io.BufferedReader
+        request             // org.apache.sling.api.SlingHttpServletRequest
+        resolver            // org.apache.sling.api.resource.ResourceResolver
+        resource            // org.apache.sling.api.resource.Resource
+        response            // org.apache.sling.api.SlingHttpServletResponse
+        sling               // org.apache.sling.api.scripting.SlingScriptHelper
+
+
 ### Sling Models Use Provider
 Loading a Sling Model can be done with the following code:
 
@@ -245,6 +262,20 @@ or like:
 
 Similar to the Java Use Provider, loading the script using a relative path allows inheriting components to overlay just the Use script, without having to also overlay the calling Sightly script.
 
+#### Global Objects
+Besides the global objects available to all Use Providers, the JavaScript Use Provider also provides the following global objects available in the context of the `use` function:
+
+    console         // basic wrapper on top of log, but without formatting / throwable support
+    exports         // basic Java implementation of CommonJS - http://requirejs.org/docs/commonjs.html
+    module          // basic Java implementation of CommonJS - http://requirejs.org/docs/commonjs.html
+    setImmediate    // Java implementation of the Node.js setImmediate function
+    setTimeout      // Java implementation of the Node.js setTimeout function
+    sightly         // the namespace object under which the asynchronous Resource-API implemented by
+                    // org.apache.sling.scripting.sightly.js.provider is made available to consumers
+    use             // the use function
+    
+With the exception of the `console` and `use` objects, all the other global objects implemented by the JavaScript Use Provider are present in order to support the asynchronous Resource-API implemented by `org.apache.sling.scripting.sightly.js.provider`. However, this was deprecated starting with version 1.0.8 - see [SLING-4964](https://issues.apache.org/jira/browse/SLING-4964).
+
 #### Passing parameters
 Passed parameters will be made available to the Use object as properties of `this`. Assuming the following markup: