Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some updates for the RLS implementation

  • Loading branch information...
commit 4cc3ba878925870cd3eca27234e62a7e2ca47f1d 1 parent 4888a8b
@davglass authored
View
8 README.textile
@@ -94,13 +94,13 @@ h2. Tests
When using JSDom, All relevent YUI 3 Dom & Selector tests pass. The ones that are skipped revolve around styles and postioning. Since there is no window or CSS cascade, these seem unimportant at the moment.
+Testing is pretty simple now once you install `expresso`:
+
<pre class="console">
- cd ./tests/
- ./dom.js
- ./selector.js
+ npm install expresso
+ expresso ./tests/*.js
</pre>
-
h2. License
This software is offered under the terms of the BSD license. See the LICENSE file or the "YUI License":http://developer.yahoo.com/yui/license.html for license text and copyright information.
View
11 examples/rls.js
@@ -9,9 +9,18 @@ yui3.rls({
gv: '2010.09.22',
'2in3v': '0.0.3'//,
//filt: 'RAW',
-}, function(js, css) {
+}, function(js, css, data) {
console.log('Callback..');
console.log(js);
console.log(css);
+ //console.log(data);
+ /*
+ for (var i in data) {
+ console.log('i: ', i, (data[i].length));
+ }
+ */
+ console.log('Total: ', [].concat(js, css).length);
+ console.log('Data: ', Object.keys(data).length);
+
});
View
98 lib/node-yui3.js
@@ -78,104 +78,8 @@ interface.rls = function(config, fn) {
};
var YUI = getYUI(c);
+ require('./yui3-rls').rls(YUI, config, fn);
- //This deletes all custom NodeJS YUI modules (jsdom, io, etc)
- delete YUI.GlobalConfig.modules;
- //Set this instance to no debugging so it never console logs anything
- YUI.GlobalConfig.debug = false;
- //Replace the default -debug with -min so all the files are -min files.
- YUI.GlobalConfig.loaderPath = YUI.GlobalConfig.loaderPath.replace('-debug', '-min');
-
- //Add the default yui file, in case we are working with a full combo file.
- var files = [YUI.GlobalConfig.base + 'yui/yui-min.js'];
-
- //Here we will displace 2 default methods and override them.
- var inc = YUI.include;
- var add = YUI.add;
-
- //Override for YUI.add so that the wrapped fn in modules never get's executed (faster, since we only actually need the module requirements and not the modules code.)
- YUI.add = function(name, fn, version, args) {
- //This keeps everything but Loader from executing it's wrapped function
- if (name.indexOf('loader') === -1) {
- fn = function() {};
- }
- //Call the original add method with the new noop function if needed.
- add.call(YUI, name, fn, version, args);
- };
-
- //Here is where we grab the filename of the file that is requested.
- YUI.include = function(file, cb) {
- if (grab) {
- files.push(file);
- }
- //Call the original YUI.include.
- inc(file, function(err, data) {
- cb(null, function() {});
- });
- }
- //Setup the YUI instance config
- var yc = {};
-
- //Add the lang property
- if (config.lang) {
- yc.lang = config.lang;
- }
-
- //Create the new instance.
- var Y = YUI(yc);
- //Tell the YUI.include file that it can grab files.
- var grab = true;
-
- //Preloading what's already on the page, telling the YUI.include function
- // to NOT grab the files until it's done
- if (config.env) {
- grab = false;
- //Using the modules that are already on the page.
- Y.useSync.apply(Y, config.env.split(','));
- grab = true;
- }
-
- //No config.m given, giving it a default
- if (!config.m) {
- config.m = 'yui,loader'; //Default here?
- }
-
- //Now we use the modules they are asking for..
- var mods = config.m.split(',');
- Y.useSync.apply(Y, mods);
-
- //If yui is NOT in the config.m list, drop it from the array
- if (mods.indexOf('yui') === -1) {
- files.splice(0, 1);
- }
- //If loader is NOT in the config.m list, drop it from the array
- if (mods.indexOf('loader') === -1) {
- files.splice(0, 1);
- }
- //Filter the URL's
- if (config.filt) {
- var str = '';
- //This just does the string replaces on the file names
- switch (config.filt.toLowerCase()) {
- case 'raw':
- str = '';
- break;
- case 'debug':
- str = '-debug';
- break;
- default:
- str = '-min';
- break;
- }
- files.forEach(function(v, k) {
- files[k] = v.replace('-min', str);
- });
- }
- //Now we fire the callback with the files array and the Y.config._cssLoad arrays
- /**
- * Y.config._cssLoad is an internal YUINodeJS holder for CSS files taken from Y.Get.css()
- */
- fn(files, Y.config._cssLoad);
}
module.exports = new YInterface;
View
153 lib/yui3-rls.js
@@ -0,0 +1,153 @@
+/**
+* This method accepts the default RLS configuration object and returns two arrays of file paths for js and css files.
+* @method rls
+* @param {YUI} YUI The YUI instance to use when creating an RLS server.
+* @param {Object} config The RLS configuration to work from
+* @param {Function} fn The callback executed when the process is completed
+* @returns {Callback} js, css Callback returns two arguments. Both arrays of file paths, one for JS and one for CSS files.
+*/
+exports.rls = function(YUI, config, fn) {
+
+ //This deletes all custom NodeJS YUI modules (jsdom, io, etc)
+ delete YUI.GlobalConfig.modules;
+ //Set this instance to no debugging so it never console logs anything
+ YUI.GlobalConfig.debug = false;
+ //Replace the default -debug with -min so all the files are -min files.
+ YUI.GlobalConfig.loaderPath = YUI.GlobalConfig.loaderPath.replace('-debug', '-min');
+
+ //Add the default yui file, in case we are working with a full combo file.
+ var files = [YUI.GlobalConfig.base + 'yui/yui-min.js'],
+ fileData = {};
+
+ //Here we will displace 2 default methods and override them.
+ var inc = YUI.include;
+ var add = YUI.add;
+
+ //Override for YUI.add so that the wrapped fn in modules never get's executed (faster, since we only actually need the module requirements and not the modules code.)
+ YUI.add = function(name, fn, version, args) {
+ //This keeps everything but Loader from executing it's wrapped function
+ if (name.indexOf('loader') === -1) {
+ fn = function() {};
+ }
+ //Call the original add method with the new noop function if needed.
+ add.call(YUI, name, fn, version, args);
+ };
+
+ //Here is where we grab the filename of the file that is requested.
+ YUI.include = function(file, cb) {
+ if (grab) {
+ files.push(file);
+ }
+ //Call the original YUI.include.
+ inc(file, function(err, data, info) {
+ if (grab) {
+ fileData[info.file] = info.data;
+ }
+ cb(null, function() {});
+ });
+ }
+ //Setup the YUI instance config
+ var yc = {};
+
+ //Add the lang property
+ if (config.lang) {
+ yc.lang = config.lang;
+ }
+
+ //Create the new instance.
+ var Y = YUI(yc);
+ //Tell the YUI.include file that it can grab files.
+ var grab = true;
+
+ //Preloading what's already on the page, telling the YUI.include function
+ // to NOT grab the files until it's done
+ if (config.env) {
+ grab = false;
+ //Using the modules that are already on the page.
+ Y.useSync.apply(Y, config.env.split(','));
+ grab = true;
+ }
+
+ //No config.m given, giving it a default
+ if (!config.m) {
+ config.m = 'yui,loader'; //Default here?
+ }
+
+ //Now we use the modules they are asking for..
+ var mods = config.m.split(',');
+ Y.useSync.apply(Y, mods);
+
+ //If yui is NOT in the config.m list, drop it from the array
+ if (mods.indexOf('yui') === -1) {
+ if (files[0].indexOf('yui')) {
+ files.splice(0, 1);
+ }
+ }
+ //If loader is NOT in the config.m list, drop it from the array
+ if (mods.indexOf('loader') === -1) {
+ if (files[0].indexOf('loader')) {
+ files.splice(0, 1);
+ }
+ }
+ //Filter the URL's
+ if (config.filt) {
+ var str = '';
+ //This just does the string replaces on the file names
+ switch (config.filt.toLowerCase()) {
+ case 'raw':
+ str = '';
+ break;
+ case 'debug':
+ str = '-debug';
+ break;
+ default:
+ str = '-min';
+ break;
+ }
+ files.forEach(function(v, k) {
+ files[k] = v.replace('-min', str);
+ });
+ }
+ //Now we fire the callback with the files array and the Y.config._cssLoad arrays
+ /**
+ * Y.config._cssLoad is an internal YUINodeJS holder for CSS files taken from Y.Get.css()
+ */
+ var complete = function() {
+ //Sanity Check, remove any files from the
+ // fileData object if they are not in the files or css list
+ var d = {};
+ [].concat(files, Y.config._cssLoad).forEach(function(v) {
+ d[v] = fileData[v];
+ });
+ fn(files, Y.config._cssLoad, d);
+ };
+ var checkComplete = function() {
+ if (missing.length === 0) {
+ complete();
+ }
+ }
+
+ var missing = [];
+ var c = 1;
+ [].concat(files, Y.config._cssLoad).forEach(function(v) {
+ if (!fileData[v]) {
+ missing.push(v);
+ }
+ });
+
+ if (missing.length) {
+ var fs = require('fs');
+ missing.forEach(function(v) {
+ fs.readFile(v, encoding='utf8', (function(fileName) {
+ return function(err, data) {
+ fileData[fileName] = data;
+ missing.splice(missing.indexOf(fileName), 1);
+ checkComplete();
+ }
+ })(v));
+ });
+ } else {
+ complete();
+ }
+
+};
View
2  lib/yui3-yui3.js
@@ -310,7 +310,7 @@ exports.configure = function(c) {
var fn = process.compile(mod, file);
YUI = fn(YUI);
//cb(null, YUI);
- cb(null, fn);
+ cb(null, fn, { file: file, data: data });
} catch(err) {
cb(err);
}
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "yui3",
- "version": "0.5.18",
+ "version": "0.5.19",
"description": "YUI 3 Library on NodeJS",
"author": "Dav Glass <davglass@gmail.com>",
"bugs": { "web" : "http://github.com/davglass/nodejs-yui3/issues" },
View
45 tests/interface.js
@@ -35,93 +35,101 @@ module.exports = {
"rls-full": function() {
yui3.rls({
m: 'yui,loader,dd,widget,autocomplete,gallery-yql,yui2-datatable',
- v: '3.3.0pr3',
+ v: '3.3.0',
gv: '2010.09.22',
'2in3v': '0.0.3'
- }, function(js, css) {
+ }, function(js, css, data) {
assert.equal(js.length, 33);
assert.equal(css.length, 4);
+ assert.equal([].concat(js, css).length, Object.keys(data).length);
});
},
"rls-mods": function() {
yui3.rls({
m: 'dd,widget,autocomplete,gallery-yql,yui2-datatable',
//env: 'node,attribute',
- v: '3.3.0pr3',
+ v: '3.3.0',
gv: '2010.09.22',
'2in3v': '0.0.3'//,
//filt: 'RAW',
- }, function(js, css) {
+ }, function(js, css, data) {
assert.equal(js.length, 31);
assert.equal(css.length, 4);
+ assert.equal((js.length + css.length), Object.keys(data).length);
+
});
},
"rls-env": function() {
yui3.rls({
m: 'dd,widget,autocomplete,gallery-yql,yui2-datatable',
env: 'node,attribute',
- v: '3.3.0pr3',
+ v: '3.3.0',
gv: '2010.09.22',
'2in3v': '0.0.3'//,
//filt: 'RAW',
- }, function(js, css) {
+ }, function(js, css, data) {
assert.equal(js.length, 26);
assert.equal(css.length, 4);
+ assert.equal([].concat(js, css).length, Object.keys(data).length);
});
},
"rls-filter-raw": function() {
yui3.rls({
m: 'dd,widget,autocomplete,gallery-yql,yui2-datatable',
env: 'node,attribute',
- v: '3.3.0pr3',
+ v: '3.3.0',
gv: '2010.09.22',
'2in3v': '0.0.3',
filt: 'RAW'
- }, function(js, css) {
+ }, function(js, css, data) {
assert.equal(js.length, 26);
assert.equal(css.length, 4);
assert.ok(js[0].indexOf('classnamemanager.js') > 0);
+ assert.equal([].concat(js, css).length, Object.keys(data).length);
});
},
"rls-filter-min": function() {
yui3.rls({
m: 'dd,widget,autocomplete,gallery-yql,yui2-datatable',
env: 'node,attribute',
- v: '3.3.0pr3',
+ v: '3.3.0',
gv: '2010.09.22',
'2in3v': '0.0.3',
filt: 'MIN'
- }, function(js, css) {
+ }, function(js, css, data) {
assert.equal(js.length, 26);
assert.equal(css.length, 4);
assert.ok(js[0].indexOf('classnamemanager-min.js') > 0);
+ assert.equal([].concat(js, css).length, Object.keys(data).length);
});
},
"rls-filter-debug": function() {
yui3.rls({
m: 'dd,widget,autocomplete,gallery-yql,yui2-datatable',
env: 'node,attribute',
- v: '3.3.0pr3',
+ v: '3.3.0',
gv: '2010.09.22',
'2in3v': '0.0.3',
filt: 'DEBUG'
- }, function(js, css) {
+ }, function(js, css, data) {
assert.equal(js.length, 26);
assert.equal(css.length, 4);
assert.ok(js[0].indexOf('classnamemanager-debug.js') > 0);
+ assert.equal([].concat(js, css).length, Object.keys(data).length);
});
},
"rls-version-33": function() {
yui3.rls({
m: 'dd,widget,autocomplete,gallery-yql,yui2-datatable',
env: 'node,attribute',
- v: '3.3.0pr3',
+ v: '3.3.0',
gv: '2010.09.22',
'2in3v': '0.0.3'
- }, function(js, css) {
+ }, function(js, css, data) {
assert.equal(js.length, 26);
assert.equal(css.length, 4);
assert.ok(js[0].indexOf('3.3.0') > 0);
+ assert.equal([].concat(js, css).length, Object.keys(data).length);
});
},
"rls-version-32": function() {
@@ -131,10 +139,11 @@ module.exports = {
v: '3.2.0',
gv: '2010.09.22',
'2in3v': '0.0.3'
- }, function(js, css) {
+ }, function(js, css, data) {
assert.equal(js.length, 15);
assert.equal(css.length, 2);
assert.ok(js[0].indexOf('3.2.0') > 0);
+ assert.equal([].concat(js, css).length, Object.keys(data).length);
});
},
"rls-version-gallery": function() {
@@ -144,7 +153,7 @@ module.exports = {
v: '3.2.0',
gv: '2010.09.22',
'2in3v': '0.0.3'
- }, function(js, css) {
+ }, function(js, css, data) {
assert.equal(js.length, 15);
assert.equal(css.length, 2);
js.forEach(function(v) {
@@ -152,6 +161,7 @@ module.exports = {
assert.ok(v.indexOf('2010.09.22') > 0);
}
});
+ assert.equal([].concat(js, css).length, Object.keys(data).length);
});
},
"rls-version-yui2": function() {
@@ -161,7 +171,7 @@ module.exports = {
v: '3.2.0',
gv: '2010.09.22',
'2in3v': '0.0.2'
- }, function(js, css) {
+ }, function(js, css, data) {
assert.equal(js.length, 15);
assert.equal(css.length, 2);
js.forEach(function(v) {
@@ -169,6 +179,7 @@ module.exports = {
assert.ok(v.indexOf('0.0.2') > 0);
}
});
+ assert.equal([].concat(js, css).length, Object.keys(data).length);
});
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.