You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.6 KiB
JavaScript
72 lines
1.6 KiB
JavaScript
|
|
module.exports = function niceNames () {
|
|
var ngScopeElts = document.getElementsByClassName('ng-scope');
|
|
ngScopeElts = Array.prototype.slice.call(ngScopeElts);
|
|
return ngScopeElts.
|
|
map(angular.element).
|
|
reduce(accumulateElements, {});
|
|
|
|
function accumulateElements (acc, elt) {
|
|
acc[elt.scope().$id] = nameElement(elt);
|
|
return acc;
|
|
}
|
|
|
|
};
|
|
|
|
|
|
var interestingAttributes = {
|
|
'ng-app': function (value) {
|
|
// body...
|
|
},
|
|
'ng-controller': function (value) {
|
|
// body...
|
|
},
|
|
'ng-repeat': function (value) {
|
|
var match = /(.+) in/.exec(val);
|
|
var lhs = match[1];
|
|
|
|
match = lhs.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/);
|
|
var valueIdentifier = match[3] || match[1];
|
|
var keyIdentifier = match[2];
|
|
|
|
name.lhs = valueIdentifier +
|
|
(keyIdentifier ? '["' + scope[keyIdentifier] + '"]' : '') +
|
|
summarizeObject(scope[valueIdentifier]);
|
|
}
|
|
};
|
|
|
|
|
|
function nameElement (element) {
|
|
var scope = element.scope(),
|
|
name = {};
|
|
|
|
Object.keys(interestingAttributes).forEach(function (attributeName) {
|
|
|
|
})
|
|
|
|
return Object.keys(name).length > 0 ? name : boringName(element);
|
|
}
|
|
|
|
function boringName ($elt) {
|
|
return {
|
|
tag: $elt[0].tagName.toLowerCase(),
|
|
name: $elt[0].className.
|
|
replace(/(\W*ng-scope\W*)/, ' ').
|
|
split(' ').
|
|
filter(function (i) { return i; })
|
|
}
|
|
}
|
|
|
|
function parseAttributeValue (attr) {
|
|
var val = $elt.attr(attr),
|
|
className;
|
|
|
|
if (!val && className.indexOf(attr) !== -1) {
|
|
|
|
className = $elt[0].className;
|
|
|
|
match = (new RegExp(attr + ': ([a-zA-Z0-9]+);')).exec(className);
|
|
val = match[1];
|
|
}
|
|
}
|