Skip to content

Commit 3898270

Browse files
committed
Merge pull request #668 from PascalPrecht/ngdocs
ngdocs API documentation
2 parents 20fcbf8 + 558d0df commit 3898270

File tree

6 files changed

+383
-10
lines changed

6 files changed

+383
-10
lines changed

Gruntfile.js

+12
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ module.exports = function (grunt) {
9393
options: {
9494
dest: 'CHANGELOG.md'
9595
}
96+
},
97+
ngdocs: {
98+
options: {
99+
dest: 'site',
100+
html5Mode: false,
101+
title: 'UI Router',
102+
startPage: '/api',
103+
},
104+
api: {
105+
src: ['src/**/*.js'],
106+
title: 'API Reference'
107+
}
96108
}
97109
});
98110

package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
"web": "https://github.com/ksperling"
1919
}
2020
],
21-
"maintainers": [{
22-
"name": "AngularUI",
23-
"web": "https://github.com/angular-ui?tab=members"
24-
}],
21+
"maintainers": [
22+
{
23+
"name": "AngularUI",
24+
"web": "https://github.com/angular-ui?tab=members"
25+
}
26+
],
2527
"repository": {
2628
"type": "git",
2729
"url": "https://github.com/angular-ui/ui-router.git"
@@ -58,6 +60,7 @@
5860
"karma": "~0.10.4",
5961
"karma-phantomjs-launcher": "~0.1.0",
6062
"load-grunt-tasks": "~0.2.0",
61-
"grunt-conventional-changelog": "~1.0.0"
63+
"grunt-conventional-changelog": "~1.0.0",
64+
"grunt-ngdocs": "~0.1.7"
6265
}
6366
}

src/common.js

+47-1
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,55 @@ function filterByKeys(keys, values) {
164164
return filtered;
165165
}
166166

167+
/**
168+
* @ngdoc overview
169+
* @name ui.router.util
170+
*
171+
* @description
172+
*
173+
*/
167174
angular.module('ui.router.util', ['ng']);
175+
176+
/**
177+
* @ngdoc overview
178+
* @name ui.router.router
179+
*
180+
* @requires ui.router.util
181+
*
182+
* @description
183+
*
184+
*/
168185
angular.module('ui.router.router', ['ui.router.util']);
186+
187+
/**
188+
* @ngdoc overview
189+
* @name ui.router.router
190+
*
191+
* @requires ui.router.router
192+
* @requires ui.router.util
193+
*
194+
* @description
195+
*
196+
*/
169197
angular.module('ui.router.state', ['ui.router.router', 'ui.router.util']);
198+
199+
/**
200+
* @ngdoc overview
201+
* @name ui.router
202+
*
203+
* @requires ui.router.state
204+
*
205+
* @description
206+
*
207+
*/
170208
angular.module('ui.router', ['ui.router.state']);
209+
/**
210+
* @ngdoc overview
211+
* @name ui.router.compat
212+
*
213+
* @requires ui.router
214+
*
215+
* @description
216+
*
217+
*/
171218
angular.module('ui.router.compat', ['ui.router']);
172-

src/compat.js

+62
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/**
2+
* @ngdoc object
3+
* @name ui.router.compat.$routeProvider
4+
*
5+
* @requires ui.router.state.$stateProvider
6+
* @requires ui.router.router.$urlRouterProvider
7+
*
8+
* @description
9+
* `$routeProvider` of the `ui.router.compat` module overwrites the existing
10+
* `routeProvider` from the core. This is done to provide compatibility between
11+
* the UI Router and the core router.
12+
*
13+
* It also provides a `when()` method to register routes that map to certain urls.
14+
* Behind the scenes it actually delegates either to
15+
* {@link ui.router.router.$urlRouterProvider $urlRouterProvider} or to the
16+
* {@link ui.router.state.$stateProvider $stateProvider} to postprocess the given
17+
* router definition object.
18+
*/
119
$RouteProvider.$inject = ['$stateProvider', '$urlRouterProvider'];
220
function $RouteProvider( $stateProvider, $urlRouterProvider) {
321

@@ -17,6 +35,32 @@ function $RouteProvider( $stateProvider, $urlRouterProvider) {
1735
}
1836

1937
this.when = when;
38+
/**
39+
* @ngdoc function
40+
* @name ui.router.compat.$routeProvider#when
41+
* @methodOf ui.router.compat.$routeProvider
42+
*
43+
* @description
44+
* Registers a route with a given route definition object. The route definition
45+
* object has the same interface the angular core route definition object has.
46+
*
47+
* @example
48+
* <pre>
49+
* var app = angular.module('app', ['ui.router.compat']);
50+
*
51+
* app.config(function ($routeProvider) {
52+
* $routeProvider.when('home', {
53+
* controller: function () { ... },
54+
* templateUrl: 'path/to/template'
55+
* });
56+
* });
57+
* </pre>
58+
*
59+
* @param {string} url URL as string
60+
* @param {object} route Route definition object
61+
*
62+
* @return {object} $routeProvider - $routeProvider instance
63+
*/
2064
function when(url, route) {
2165
/*jshint validthis: true */
2266
if (route.redirectTo != null) {
@@ -47,6 +91,24 @@ function $RouteProvider( $stateProvider, $urlRouterProvider) {
4791
return this;
4892
}
4993

94+
/**
95+
* @ngdoc object
96+
* @name ui.router.compat.$route
97+
*
98+
* @requires ui.router.state.$state
99+
* @requires $rootScope
100+
* @requires $routeParams
101+
*
102+
* @property {object} routes - Array of registered routes.
103+
* @property {object} params - Current route params as object.
104+
* @property {string} current - Name of the current route.
105+
*
106+
* @description
107+
* The `$route` service provides interfaces to access defined routes. It also let's
108+
* you access route params through `$routeParams` service, so you have fully
109+
* control over all the stuff you would actually get from angular's core `$route`
110+
* service.
111+
*/
50112
this.$get = $get;
51113
$get.$inject = ['$state', '$rootScope', '$routeParams'];
52114
function $get( $state, $rootScope, $routeParams) {

src/state.js

+112-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* @ngdoc object
3+
* @name ui.router.state.$stateProvider
4+
*
5+
* @requires ui.router.router.$urlRouterProvider
6+
* @requires ui.router.util.$urlMatcherFactoryProvider
7+
* @requires $locationProvider
8+
*
9+
* @description
10+
* The new `$stateProvider` works similar to Angular's v1 router, but it focuses purely
11+
* on state.
12+
*
13+
* A state corresponds to a "place" in the application in terms of the overall UI and
14+
* navigation. A state describes (via the controller / template / view properties) what
15+
* the UI looks like and does at that place.
16+
*
17+
* States often have things in common, and the primary way of factoring out these
18+
* commonalities in this model is via the state hierarchy, i.e. parent/child states aka
19+
* nested states.
20+
*
21+
* The `$stateProvider` provides interfaces to declare these states for your app.
22+
*/
123
$StateProvider.$inject = ['$urlRouterProvider', '$urlMatcherFactoryProvider', '$locationProvider'];
224
function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $locationProvider) {
325

@@ -207,9 +229,96 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
207229
root.navigable = null;
208230

209231

210-
// .decorator()
211-
// .decorator(name)
212-
// .decorator(name, function)
232+
/**
233+
* @ngdoc function
234+
* @name ui.router.state.$stateProvider#decorator
235+
* @methodOf ui.router.state.$stateProvider
236+
*
237+
* @description
238+
* Allows you to extend (carefully) or override (at your own peril) the
239+
* `stateBuilder` object used internally by `$stateProvider`. This can be used
240+
* to add custom functionality to ui-router, for example inferring templateUrl
241+
* based on the state name.
242+
*
243+
* When passing only a name, it returns the current (original or decorated) builder
244+
* function that matches `name`.
245+
*
246+
* The builder functions that can be decorated are listed below. Though not all
247+
* necessarily have a good use case for decoration, that is up to you to decide.
248+
*
249+
* In addition, users can attach custom decorators, which will generate new
250+
* properties within the state's internal definition. There is currently no clear
251+
* use-case for this beyond accessing internal states (i.e. $state.$current),
252+
* however, expect this to become increasingly relevant as we introduce additional
253+
* meta-programming features.
254+
*
255+
* **Warning**: Decorators should not be interdependent because the order of
256+
* execution of the builder functions in nondeterministic. Builder functions
257+
* should only be dependent on the state definition object and super function.
258+
*
259+
*
260+
* Existing builder functions and current return values:
261+
*
262+
* - parent - `{object}` - returns the parent state object.
263+
* - data - `{object}` - returns state data, including any inherited data that is not
264+
* overridden by own values (if any).
265+
* - url - `{object}` - returns a UrlMatcher or null.
266+
* - navigable - returns closest ancestor state that has a URL (aka is
267+
* navigable).
268+
* - params - `{object}` - returns an array of state params that are ensured to
269+
* be a super-set of parent's params.
270+
* - views - `{object}` - returns a views object where each key is an absolute view
271+
* name (i.e. "viewName@stateName") and each value is the config object
272+
* (template, controller) for the view. Even when you don't use the views object
273+
* explicitly on a state config, one is still created for you internally.
274+
* So by decorating this builder function you have access to decorating template
275+
* and controller properties.
276+
* - ownParams - `{object}` - returns an array of params that belong to the state,
277+
* not including any params defined by ancestor states.
278+
* - path - `{string}` - returns the full path from the root down to this state.
279+
* Needed for state activation.
280+
* - includes - `{object}` - returns an object that includes every state that
281+
* would pass a '$state.includes()' test.
282+
*
283+
* @example
284+
* <pre>
285+
* // Override the internal 'views' builder with a function that takes the state
286+
* // definition, and a reference to the internal function being overridden:
287+
* $stateProvider.decorator('views', function ($state, parent) {
288+
* var result = {},
289+
* views = parent(state);
290+
*
291+
* angular.forEach(view, function (config, name) {
292+
* var autoName = (state.name + '.' + name).replace('.', '/');
293+
* config.templateUrl = config.templateUrl || '/partials/' + autoName + '.html';
294+
* result[name] = config;
295+
* });
296+
* return result;
297+
* });
298+
*
299+
* $stateProvider.state('home', {
300+
* views: {
301+
* 'contact.list': { controller: 'ListController' },
302+
* 'contact.item': { controller: 'ItemController' }
303+
* }
304+
* });
305+
*
306+
* // ...
307+
*
308+
* $state.go('home');
309+
* // Auto-populates list and item views with /partials/home/contact/list.html,
310+
* // and /partials/home/contact/item.html, respectively.
311+
* </pre>
312+
*
313+
* @param {string} name The name of the builder function to decorate.
314+
* @param {object} func A function that is responsible for decorating the original
315+
* builder function. The function receives two parameters:
316+
*
317+
* - `{object}` - state - The state config object.
318+
* - `{object}` - super - The original builder function.
319+
*
320+
* @return {object} $stateProvider - $stateProvider instance
321+
*/
213322
this.decorator = decorator;
214323
function decorator(name, func) {
215324
/*jshint validthis: true */

0 commit comments

Comments
 (0)