[jsscripting] Update docs and refactor path (#11827)
This adds a minor refactoring of loading local resource paths that i didn't have time to get into 3.2 and moves the docs directory to doc. Signed-off-by: Dan Cunningham <dan@digitaldan.com>
@ -30,7 +30,7 @@ to common openHAB functionality within rules including items, things, actions, l
|
|||||||
|
|
||||||
This add-on includes by default the [openhab-js](https://github.com/openhab/openhab-js/) NPM library and exports it's namespaces onto the global namespace. This allows the use of `items`, `actions`, `cache` and other objects without the need to explicitly import using `require()`. This functionality can be disabled for users who prefer to manage their own imports via the add-on configuration options.
|
This add-on includes by default the [openhab-js](https://github.com/openhab/openhab-js/) NPM library and exports it's namespaces onto the global namespace. This allows the use of `items`, `actions`, `cache` and other objects without the need to explicitly import using `require()`. This functionality can be disabled for users who prefer to manage their own imports via the add-on configuration options.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## UI Based Rules
|
## UI Based Rules
|
||||||
|
|
||||||
@ -42,17 +42,17 @@ Advanced users, or users migrating scripts from existing systems may want to use
|
|||||||
|
|
||||||
Using the openHAB UI, first create a new rule and set a trigger condition
|
Using the openHAB UI, first create a new rule and set a trigger condition
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### Adding Actions
|
### Adding Actions
|
||||||
|
|
||||||
Select "Add Action" and then select "ECMAScript 262 Edition 11". Its important this is "Edition 11" or higher, earlier versions will not work. This will bring up a empty script editor where you can enter your javascript.
|
Select "Add Action" and then select "ECMAScript 262 Edition 11". Its important this is "Edition 11" or higher, earlier versions will not work. This will bring up a empty script editor where you can enter your javascript.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
You can now write rules using standard ES6 Javascript along with the included openHAB [standard library](#standard-library).
|
You can now write rules using standard ES6 Javascript along with the included openHAB [standard library](#standard-library).
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
For example, turning a light on:
|
For example, turning a light on:
|
||||||
```javascript
|
```javascript
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 154 KiB |
|
Before Width: | Height: | Size: 178 KiB After Width: | Height: | Size: 178 KiB |
|
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 115 KiB |
|
Before Width: | Height: | Size: 122 KiB After Width: | Height: | Size: 122 KiB |
@ -223,11 +223,12 @@ public class OpenhabGraalJSScriptEngine extends InvocationInterceptingScriptEngi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a root node path to a class resource path for loading local modules
|
* Converts a root node path to a class resource path for loading local modules
|
||||||
|
* Ex: C:\node_modules\foo.js -> /node_modules/foo.js
|
||||||
*
|
*
|
||||||
* @param path
|
* @param path
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String nodeFileToResource(Path path) {
|
private String nodeFileToResource(Path path) {
|
||||||
return "/" + NODE_DIR + "/" + path.getFileName();
|
return "/" + path.subpath(0, path.getNameCount()).toString().replace('\\', '/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||