Permalink
Browse files

Setup YUI.setLoadHook and it's docs

  • Loading branch information...
davglass committed Jan 10, 2013
1 parent 0e6f7cd commit e879dd372a99661d076aa43bebcad7dda8370080
Showing with 26 additions and 2 deletions.
  1. +2 −2 src/get/js/get-nodejs.js
  2. +24 −0 src/yui/js/yui.js
View
@@ -60,8 +60,8 @@
var mod = new Module(url, module);
mod.filename = url;
mod.paths = Module._nodeModulePaths(path.dirname(url));
- if (typeof YUI.getLoadHook === 'function') {
- data = YUI.getLoadHook(data, url);
+ if (typeof YUI._getLoadHook === 'function') {
+ data = YUI._getLoadHook(data, url);
}
mod._compile('module.exports = function (YUI) {' + data + '\n;return YUI;};', url);
View
@@ -1494,6 +1494,30 @@ Y.log('Fetching loader: ' + config.base + config.loaderPath, 'info', 'yui');
// Support the CommonJS method for exporting our single global
if (typeof exports == 'object') {
exports.YUI = YUI;
+ /**
+ * Set a method to be called when `Get.script` is called in Node.js
+ * `Get` will open the file, then pass it's content and it's path
+ * to this method before attaching it. Commonly used for code coverage
+ * instrumentation. <strong>Calling this multiple times will only
+ * attach the last hook method</strong>. This method is only
+ * available in Node.js.
+ * @method setLoadHook
+ * @static
+ * @param {Function} fn The function to set
+ * @param {String} fn.data The content of the file
+ * @param {String} fn.path The file path of the file
+ */
+ YUI.setLoadHook = function(fn) {
+ YUI._getLoadHook = fn;
+ };
+ /**
+ * Load hook for `Y.Get.script` in Node.js, see `YUI.setLoadHook`
+ * @method _getLoadHook
+ * @private
+ * @param {String} data The content of the file
+ * @param {String} path The file path of the file
+ */
+ YUI._getLoadHook = null;
}
}());

0 comments on commit e879dd3

Please sign in to comment.