Skip to content

Instantly share code, notes, and snippets.

@pangratz
Created June 27, 2012 22:17
Show Gist options
  • Save pangratz/3007220 to your computer and use it in GitHub Desktop.
Save pangratz/3007220 to your computer and use it in GitHub Desktop.
Replace Undefined with string
//original ember version
Ember.getPath = function(root, path) {
var hasThis, isGlobal, ret;
// Helpers that operate with 'this' within an #each
if (path === '') {
return root;
}
if (!path && 'string'===typeof root) {
path = root;
root = null;
}
path = cleanupStars(path);
// If there is no root and path is a key name, return that
// property from the global object.
// E.g. getPath('Ember') -> Ember
if (root === null && path.indexOf('.') < 0) { return get(window, path); }
// detect complicated paths and normalize them
path = normalizePath(path);
hasThis = HAS_THIS.test(path);
if (!root || hasThis) {
var tuple = normalizeTuple(root, path);
root = tuple[0];
path = tuple[1];
tuple.length = 0;
}
return getPath(root, path);
};
var getPath = Ember.getPath;
// Overwrite the original and add the OMG 'feature'
// @pangratz solution
Ember.getPath = function(obj, path) {
var value = getPath(obj, path);
if (obj === App.objectWhichHasUndefinedProps) {
return (Ember.none(value) ? 'OMG %@ is not defined!!'.fmt(path) : value);
}
return value;
};
@pangratz
Copy link
Author

To be clear, you just have to add the part starting from line #36 to your code...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment