3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
7 YUI.add('get-nodejs', function(Y) {
10 * NodeJS specific Get module used to load remote resources. It contains the same signature as the default Get module so there is no code change needed.
11 * Note: There is an added method called Get.domScript, which is the same as Get.script in a browser, it simply loads the script into the dom tree
12 * so that you can call outerHTML on the document to print it to the screen.
16 var path = require('path');
18 Y.config.base = path.join(__dirname, '../');
19 console.log(Y.config);
21 YUI.add('get', function() { });
23 var end = function(cb, msg, result) {
24 if (Y.Lang.isFunction(cb.onEnd)) {
25 cb.onEnd.call(Y, msg, result);
27 }, pass = function(cb) {
28 if (Y.Lang.isFunction(cb.onSuccess)) {
29 cb.onSuccess.call(Y, cb);
31 end(cb, 'success', 'success');
32 }, fail = function(cb, er) {
33 if (Y.Lang.isFunction(cb.onFailure)) {
34 cb.onFailure.call(Y, er, cb);
39 Y.Get = function() {};
42 * Override for Get.script for loading local or remote YUI modules.
44 Y.Get.script = function(s, cb) {
46 urls = A(s), url, i, l = urls.length;
50 url = url.replace(/'/g, '%27');
51 // doesn't need to be blocking, so don't block.
52 include(url, function(err) {
60 A.each(err.stack.split('\n'), function(frame) {
74 var vm = require('vm'),
78 var include = function(url, cb) {
79 var mod = fs.readFileSync(url, 'utf8');
80 var script = vm.createScript(mod, url);
84 console.log('YUI in the sandbox');
85 console.log(arguments);
86 YUI.apply(YUI, arguments);
91 script.runInNewContext(box);
97 }, '3.5.0' ,{requires:['yui-base']});