Skip to content

Commit

Permalink
Setup YUI.setLoadHook and it's docs
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Jan 10, 2013
1 parent 0e6f7cd commit e879dd3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/get/js/get-nodejs.js
Expand Up @@ -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);

Expand Down
24 changes: 24 additions & 0 deletions src/yui/js/yui.js
Expand Up @@ -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;
}

}());
Expand Down

0 comments on commit e879dd3

Please sign in to comment.