Skip to content
Browse files

much cleaner version

  • Loading branch information...
1 parent c887ccf commit bd6cd5f529d5cc87be7df539de0c5791c41eb257 @drewfish committed Oct 3, 2012
Showing with 19 additions and 23 deletions.
  1. +19 −23 lib/app/addons/rs/yui.server.js
View
42 lib/app/addons/rs/yui.server.js
@@ -178,7 +178,7 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
var fs = source.fs,
baseParts,
res,
- parts;
+ sandbox;
if ('yui-lang' === type) {
res = {
@@ -191,28 +191,15 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
if (!res.yui) {
res.yui = {};
}
- if (fs.basename === mojitType) {
- res.yui.lang = '';
- res.yui.langFor = mojitType;
- } else if (mojitType === fs.basename.substr(0, mojitType.length)) {
- res.yui.lang = fs.basename.substr(mojitType.length + 1);
- res.yui.langFor = mojitType;
- } else if ('shared' === mojitType) {
- // Supporting global (AKA shared) language bundles isn't
- // really supported, since it's tricky to determine the
- // language name from the filename. The hack below is a
- // quick but restrictive way to do that.
- parts = fs.basename.split('_');
- res.yui.lang = '';
- res.yui.langFor = fs.basename;
- if (parts.length > 1) {
- res.yui.lang = parts.pop();
- res.yui.langFor = parts.join('_');
+ sandbox = {
+ Intl: {
+ add: function(langFor, lang) {
+ res.yui.langFor = langFor;
+ res.yui.lang = lang;
+ }
}
- } else {
- Y.log('invalid YUI lang file format. skipping ' + fs.fullPath, 'error', NAME);
- }
- this._captureYUIModuleDetails(res);
+ };
+ this._captureYUIModuleDetails(res, sandbox);
res.name = res.yui.name;
res.id = [res.type, res.subtype, res.name].join('-');
return new Y.Do.Halt(null, res);
@@ -612,9 +599,11 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
* @private
* @method _captureYUIModuleDetails
* @param {object} res resource metadata
+ * @param {object} runSandbox if passed, the function in the module
+ * will be called using this parameter as the YUI sandbox
* @return {nothing}
*/
- _captureYUIModuleDetails: function(res) {
+ _captureYUIModuleDetails: function(res, runSandbox) {
var file,
ctx,
yui = {};
@@ -636,6 +625,13 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
if (!yui.meta.requires) {
yui.meta.requires = [];
}
+ if (runSandbox) {
+ try {
+ fn(runSandbox, yui.name);
+ } catch (e) {
+ Y.log('failed to run javascript file ' + res.source.fs.fullPath + '\n' + e.message, 'error', NAME);
+ }
+ }
}
}
};

0 comments on commit bd6cd5f

Please sign in to comment.
Something went wrong with that request. Please try again.