Permalink
Browse files

Added useSync support to the require, so YUI can be required inside a…

…nother require and it's assets can be exported
  • Loading branch information...
1 parent bca0748 commit 52d6bc74717c4fc5ab4b704df8611d3ec58f975d @davglass davglass committed Nov 20, 2010
Showing with 42 additions and 10 deletions.
  1. +42 −10 lib/node-yui3.js
View
@@ -66,7 +66,7 @@ YUI.GlobalConfig = {
modules: {
'parallel': {
requires: ['oop'],
- fullpath: __dirname + '/parallel.js',
+ fullpath: __dirname + '/yui3-parallel.js',
condition: {
when: 'after',
trigger: 'oop',
@@ -76,11 +76,11 @@ YUI.GlobalConfig = {
}
},
'express': {
- requires: ['substitute'],
- fullpath: __dirname + '/express.js'
+ requires: ['substitute', 'node'],
+ fullpath: __dirname + '/yui3-express.js'
},
'nodejs-dom': {
- fullpath: __dirname + '/dom.js',
+ fullpath: __dirname + '/yui3-dom.js',
condition: {
when: 'before',
trigger: 'dom-base',
@@ -91,7 +91,7 @@ YUI.GlobalConfig = {
},
'nodejs-node': {
requires: ['node'],
- fullpath: __dirname + '/node.js',
+ fullpath: __dirname + '/yui3-node.js',
condition: {
when: 'after',
trigger: 'node',
@@ -101,7 +101,7 @@ YUI.GlobalConfig = {
}
},
'io-nodejs': {
- fullpath: __dirname + '/io.js',
+ fullpath: __dirname + '/yui3-io.js',
condition: {
when: 'after',
trigger: 'io',
@@ -311,7 +311,29 @@ YUI.prototype.use = function() {
return this;
}
+YUI.loadSync = false;
+
exports.YUI = YUI;
+exports.sync = function() {
+ YUI.loadSync = true;
+ return YUI();
+};
+exports.async = function() {
+ YUI.loadSync = false;
+ return YUI();
+};
+
+exports.useSync = function() {
+ YUI.loadSync = true;
+ var Y = YUI();
+ return Y.use.apply(Y, arguments);
+}
+
+exports.use = function() {
+ YUI.loadSync = false;
+ var Y = YUI();
+ return Y.use.apply(Y, arguments);
+}
/**
@@ -343,7 +365,9 @@ YUI.include = function(file, cb) {
* This is the fancy stepping required to get the module to eval into the local scope
*/
var dirName = path.dirname(file);
- require.paths.unshift(dirName);
+ //require.paths.unshift(dirName);
+ require.paths.push(dirName);
+ var _require = require;
var mod = "(function(YUI) { var __dirname = '" + dirName + "'; "+
"var __filename = '" + file + "'; " +
"var process = YUI.process;" +
@@ -394,7 +418,12 @@ YUI.include = function(file, cb) {
} else {
//Load the file locally
- fs.readFile(file, encoding='utf8', loaderFn);
+ if (YUI.loadSync) {
+ var data = fs.readFileSync(file, encoding='utf8');
+ loaderFn(null, data);
+ } else {
+ fs.readFile(file, encoding='utf8', loaderFn);
+ }
}
};
@@ -470,9 +499,12 @@ YUI.add('get', function(Y) {
Y.log('URL: ' + url, 'info', 'get');
// doesn't need to be blocking, so don't block.
YUI.include(url, function(err) {
- if (Y.config) {
- Y.log('Loaded: ' + url, 'info', 'get');
+ if (!Y.config) {
+ Y.config = {
+ debug: true
+ };
}
+ Y.log('Loaded: ' + url, 'info', 'get');
if (err) {
Y.log('----------------------------------------------------------', 'error', 'nodejsYUI3');
if (err.stack) {

0 comments on commit 52d6bc7

Please sign in to comment.