Skip to content

Instantly share code, notes, and snippets.

@scott2449
Created April 26, 2011 02:55
Show Gist options
  • Save scott2449/941713 to your computer and use it in GitHub Desktop.
Save scott2449/941713 to your computer and use it in GitHub Desktop.
ref.js
//...
var target = defaultObject || it;
//=================================================================================================================================================
// BEGIN - Customizations to produce real RESTful URIs instead from representation hierarchy instead of the shameless excuse for URIs dojo is producing
//=================================================================================================================================================
var targUrl = prefix.substring(0, prefix.length - 1);;
var stack = new Array();
var crawler = target;
if( crawler.__parent && crawler.__parent.id ){
if(id && id.indexOf('#')>-1){
stack.push(id.substr(id.lastIndexOf('#')));
}else{
stack.push("Attributes/"+it[idAttribute]);
}
}
else{stack.push(it[idAttribute]);} //push the target objects identifier to the stack, if the parent is a first level resource add /Attributes
while(crawler.__parent){
stack.push(crawler.__parent.id || crawler.__parent.__id.substr(crawler.__parent.__id.lastIndexOf('#')+1)); //Push the parents id or absolute (jsonref) id to the stack
crawler = crawler.__parent;
}
while(stack.length > 0){
var curr = stack.pop();
if(curr){
targUrl+=(curr.indexOf('#')>-1?'':'/')+ curr; //pop them all off to build RESTful URI
}
}
id = targUrl;
//=================================================================================================================================================
// END - Customizations to produce real RESTful URIs instead from representation hierarchy instead of the shameless excuse for URIs dojo is producing
//=================================================================================================================================================
if(id !== undefined){ // if there is an id available...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment