Skip to content

ngdocs API documentation #668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 11, 2013
Merged
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
12 changes: 12 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ module.exports = function (grunt) {
options: {
dest: 'CHANGELOG.md'
}
},
ngdocs: {
options: {
dest: 'site',
html5Mode: false,
title: 'UI Router',
startPage: '/api',
},
api: {
src: ['src/**/*.js'],
title: 'API Reference'
}
}
});

Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
"web": "https://github.com/ksperling"
}
],
"maintainers": [{
"name": "AngularUI",
"web": "https://github.com/angular-ui?tab=members"
}],
"maintainers": [
{
"name": "AngularUI",
"web": "https://github.com/angular-ui?tab=members"
}
],
"repository": {
"type": "git",
"url": "https://github.com/angular-ui/ui-router.git"
Expand Down Expand Up @@ -58,6 +60,7 @@
"karma": "~0.10.4",
"karma-phantomjs-launcher": "~0.1.0",
"load-grunt-tasks": "~0.2.0",
"grunt-conventional-changelog": "~1.0.0"
"grunt-conventional-changelog": "~1.0.0",
"grunt-ngdocs": "~0.1.7"
}
}
48 changes: 47 additions & 1 deletion src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,55 @@ function filterByKeys(keys, values) {
return filtered;
}

/**
* @ngdoc overview
* @name ui.router.util
*
* @description
*
*/
angular.module('ui.router.util', ['ng']);

/**
* @ngdoc overview
* @name ui.router.router
*
* @requires ui.router.util
*
* @description
*
*/
angular.module('ui.router.router', ['ui.router.util']);

/**
* @ngdoc overview
* @name ui.router.router
*
* @requires ui.router.router
* @requires ui.router.util
*
* @description
*
*/
angular.module('ui.router.state', ['ui.router.router', 'ui.router.util']);

/**
* @ngdoc overview
* @name ui.router
*
* @requires ui.router.state
*
* @description
*
*/
angular.module('ui.router', ['ui.router.state']);
/**
* @ngdoc overview
* @name ui.router.compat
*
* @requires ui.router
*
* @description
*
*/
angular.module('ui.router.compat', ['ui.router']);

62 changes: 62 additions & 0 deletions src/compat.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/**
* @ngdoc object
* @name ui.router.compat.$routeProvider
*
* @requires ui.router.state.$stateProvider
* @requires ui.router.router.$urlRouterProvider
*
* @description
* `$routeProvider` of the `ui.router.compat` module overwrites the existing
* `routeProvider` from the core. This is done to provide compatibility between
* the UI Router and the core router.
*
* It also provides a `when()` method to register routes that map to certain urls.
* Behind the scenes it actually delegates either to
* {@link ui.router.router.$urlRouterProvider $urlRouterProvider} or to the
* {@link ui.router.state.$stateProvider $stateProvider} to postprocess the given
* router definition object.
*/
$RouteProvider.$inject = ['$stateProvider', '$urlRouterProvider'];
function $RouteProvider( $stateProvider, $urlRouterProvider) {

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

this.when = when;
/**
* @ngdoc function
* @name ui.router.compat.$routeProvider#when
* @methodOf ui.router.compat.$routeProvider
*
* @description
* Registers a route with a given route definition object. The route definition
* object has the same interface the angular core route definition object has.
*
* @example
* <pre>
* var app = angular.module('app', ['ui.router.compat']);
*
* app.config(function ($routeProvider) {
* $routeProvider.when('home', {
* controller: function () { ... },
* templateUrl: 'path/to/template'
* });
* });
* </pre>
*
* @param {string} url URL as string
* @param {object} route Route definition object
*
* @return {object} $routeProvider - $routeProvider instance
*/
function when(url, route) {
/*jshint validthis: true */
if (route.redirectTo != null) {
Expand Down Expand Up @@ -47,6 +91,24 @@ function $RouteProvider( $stateProvider, $urlRouterProvider) {
return this;
}

/**
* @ngdoc object
* @name ui.router.compat.$route
*
* @requires ui.router.state.$state
* @requires $rootScope
* @requires $routeParams
*
* @property {object} routes - Array of registered routes.
* @property {object} params - Current route params as object.
* @property {string} current - Name of the current route.
*
* @description
* The `$route` service provides interfaces to access defined routes. It also let's
* you access route params through `$routeParams` service, so you have fully
* control over all the stuff you would actually get from angular's core `$route`
* service.
*/
this.$get = $get;
$get.$inject = ['$state', '$rootScope', '$routeParams'];
function $get( $state, $rootScope, $routeParams) {
Expand Down
115 changes: 112 additions & 3 deletions src/state.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/**
* @ngdoc object
* @name ui.router.state.$stateProvider
*
* @requires ui.router.router.$urlRouterProvider
* @requires ui.router.util.$urlMatcherFactoryProvider
* @requires $locationProvider
*
* @description
* The new `$stateProvider` works similar to Angular's v1 router, but it focuses purely
* on state.
*
* A state corresponds to a "place" in the application in terms of the overall UI and
* navigation. A state describes (via the controller / template / view properties) what
* the UI looks like and does at that place.
*
* States often have things in common, and the primary way of factoring out these
* commonalities in this model is via the state hierarchy, i.e. parent/child states aka
* nested states.
*
* The `$stateProvider` provides interfaces to declare these states for your app.
*/
$StateProvider.$inject = ['$urlRouterProvider', '$urlMatcherFactoryProvider', '$locationProvider'];
function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $locationProvider) {

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


// .decorator()
// .decorator(name)
// .decorator(name, function)
/**
* @ngdoc function
* @name ui.router.state.$stateProvider#decorator
* @methodOf ui.router.state.$stateProvider
*
* @description
* Allows you to extend (carefully) or override (at your own peril) the
* `stateBuilder` object used internally by `$stateProvider`. This can be used
* to add custom functionality to ui-router, for example inferring templateUrl
* based on the state name.
*
* When passing only a name, it returns the current (original or decorated) builder
* function that matches `name`.
*
* The builder functions that can be decorated are listed below. Though not all
* necessarily have a good use case for decoration, that is up to you to decide.
*
* In addition, users can attach custom decorators, which will generate new
* properties within the state's internal definition. There is currently no clear
* use-case for this beyond accessing internal states (i.e. $state.$current),
* however, expect this to become increasingly relevant as we introduce additional
* meta-programming features.
*
* **Warning**: Decorators should not be interdependent because the order of
* execution of the builder functions in nondeterministic. Builder functions
* should only be dependent on the state definition object and super function.
*
*
* Existing builder functions and current return values:
*
* - parent - `{object}` - returns the parent state object.
* - data - `{object}` - returns state data, including any inherited data that is not
* overridden by own values (if any).
* - url - `{object}` - returns a UrlMatcher or null.
* - navigable - returns closest ancestor state that has a URL (aka is
* navigable).
* - params - `{object}` - returns an array of state params that are ensured to
* be a super-set of parent's params.
* - views - `{object}` - returns a views object where each key is an absolute view
* name (i.e. "viewName@stateName") and each value is the config object
* (template, controller) for the view. Even when you don't use the views object
* explicitly on a state config, one is still created for you internally.
* So by decorating this builder function you have access to decorating template
* and controller properties.
* - ownParams - `{object}` - returns an array of params that belong to the state,
* not including any params defined by ancestor states.
* - path - `{string}` - returns the full path from the root down to this state.
* Needed for state activation.
* - includes - `{object}` - returns an object that includes every state that
* would pass a '$state.includes()' test.
*
* @example
* <pre>
* // Override the internal 'views' builder with a function that takes the state
* // definition, and a reference to the internal function being overridden:
* $stateProvider.decorator('views', function ($state, parent) {
* var result = {},
* views = parent(state);
*
* angular.forEach(view, function (config, name) {
* var autoName = (state.name + '.' + name).replace('.', '/');
* config.templateUrl = config.templateUrl || '/partials/' + autoName + '.html';
* result[name] = config;
* });
* return result;
* });
*
* $stateProvider.state('home', {
* views: {
* 'contact.list': { controller: 'ListController' },
* 'contact.item': { controller: 'ItemController' }
* }
* });
*
* // ...
*
* $state.go('home');
* // Auto-populates list and item views with /partials/home/contact/list.html,
* // and /partials/home/contact/item.html, respectively.
* </pre>
*
* @param {string} name The name of the builder function to decorate.
* @param {object} func A function that is responsible for decorating the original
* builder function. The function receives two parameters:
*
* - `{object}` - state - The state config object.
* - `{object}` - super - The original builder function.
*
* @return {object} $stateProvider - $stateProvider instance
*/
this.decorator = decorator;
function decorator(name, func) {
/*jshint validthis: true */
Expand Down
Loading