Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Added URL Suffixes to Resources #1211

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
AngularJS
=========

AngularJS lets you write client-side web applications as if you had a smarter browser. It lets use
good old HTML (or HAML, Jade and friends!) as your template language and lets you extend HTML’s
syntax to express your application’s components clearly and succinctly. It automatically
synchronizes data from your UI (view) with your JavaScript objects (model) through 2-way data
binding. To help you structure your application better and make it easy to test AngularJS teaches
the browser how to do dependency injection and inversion of control. Oh yeah and it also helps with
server-side communication, taming async callbacks with promises and deferreds; and make client-side
navigation and deeplinking with hashbang urls or HTML5 pushState a piece of cake. The best of all:
it makes development fun!
This repo is a fork of AngularJS which adds support for parameter suffixes for resources.

* Web site: http://angularjs.org
* Tutorial: http://docs.angularjs.org/tutorial
* API Docs: http://docs.angularjs.org
* Developer Guide: http://docs.angularjs.org/guide

Compiling
---------
rake compile

Running Tests
-------------
./server.sh # start the server
open http://localhost:9876/capture # capture browser
./test.sh # run all unit tests
This way you can create resources which have a URL which relates to /resources/:id.json

## Usage
```
angular.module('App',['ngResource']).factory('Model',['$resource',function($resource) {

return $resource('/path/to/resource',{
_suffx : '.json'
},{
//actions
}
);
}]);
9 changes: 9 additions & 0 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,15 @@ angular.module('ngResource', ['ng']).
url: function(params) {
var self = this,
url = this.template,
suffix,
encodedVal;

params = params || {};
if(params['_suffix']) {
suffix = params['_suffix'];
delete params['_suffix'];
}

forEach(this.urlParams, function(_, urlParam){
encodedVal = encodeUriSegment(params[urlParam] || self.defaults[urlParam] || "");
url = url.replace(new RegExp(":" + urlParam + "(\\W)"), encodedVal + "$1");
Expand All @@ -295,6 +301,9 @@ angular.module('ngResource', ['ng']).
});
query.sort();
url = url.replace(/\/*$/, '');
if(suffix) {
url += suffix;
}
return url + (query.length ? '?' + query.join('&') : '');
}
};
Expand Down