Utility classes

Plugin

Plugins have access to a global Plugin object which provides some useful utility functions for the plugin writer.

Available functions are:

readResourceFile(fileName, encoding)

Returns a string or byte buffer object of the contents of the specified file.

If encoding is 'utf8' or 'utf-8' the contents of a file will be returned as a string object otherwise it will be a byte buffer object.

getPathForResource(fileName)

Returns a string presenting a path of a file inside plugin's Resources folder.

loadImage(filePath/imageObj)

Returns an image object which can be used e.g. for drawing plugin preview in Neonto Studio.

Image can be loaded from a file path:

var path = Plugin.getPathForResource("image.png");
var image = Plugin.loadImage(path);

...or converted from a native Studio-side object (which can't be directly used with JavaScript Canvas):

var rows = this.getDataSheetRows(dataSheetName);
var image = Plugin.loadImage(rows[rowIndex]["image"]);

getPrerenderedContent(contentKey)

TODO

HttpClient

HttpClient is a utility class which allows plugins to create HTTP requests and get responses asynchronously through a callback function. Plugins can create an HttpClient object simply with the new operator:

var httpClient = new HttpClient();

loaded

This property holds a value (true or false) whether the load function is called on the object.

loadedUrl

This property holds a value passed as an url-parameter when calling the load function on the object. Will be null before the load function is called.

load(url, options, callbackFunc)

Triggers an HTTP request to the specified URL and gets response through a callback function. Following options can be configured for the request:

  • encoding: 'utf8', 'utf-8' or empty
  • method: regular HTTP methods (such as GET, POST, etc.)
  • headers: HTTP header fields (JSON with names as keys)
  • body: HTTP message body (can be JSON or plain text)

Example:

httpClient.load(url, {encoding: 'utf8', method: 'GET'}, function(err, httpStatus, data) {
    if ( !err) {
      try {
        var obj = JSON.parse(data);
        // do something with 'obj'
      } catch (exc) {
        err = new Error("Error loading data: "+exc);
      }
    }
  });

wait()

This will stop execution of a plugin code until load-method has finished.