From 0350bcd749d1aa68e7cb8c142ccfd7af9ee6452b Mon Sep 17 00:00:00 2001 From: Martin Gontovnikas Date: Fri, 3 May 2013 20:28:11 -0300 Subject: [PATCH] feat(url): Url now supports unescaped suffix Fixes #45 --- dist/restangular.js | 4 ++-- dist/restangular.min.js | 2 +- dist/restangular.zip | Bin 23719 -> 23637 bytes src/restangular.js | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/restangular.js b/dist/restangular.js index 6be5153d..98d38c0c 100644 --- a/dist/restangular.js +++ b/dist/restangular.js @@ -137,8 +137,8 @@ module.provider('Restangular', function() { } BaseCreator.prototype.resource = function(current, $resource, headers) { - var reqParams = suffix ? {restangularSuffix: suffix} : {}; - return $resource(this.base(current) + "/:" + restangularFields.what + ":restangularSuffix" , {}, { + var reqParams = {}; + return $resource(this.base(current) + "/:" + restangularFields.what + (suffix || '') , {}, { getList: {method: 'GET', params: reqParams, isArray: listTypeIsArray, headers: headers || {}}, get: {method: 'GET', params: reqParams, isArray: false, headers: headers || {}}, put: {method: 'PUT', params: reqParams, isArray: false, headers: headers || {}}, diff --git a/dist/restangular.min.js b/dist/restangular.min.js index 47be4adc..fde69132 100644 --- a/dist/restangular.min.js +++ b/dist/restangular.min.js @@ -5,4 +5,4 @@ * @author Martin Gontovnikas * @license MIT License, http://www.opensource.org/licenses/MIT */ -var module=angular.module("restangular",["ngResource"]);module.provider("Restangular",function(){function t(t){return _.contains(e,t)}var e=["get","head","options","trace"],r="";this.setBaseUrl=function(t){r=t};var n=[];this.setExtraFields=function(t){n=t};var i="path";this.setUrlCreator=function(t){if(!_.has(d,t))throw Error("URL Path selected isn't valid");i=t};var o={id:"id",route:"route",parentResource:"parentResource",restangularCollection:"restangularCollection",what:"restangularWhat"};this.setRestangularFields=function(t){o=_.extend(o,t)};var a=function(t){return t};this.setResponseExtractor=function(t){a=t},this.setResponseInterceptor=this.setResponseExtractor;var s=function(t){return t};this.setOnElemRestangularized=function(t){s=t};var u=!0;this.setListTypeIsArray=function(t){u=t};var c=null;this.setRequestSuffix=function(t){c=t};var d={},l=function(){};l.prototype.parentsArray=function(t){for(var e=[];!_.isUndefined(t);)e.push(t),t=t[o.parentResource];return e.reverse()},l.prototype.resource=function(t,e,r){var n=c?{restangularSuffix:c}:{};return e(this.base(t)+"/:"+o.what+":restangularSuffix",{},{getList:{method:"GET",params:n,isArray:u,headers:r||{}},get:{method:"GET",params:n,isArray:!1,headers:r||{}},put:{method:"PUT",params:n,isArray:!1,headers:r||{}},post:{method:"POST",params:n,isArray:!1,headers:r||{}},remove:{method:"DELETE",params:n,isArray:!1,headers:r||{}},head:{method:"HEAD",params:n,isArray:!1,headers:r||{}},trace:{method:"TRACE",params:n,isArray:!1,headers:r||{}},options:{method:"OPTIONS",params:n,isArray:!1,headers:r||{}},patch:{method:"PATCH",params:n,isArray:!1,headers:r||{}}})};var h=function(){};h.prototype=new l,h.prototype.base=function(t){return r+_.reduce(this.parentsArray(t),function(t,e){var r=t+"/"+e[o.route];return e[o.restangularCollection]||(r+="/"+e[o.id]),r},"")},h.prototype.fetchUrl=function(t,e){var r=this.base(t);return e[o.what]&&(r+="/"+e[o.what]),r},d.path=h,this.$get=["$resource","$q",function(e,r){function u(t,e,r){if(e[o.route]=r,e.addRestangularMethod=_.bind(G,e),t){var i=_.union(_.values(_.pick(o,["id","route","parentResource"])),n);e[o.parentResource]=_.pick(t,i)}return e}function c(t,e,r){var n={};return n[o.id]=r,b(t,n,e)}function l(t,e){return g(t,{},e,!0)}function h(t,e){return t.call=_.bind(p,t),t.get=_.bind(f,t),t[o.restangularCollection]=e,e&&(t.push=_.bind(p,t,"push")),t}function p(t){var e=r.defer(),n=arguments;return this.then(function(r){var i=Array.prototype.slice.call(n,1),o=r[t];o.apply(r,i),e.resolve(r)}),h(e.promise,this[o.restangularCollection])}function f(t){var e=r.defer();return this.then(function(r){e.resolve(r[t])}),h(e.promise,this[o.restangularCollection])}function v(t){return _.omit(t,_.values(_.omit(o,"id")))}function m(t){t.customOperation=_.bind(I,t),_.each(["put","post","get","delete"],function(e){_.each(["do","custom"],function(r){var n=r+e.toUpperCase();t[n]=_.bind(I,t,e)})}),t.customGETLIST=_.bind(R,t),t.doGETLIST=t.customGETLIST}function b(t,e,r){var n=u(t,e,r);return n[o.restangularCollection]=!1,n.get=_.bind(C,n),n.getList=_.bind(R,n),n.put=_.bind(T,n),n.post=_.bind(L,n),n.remove=_.bind(E,n),n.head=_.bind(x,n),n.trace=_.bind(w,n),n.options=_.bind(U,n),n.patch=_.bind(S,n),n.one=_.bind(c,n,n),n.all=_.bind(l,n,n),m(n),s(n,!1,r)}function g(t,e,r){var n=u(t,e,r);return n[o.restangularCollection]=!0,n.post=_.bind(L,n,null),n.head=_.bind(x,n),n.trace=_.bind(w,n),n.options=_.bind(U,n),n.patch=_.bind(S,n),n.getList=_.bind(R,n,null),m(n),s(n,!0,r)}function y(t){var e={};return t&&(e[o.what]=t),e}function R(t,n,i){var s=y(t),u=this,c=r.defer();return O.resource(this,e,i).getList(_.extend(s,n),function(e){var r=a(e,"getList",t,O.fetchUrl(u,s)),n=_.map(r,function(e){return u[o.restangularCollection]?b(null,e,u[o.route]):b(u,e,t)});n=_.extend(r,n),u[o.restangularCollection]?c.resolve(g(null,n,u[o.route])):c.resolve(g(u,n,t))},function(t){c.reject(t)}),h(c.promise,!0)}function A(n,i,s,u){var c=this,d=r.defer(),l=i||{},p=s||this,f=function(t){var e=a(t,n,l[o.what]||c[o.route],O.fetchUrl(c,l))||p;"post"!==n||c[o.restangularCollection]?d.resolve(b(c[o.parentResource],e,c[o.route])):d.resolve(b(c,e,l[o.what]))},_=function(t){d.reject(t)};return t(n)?O.resource(this,e,u)[n](l,f,_):O.resource(this,e,u)[n](l,s||v(this),f,_),h(d.promise)}function C(t,e){return _.bind(A,this)("get",t,void 0,e)}function E(t,e){return _.bind(A,this)("remove",t,{},e)}function T(t,e){return _.bind(A,this)("put",t,void 0,e)}function L(t,e,r,n){return _.bind(A,this)("post",_.extend(y(t),r),e,n)}function x(t,e){return _.bind(A,this)("head",t,void 0,e)}function w(t,e){return _.bind(A,this)("trace",t,void 0,e)}function U(t,e){return _.bind(A,this)("options",t,void 0,e)}function S(t,e){return _.bind(A,this)("patch",t,void 0,e)}function I(t,e,r,n,i){return _.bind(A,this)(t,_.extend(y(e),r),i,n)}function G(t,e,r,n,i,o){var a;a="getList"===e?_.bind(R,this,r):_.bind(I,this,e,r),this[t]=function(t,e,r){var s=_.defaults({params:t,headers:e,elem:r},{params:n,headers:i,elem:o});return a(s.params,s.headers,s.elem)}}var O=new d[i],P={};return P.one=_.bind(c,P,null),P.all=_.bind(l,P,null),P}]}); \ No newline at end of file +var module=angular.module("restangular",["ngResource"]);module.provider("Restangular",function(){function t(t){return _.contains(e,t)}var e=["get","head","options","trace"],r="";this.setBaseUrl=function(t){r=t};var n=[];this.setExtraFields=function(t){n=t};var i="path";this.setUrlCreator=function(t){if(!_.has(d,t))throw Error("URL Path selected isn't valid");i=t};var o={id:"id",route:"route",parentResource:"parentResource",restangularCollection:"restangularCollection",what:"restangularWhat"};this.setRestangularFields=function(t){o=_.extend(o,t)};var a=function(t){return t};this.setResponseExtractor=function(t){a=t},this.setResponseInterceptor=this.setResponseExtractor;var s=function(t){return t};this.setOnElemRestangularized=function(t){s=t};var u=!0;this.setListTypeIsArray=function(t){u=t};var c=null;this.setRequestSuffix=function(t){c=t};var d={},h=function(){};h.prototype.parentsArray=function(t){for(var e=[];!_.isUndefined(t);)e.push(t),t=t[o.parentResource];return e.reverse()},h.prototype.resource=function(t,e,r){var n={};return e(this.base(t)+"/:"+o.what+(c||""),{},{getList:{method:"GET",params:n,isArray:u,headers:r||{}},get:{method:"GET",params:n,isArray:!1,headers:r||{}},put:{method:"PUT",params:n,isArray:!1,headers:r||{}},post:{method:"POST",params:n,isArray:!1,headers:r||{}},remove:{method:"DELETE",params:n,isArray:!1,headers:r||{}},head:{method:"HEAD",params:n,isArray:!1,headers:r||{}},trace:{method:"TRACE",params:n,isArray:!1,headers:r||{}},options:{method:"OPTIONS",params:n,isArray:!1,headers:r||{}},patch:{method:"PATCH",params:n,isArray:!1,headers:r||{}}})};var l=function(){};l.prototype=new h,l.prototype.base=function(t){return r+_.reduce(this.parentsArray(t),function(t,e){var r=t+"/"+e[o.route];return e[o.restangularCollection]||(r+="/"+e[o.id]),r},"")},l.prototype.fetchUrl=function(t,e){var r=this.base(t);return e[o.what]&&(r+="/"+e[o.what]),r},d.path=l,this.$get=["$resource","$q",function(e,r){function u(t,e,r){if(e[o.route]=r,e.addRestangularMethod=_.bind(G,e),t){var i=_.union(_.values(_.pick(o,["id","route","parentResource"])),n);e[o.parentResource]=_.pick(t,i)}return e}function c(t,e,r){var n={};return n[o.id]=r,b(t,n,e)}function h(t,e){return g(t,{},e,!0)}function l(t,e){return t.call=_.bind(p,t),t.get=_.bind(f,t),t[o.restangularCollection]=e,e&&(t.push=_.bind(p,t,"push")),t}function p(t){var e=r.defer(),n=arguments;return this.then(function(r){var i=Array.prototype.slice.call(n,1),o=r[t];o.apply(r,i),e.resolve(r)}),l(e.promise,this[o.restangularCollection])}function f(t){var e=r.defer();return this.then(function(r){e.resolve(r[t])}),l(e.promise,this[o.restangularCollection])}function v(t){return _.omit(t,_.values(_.omit(o,"id")))}function m(t){t.customOperation=_.bind(S,t),_.each(["put","post","get","delete"],function(e){_.each(["do","custom"],function(r){var n=r+e.toUpperCase();t[n]=_.bind(S,t,e)})}),t.customGETLIST=_.bind(R,t),t.doGETLIST=t.customGETLIST}function b(t,e,r){var n=u(t,e,r);return n[o.restangularCollection]=!1,n.get=_.bind(C,n),n.getList=_.bind(R,n),n.put=_.bind(T,n),n.post=_.bind(L,n),n.remove=_.bind(E,n),n.head=_.bind(w,n),n.trace=_.bind(x,n),n.options=_.bind(U,n),n.patch=_.bind(I,n),n.one=_.bind(c,n,n),n.all=_.bind(h,n,n),m(n),s(n,!1,r)}function g(t,e,r){var n=u(t,e,r);return n[o.restangularCollection]=!0,n.post=_.bind(L,n,null),n.head=_.bind(w,n),n.trace=_.bind(x,n),n.options=_.bind(U,n),n.patch=_.bind(I,n),n.getList=_.bind(R,n,null),m(n),s(n,!0,r)}function y(t){var e={};return t&&(e[o.what]=t),e}function R(t,n,i){var s=y(t),u=this,c=r.defer();return O.resource(this,e,i).getList(_.extend(s,n),function(e){var r=a(e,"getList",t,O.fetchUrl(u,s)),n=_.map(r,function(e){return u[o.restangularCollection]?b(null,e,u[o.route]):b(u,e,t)});n=_.extend(r,n),u[o.restangularCollection]?c.resolve(g(null,n,u[o.route])):c.resolve(g(u,n,t))},function(t){c.reject(t)}),l(c.promise,!0)}function A(n,i,s,u){var c=this,d=r.defer(),h=i||{},p=s||this,f=function(t){var e=a(t,n,h[o.what]||c[o.route],O.fetchUrl(c,h))||p;"post"!==n||c[o.restangularCollection]?d.resolve(b(c[o.parentResource],e,c[o.route])):d.resolve(b(c,e,h[o.what]))},_=function(t){d.reject(t)};return t(n)?O.resource(this,e,u)[n](h,f,_):O.resource(this,e,u)[n](h,s||v(this),f,_),l(d.promise)}function C(t,e){return _.bind(A,this)("get",t,void 0,e)}function E(t,e){return _.bind(A,this)("remove",t,{},e)}function T(t,e){return _.bind(A,this)("put",t,void 0,e)}function L(t,e,r,n){return _.bind(A,this)("post",_.extend(y(t),r),e,n)}function w(t,e){return _.bind(A,this)("head",t,void 0,e)}function x(t,e){return _.bind(A,this)("trace",t,void 0,e)}function U(t,e){return _.bind(A,this)("options",t,void 0,e)}function I(t,e){return _.bind(A,this)("patch",t,void 0,e)}function S(t,e,r,n,i){return _.bind(A,this)(t,_.extend(y(e),r),i,n)}function G(t,e,r,n,i,o){var a;a="getList"===e?_.bind(R,this,r):_.bind(S,this,e,r),this[t]=function(t,e,r){var s=_.defaults({params:t,headers:e,elem:r},{params:n,headers:i,elem:o});return a(s.params,s.headers,s.elem)}}var O=new d[i],P={};return P.one=_.bind(c,P,null),P.all=_.bind(h,P,null),P}]}); \ No newline at end of file diff --git a/dist/restangular.zip b/dist/restangular.zip index 397aa9e9beec216628a0cc56c50fddc527148bbe..953ba54bceb97b7aab5af278c3ef8f53568a065c 100644 GIT binary patch delta 471 zcmZ3!lkw^fMxFp~W)?065NKFDkw=lYVew+8CE8IJHQX2&G&WlG2v2@19LA?nT$+}a zS)ou26%M~(oawaGHEn&== z%;BHHn6o+8U!DC61EsWrj3+-0bOEzE8G|Qp3912-hQU8X%XRWJ zb@KE|iV~AkZR7QlGV@Y2Dkj^7Xfk?E&InNjn$#E4h)>mKztCfhK!ZiYt$>OH!nJ{9 zO}G+}oFAS8BzYpd*)w#~bmBFwCfi3y2xsUN*VL40lw@QUYl4M!ayEBHFf&d*8Ywq< zRiyOf9w7ZVGJ?@_Qk3lE$S4`^V2u);RGlK7Je|zR6C))i&xncxI{tgqMWE>?qotV| n7EgW_ZHO8NlT~6&7Nep&PAwgtdxG)6z046zmnM zi&BeA67$kaa}tY!!Gcx_5Xo8vD~0M>>&cChB9re5+e;}~VJKBn&;csZnXITPyxCdA z*$8Y=yVmz@zeE@qer=xYR?af{y|2_{74JO8oXL~DwIq`5u~?W~Yc+YVx2gy>8#cf6 zW@DPn6H{ECa2oQ>m_C8rD&8-eiN+87(7`lL=|X~ zO-Lg?Rh$2W9Ag9;emKkusQ6!)HjvZ`R|1m0;W8=|(i0;ifcCG8l%32TCByBhQKFNoQ>2rp zlQ}ssLSnL8R2&+XzB#i#@1?D2Y53wi7>z-dh(QLL)4g_d@0&Q b9u)WRC;>)`I5=Ivh?SF7W3