Skip to content

Commit

Permalink
Added comments to RLS code so it's understandable. Also added CSS fil…
Browse files Browse the repository at this point in the history
…e support and lang support
  • Loading branch information
davglass committed Jan 12, 2011
1 parent 868eb04 commit 59dd82c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
5 changes: 3 additions & 2 deletions examples/rls.js
Expand Up @@ -9,8 +9,9 @@ yui3.rls({
gv: '2010.09.22',
'2in3v': '0.0.3'//,
//filt: 'RAW',
}, function(files) {
}, function(js, css) {
console.log('Callback..');
console.log(files);
console.log(js);
console.log(css);
});

48 changes: 42 additions & 6 deletions lib/node-yui3.js
Expand Up @@ -62,49 +62,80 @@ interface.configure = function (config) {
return new YInterface(config);
};

/**
* This method accepts the default RLS configuration object and returns two arrays of file paths for js and css files.
* @method rls
* @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.
*/
interface.rls = function(config, fn) {
//The config to create the YUI instance with
var c = {
core: config.v,
gallery: config.gv,
yui2: config['2v'] || config['2in3v']
};

var YUI = getYUI(c);

//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 = {};

var Y = YUI();
//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) {
//Preloading what's already on the page, telling the script to NOT grab the files until it's done
grab = false;
//Using the modules that are already on the page.
Y.useSync.apply(Y, config.env.split(','));
grab = true;
}
//No .m given, giving it a default

//No config.m given, giving it a default
if (!config.m) {
config.m = 'yui,loader'; //Default here?
}
Expand All @@ -124,6 +155,7 @@ interface.rls = function(config, fn) {
//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 = '';
Expand All @@ -139,7 +171,11 @@ interface.rls = function(config, fn) {
files[k] = v.replace('-min', str);
});
}
fn(files);
//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;

0 comments on commit 59dd82c

Please sign in to comment.