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
//Y.log('Get end: ' + cb.onEnd);
25
if (Y.Lang.isFunction(cb.onEnd)) {
26
cb.onEnd.call(Y, msg, result);
28
}, pass = function(cb) {
29
//Y.log('Get pass: ' + cb.onSuccess);
30
if (Y.Lang.isFunction(cb.onSuccess)) {
31
cb.onSuccess.call(Y, cb);
33
end(cb, 'success', 'success');
34
}, fail = function(cb, er) {
35
//Y.log('Get fail: ' + er);
36
if (Y.Lang.isFunction(cb.onFailure)) {
37
cb.onFailure.call(Y, er, cb);
42
Y.Get = function() {};
45
* Override for Get.script for loading local or remote YUI modules.
47
Y.Get.script = function(s, cb) {
49
urls = A(s), url, i, l = urls.length;
53
url = url.replace(/'/g, '%27');
54
Y.log('URL: ' + url, 'info', 'get');
55
// doesn't need to be blocking, so don't block.
56
include(url, function(err) {
62
Y.log('Loaded: ' + url, 'info', 'get');
64
Y.log('----------------------------------------------------------', 'error', 'nodejsYUI3');
66
A.each(err.stack.split('\n'), function(frame) {
67
Y.log(frame, 'error', 'nodejsYUI3');
72
Y.log('----------------------------------------------------------', 'error', 'nodejsYUI3');
82
var vm = require('vm'),
86
var include = function(url, cb) {
87
var mod = fs.readFileSync(url, 'utf8');
88
var script = vm.createScript(mod, url);
92
console.log('YUI in the sandbox');
93
console.log(arguments);
94
YUI.apply(YUI, arguments);
99
script.runInNewContext(box);
105
}, '3.5.0' ,{requires:['yui-base']});