1
/* YUI 3.9.1 (build 5852) Copyright 2013 Yahoo! Inc. http://yuilibrary.com/license/ */
2
YUI.add('get', function (Y, NAME) {
5
* NodeJS specific Get module used to load remote resources.
6
* It contains the same signature as the default Get module so there is no code change needed.
11
var Module = require('module'),
13
path = require('path'),
15
request = require('request'),
16
end = function(cb, msg, result) {
17
if (Y.Lang.isFunction(cb.onEnd)) {
18
cb.onEnd.call(Y, msg, result);
20
}, pass = function(cb) {
21
if (Y.Lang.isFunction(cb.onSuccess)) {
22
cb.onSuccess.call(Y, cb);
24
end(cb, 'success', 'success');
25
}, fail = function(cb, er) {
27
if (Y.Lang.isFunction(cb.onFailure)) {
28
cb.onFailure.call(Y, er, cb);
37
//Setup the default config base path
38
Y.config.base = path.join(__dirname, '../');
40
YUI.require = require;
41
YUI.process = process;
44
* Takes the raw JS files and wraps them to be executed in the YUI context so they can be loaded
48
* @param {String} data The JS to execute
49
* @param {String} url The path to the file that was parsed
50
* @param {Callback} cb The callback to execute when this is completed
51
* @param {Error} cb.err=null Error object
52
* @param {String} cb.url The URL that was just parsed
55
Y.Get._exec = function(data, url, cb) {
56
if (data.charCodeAt(0) === 0xFEFF) {
60
var mod = new Module(url, module);
62
mod.paths = Module._nodeModulePaths(path.dirname(url));
63
if (typeof YUI._getLoadHook === 'function') {
64
data = YUI._getLoadHook(data, url);
66
mod._compile('module.exports = function (YUI) {' + data + '\n;return YUI;};', url);
69
YUI = mod.exports(YUI);
77
* Fetches the content from a remote URL or a file from disc and passes the content
78
* off to `_exec` for parsing
81
* @param {String} url The URL/File path to fetch the content from
82
* @param {Callback} cb The callback to fire once the content has been executed via `_exec`
84
Y.Get._include = function (url, cb) {
89
if (url.match(/^https?:\/\//)) {
94
request(cfg, function (err, response, body) {
98
Y.Get._exec(body, url, cb);
103
// Try to resolve paths relative to the module that required yui.
104
url = Module._findPath(url, Module._resolveLookupPaths(url, module.parent.parent)[1]);
106
if (Y.config.useSync) {
107
//Needs to be in useSync
108
mod = fs.readFileSync(url,'utf8');
110
fs.readFile(url, 'utf8', function (err, mod) {
114
Y.Get._exec(mod, url, cb);
124
Y.Get._exec(mod, url, cb);
130
* Override for Get.script for loading local or remote YUI modules.
132
* @param {Array|String} s The URL's to load into this context
133
* @param {Object} options Transaction options
135
Y.Get.js = function(s, options) {
136
var urls = Y.Array(s), url, i, l = urls.length, c= 0,
144
/*jshint loopfunc: true */
145
for (i=0; i<l; i++) {
147
if (Y.Lang.isObject(url)) {
151
url = url.replace(/'/g, '%27');
152
Y.Get._include(url, function(err, url) {
158
if (options.onProgress) {
159
options.onProgress.call(options.context || Y, url);
170
//Keeping Signature in the browser.
172
execute: function() {}
177
* Alias for `Y.Get.js`
180
Y.Get.script = Y.Get.js;
182
//Place holder for SS Dom access
183
Y.Get.css = function(s, cb) {