aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMisko Hevery2012-03-26 21:18:01 -0700
committerMisko Hevery2012-03-28 11:16:36 -0700
commit8218c4b60b82927234cf545253266f288fa936c2 (patch)
treece26aa1e0f273a81c7f38c85aa9849a6675f6c59 /src
parent2430f52bb97fa9d682e5f028c977c5bf94c5ec38 (diff)
downloadangular.js-8218c4b60b82927234cf545253266f288fa936c2.tar.bz2
chore(Rakefile): get ready for modules
Diffstat (limited to 'src')
-rw-r--r--src/AngularPublic.js1
-rw-r--r--src/ng/http.js2
-rw-r--r--src/ng/httpBackend.js2
-rw-r--r--src/ngResource/resource.js (renamed from src/ng/resource.js)65
-rw-r--r--src/publishExternalApis.js3
5 files changed, 63 insertions, 10 deletions
diff --git a/src/AngularPublic.js b/src/AngularPublic.js
index 9a0e1977..ec307962 100644
--- a/src/AngularPublic.js
+++ b/src/AngularPublic.js
@@ -122,7 +122,6 @@ function publishExternalAPI(angular){
$location: $LocationProvider,
$log: $LogProvider,
$parse: $ParseProvider,
- $resource: $ResourceProvider,
$route: $RouteProvider,
$routeParams: $RouteParamsProvider,
$rootScope: $RootScopeProvider,
diff --git a/src/ng/http.js b/src/ng/http.js
index c2cbd161..e67dd496 100644
--- a/src/ng/http.js
+++ b/src/ng/http.js
@@ -152,7 +152,7 @@ function $HttpProvider() {
* For unit testing applications that use `$http` service, see
* {@link angular.module.ngMock.$httpBackend $httpBackend mock}.
*
- * For a higher level of abstraction, please check out the {@link angular.module.ng.$resource
+ * For a higher level of abstraction, please check out the {@link angular.module.ngResource.$resource
* $resource} service.
*
* The $http API is based on the {@link angular.module.ng.$q deferred/promise APIs} exposed by
diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js
index 201d1a87..abe1d8f5 100644
--- a/src/ng/httpBackend.js
+++ b/src/ng/httpBackend.js
@@ -18,7 +18,7 @@ var XHR = window.XMLHttpRequest || function() {
* XMLHttpRequest object or JSONP and deals with browser incompatibilities.
*
* You should never need to use this service directly, instead use the higher-level abstractions:
- * {@link angular.module.ng.$http $http} or {@link angular.module.ng.$resource $resource}.
+ * {@link angular.module.ng.$http $http} or {@link angular.module.ngResource.$resource $resource}.
*
* During testing this implementation is swapped with {@link angular.module.ngMock.$httpBackend mock
* $httpBackend} which can be trained with responses.
diff --git a/src/ng/resource.js b/src/ngResource/resource.js
index 3aa48e74..fe111b47 100644
--- a/src/ng/resource.js
+++ b/src/ngResource/resource.js
@@ -1,8 +1,14 @@
'use strict';
/**
+ * @ngdoc overview
+ * @name angular.module.ngResource
+ * @description
+ */
+
+ /**
* @ngdoc object
- * @name angular.module.ng.$resource
+ * @name angular.module.ngResource.$resource
* @requires $http
*
* @description
@@ -200,8 +206,8 @@
</doc:scenario>
</doc:example>
*/
-function $ResourceProvider() {
- this.$get = ['$http', function($http) {
+angular.module('ngResource', ['ng']).
+ factory('$resource', ['$http', '$parse', function($http, $parse) {
var DEFAULT_ACTIONS = {
'get': {method:'GET'},
'save': {method:'POST'},
@@ -209,9 +215,54 @@ function $ResourceProvider() {
'remove': {method:'DELETE'},
'delete': {method:'DELETE'}
};
+ var forEach = angular.forEach,
+ extend = angular.extend,
+ copy = angular.copy,
+ isFunction = angular.isFunction,
+ getter = function(obj, path) {
+ return $parse(path)(obj);
+ };
+
+ /**
+ * We need our custom mehtod because encodeURIComponent is too agressive and doesn't follow
+ * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
+ * segments:
+ * segment = *pchar
+ * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
+ * pct-encoded = "%" HEXDIG HEXDIG
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
+ * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
+ * / "*" / "+" / "," / ";" / "="
+ */
+ function encodeUriSegment(val) {
+ return encodeUriQuery(val, true).
+ replace(/%26/gi, '&').
+ replace(/%3D/gi, '=').
+ replace(/%2B/gi, '+');
+ }
+
+ /**
+ * This method is intended for encoding *key* or *value* parts of query component. We need a custom
+ * method becuase encodeURIComponent is too agressive and encodes stuff that doesn't have to be
+ * encoded per http://tools.ietf.org/html/rfc3986:
+ * query = *( pchar / "/" / "?" )
+ * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
+ * pct-encoded = "%" HEXDIG HEXDIG
+ * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
+ * / "*" / "+" / "," / ";" / "="
+ */
+ function encodeUriQuery(val, pctEncodeSpaces) {
+ return encodeURIComponent(val).
+ replace(/%40/gi, '@').
+ replace(/%3A/gi, ':').
+ replace(/%24/g, '$').
+ replace(/%2C/gi, ',').
+ replace((pctEncodeSpaces ? null : /%20/g), '+');
+ }
- function Route(template, defaults) {
+ function Route(template, defaults) {
this.template = template = template + '#';
this.defaults = defaults || {};
var urlParams = this.urlParams = {};
@@ -236,11 +287,12 @@ function $ResourceProvider() {
});
url = url.replace(/\/?#$/, '');
var query = [];
- forEachSorted(params, function(value, key){
+ forEach(params, function(value, key){
if (!self.urlParams[key]) {
query.push(encodeUriQuery(key) + '=' + encodeUriQuery(value));
}
});
+ query.sort();
url = url.replace(/\/*$/, '');
return url + (query.length ? '?' + query.join('&') : '');
}
@@ -364,5 +416,4 @@ function $ResourceProvider() {
}
return ResourceFactory;
- }];
-}
+ }]);
diff --git a/src/publishExternalApis.js b/src/publishExternalApis.js
new file mode 100644
index 00000000..6a6acd13
--- /dev/null
+++ b/src/publishExternalApis.js
@@ -0,0 +1,3 @@
+'use strict';
+
+publishExternalAPI(angular);