Implement a node API for plugins
@see localnwt.plugin
968868
function(plugin, config) {	
	config = config || {};
	config.node = this;
	return localnwt.plugin(plugin, config);
}
678136
function PluginRender(pluginInstance, rendererInstance) {
    this._view = "index.jade";
    this._locals = {};

    var ns = pluginInstance.pluginNamespace, obj = PluginHelper.getPluginIdAndIId(ns), pluginId = obj.pluginId,
        req = PluginHelper.cloneRequest(rendererInstance.req, pluginId), res = rendererInstance.res;

    Object.defineProperties(req.params, {
        plugin: {
            value: obj.pluginId
        },
        iId: {
            value: obj.iId
        },
        namespace: {
            value: ns
        }
    });


    Object.defineProperties(req, {
        pluginRender: {
            value: this
        }
    });

    Object.defineProperties(this, {
        req: {
            value: req
        },
        res: {
            value: res
        },
        pluginId: {
            value: req.params.plugin
        },
        iId: {
            value: req.params.iId
        },
        plugin: {
            value: Plugins.get(req.params.plugin)
        },
        namespace: {
            value: req.params.namespace
        },
        pluginInstance: {
            value: pluginInstance
        },
        theme: {
            value: rendererInstance.theme
        },
        page: {
            value: rendererInstance.page
        },
        pluginPermissionValidator: {
            value: rendererInstance.pluginPermissionValidator
        },
        pagePermissionValidator: {
            value: rendererInstance.pagePermissionValidator
        },
        pluginInstanceDBAction: {
            value: rendererInstance.pluginInstanceDBAction
        },
        isExclusive: {
            value: rendererInstance.isExclusive
        }
    });
}
289744
function Plugin(element, options, jsonData) {
        // same the DOM element.
        this.element = element;
        this.jsonData = jsonData;
        // merge the options.
        // the jQuery extend function, the later object will
        // overwrite the former object.
        this.options = $.extend({}, defaultOptions, options);
        // set the plugin name.
        this._name = pluginName;
        // call the initialize function.
        this.init();
    }
196308
function(context, request, callback){
		if ((context.indexOf('node_modules') !== -1) || (request.indexOf('.') !== 0)) {
			callback(null, 'commonjs ' + request);
		}
		else {
			callback();
		}
	}
843279
function(markup) {

	var container = document.createElement('div');
	container.innerHTML = markup;

	return new NWTNodeInstance(container.childNodes[0]);
}
711213
function(id) {
        var plugin_dir = path.join(plugins_dir, id);
        if ( !fs.existsSync(plugin_dir) ) {
            events.emit('verbose', 'Plugin "'+ id +'" already removed ('+ plugin_dir +')');
            return Q();
        }
        
        shell.rm('-rf', plugin_dir);
        events.emit('verbose', 'Deleted "'+ id +'"');
        
        if(options.fetch) {
            //remove plugin from node_modules directory
            return npmUninstall(id, options.projectRoot, options); 
        }
        
        return Q();

    }
352059
function(pluginResult, payloadString) {
    var payload = JSON.parse(payloadString),
        ndefObjectAsString = JSON.stringify(decode(b64toArray(payload.data)));
    pluginResult.callbackOk(ndefObjectAsString, true);
}
645020
function(pluginIdx) {
    if (pluginIdx >= plugins.length) return callback(hooks.collectionHook);

    var plugin = plugins[pluginIdx];
    var next = function() {iterPlugins(pluginIdx + 1);};
    var func = plugin[stage];

    // call the plugin's stage hook, if defined
    if (func) {
      // T is database operation object
      func.call(plugin, T, next);
    } else next();
  }
1080723
function(context, node) {
        var layerContext = {
            visibility: (node.getAttribute("hidden") != "1"),
            queryable: (node.getAttribute("queryable") == "1"),
            formats: [],
             styles: [],
             metadata: {}
        };

        this.runChildNodes(layerContext, node);
        // set properties common to multiple objects on layer options/params
        context.layersContext.push(layerContext);
    }
1163149
function(type, id) {
        var node = document.createElementNS(this.xmlns, type);
        if (id) {
            node.setAttributeNS(null, "id", id);
        }
        return node;    
    }
1336259
function loadNodeModule(nodeModulePath, name) {
  return plugin.myrmex.fire('beforeNodeModuleLoad', nodeModulePath, name)
  .spread((nodeModulePath, name) => {
    let packageJson = {};
    try {
      packageJson = _.cloneDeep(require(path.join(nodeModulePath, 'package.json')));
    } catch (e) {
      if (e.code !== 'MODULE_NOT_FOUND') {
        throw e;
      }
    }

    // Lasy loading because the plugin has to be registered in a Myrmex instance before requiring ./node-module
    const NodeModule = require('./node-module');
    const nodePackage = new NodeModule(packageJson, name, nodeModulePath);

    // This event allows to inject code to alter the Lambda configuration
    return plugin.myrmex.fire('afterNodeModuleLoad', nodePackage);
  })
  .spread(nodePackage => {
    return Promise.resolve(nodePackage);
  });
}
988199
function (type, args, htmlpath, projectRoot, pageName) {
    var plugin = plugins.use(args);
    if (plugin[type] !== undefined) {
        return plugin[type](args[0], htmlpath, projectRoot, pageName, concatServerBaseUrl, projectPublishRoot);
    } else {
        return args[0];
    }
}
1222291
function dispatch(methodName, inDocument, xpath, contextNode, namespaceResolver) {
        xpath = preprocess(xpath);

        if (! contextNode) {
            contextNode = inDocument;
        }

        var result = getEngineFor(inDocument)
            .setIgnoreAttributesWithoutValue(ignoreAttributesWithoutValue)
            [methodName](xpath, contextNode, namespaceResolver);

        return result;
    }
673656
function(event, fn, selector, context) {	
	return localnwt.event.on(this, event, fn, selector,context);
}
1184664
function Node (config) {
    RED.nodes.createNode(this, config);
    var node = this;

    this.on('input', function (msg) {
      var method = config['cwm-custom-mode'],
        message = '',
        params = {};

      username = sUsername || this.credentials.username;
      password = sPassword || this.credentials.password || config.password;
      apikey = sApikey || this.credentials.apikey || config.apikey;

      // All method to be overridden
      if (msg.params) {
        if (msg.params.method) {
          method = msg.params.method;
        }
        if (msg.params.username) {
          username = msg.params.username;
        }
        if (msg.params.password) {
          password = msg.params.password;
        }
        if (msg.params.apikey) {
          apikey = msg.params.apikey;
        }
        if (msg.params.version) {
          version = msg.params.version;
        }
      }
      endpoint = sEndpoint;
      if ((!config['cwm-default-endpoint']) && config['cwm-service-endpoint']) {
        endpoint = config['cwm-service-endpoint'];
      }

      node.status({});
      initialCheck(apikey, username, password, method)
        .then(function(){
          return buildParams(msg, method, config, params);
        })
        .then(function(){
          return checkForFile(method);
        })
        .then(function(fileNeeded){
          if (fileNeeded) {
            if (msg.payload instanceof Buffer) {
              return loadFile(node, method, params, msg);
            }
            // If the data is a json object then it will not
            // have been detected as a buffer.
            return setWorkspaceParams(method, params, msg.payload);
          }
          return Promise.resolve(params);
        })
        .then(function(p){
          params = p;
          node.status({fill:'blue', shape:'dot', text:'executing'});
          return executeMethod(node, method, params, msg);
        })
        .then(function(){
          temp.cleanup();
          node.status({});
          node.send(msg);
        })
        .catch(function(err){
          temp.cleanup();
          payloadutils.reportError(node,msg,err);
        });

    });
  }
320802
function( element, options ) {
                Boilerplate.call( this, element, options || {}, defaults || {} );
                MyPlugin.call( this, element, options );
                return this;
            }
1282723
def add_node(namespace_inc_global, body, opts = {})
      data, _status_code, _headers = add_node_with_http_info(namespace_inc_global, body, opts)
      return data
    end