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

Commit 57c43dd

Browse files
committed
docs(module): improve the installation instructions for optional modules
Currently, the documentation does a bad job of explaining the distinction between the services that it provides, and the module itself. Furthermore, the instructions for using optional modules are inconsistent or missing. This commit addresses the problem by ading a new `{@installModule foo}` annotation to the docs generator that inlines the appropriate instructions based on the name of the module.
1 parent 99175f4 commit 57c43dd

File tree

14 files changed

+117
-73
lines changed

14 files changed

+117
-73
lines changed

docs/content/api/ng.ngdoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
@name ng
33
@description
44

5-
The `ng` is an angular module which contains all of the core angular services.
5+
`ng` is the name of the {@link guide/module angular module} that contains all of the core angular services.

docs/src/ngdoc.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ Doc.prototype = {
276276
replace(/{@type\s+(\S+)(?:\s+(\S+))?}/g, function(_, type, url) {
277277
url = url || '#';
278278
return '<a href="' + url + '" class="' + self.prepare_type_hint_class_name(type) + '">' + type + '</a>';
279+
}).
280+
replace(/{@installModule\s+(\S+)?}/g, function(_, module) {
281+
return explainModuleInstallation(module);
279282
});
280283
});
281284
text = parts.join('');
@@ -450,7 +453,6 @@ Doc.prototype = {
450453
dom.text(' Improve this doc');
451454
});
452455
dom.h(title(this), function() {
453-
454456
notice('deprecated', 'Deprecated API', self.deprecated);
455457
if (self.ngdoc === 'error') {
456458
minerrMsg = lookupMinerrMsg(self);
@@ -1169,3 +1171,28 @@ function dashCase(name){
11691171
return (pos ? '-' : '') + letter.toLowerCase();
11701172
});
11711173
}
1174+
//////////////////////////////////////////////////////////
1175+
1176+
function explainModuleInstallation(moduleName){
1177+
var ngMod = ngModule(moduleName),
1178+
modulePackage = 'angular-' + moduleName,
1179+
modulePackageFile = modulePackage + '.js';
1180+
1181+
return '<h1>Installation</h1>' +
1182+
'<p>First include <code>' + modulePackageFile +'</code> in your HTML:</p><pre><code>' +
1183+
' &lt;script src=&quot;angular.js&quot;&gt;\n' +
1184+
' &lt;script src=&quot;' + modulePackageFile + '&quot;&gt;</pre></code>' +
1185+
1186+
'<p>You can also find this file on the [Google CDN](https://developers.google.com/speed/libraries/devguide#angularjs), ' +
1187+
'<a href="http://bower.io/">Bower</a> (as <code>' + modulePackage + '</code>), ' +
1188+
'and on <a href="http://code.angularjs.org/">code.angularjs.org</a>.</p>' +
1189+
1190+
'<p>Then load the module in your application by adding it as a dependant module:</p><pre><code>' +
1191+
' angular.module(\'app\', [\'' + ngMod + '\']);</pre></code>' +
1192+
1193+
'<p>With that you\'re ready to get started!</p>';
1194+
}
1195+
1196+
function ngModule(moduleName) {
1197+
return 'ng' + moduleName[0].toUpperCase() + moduleName.substr(1);
1198+
}

src/ngAnimate/animate.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,15 @@
33
* @name ngAnimate
44
* @description
55
*
6-
* ngAnimate
7-
* =========
6+
* # ngAnimate
87
*
9-
* The ngAnimate module is an optional module that comes packed with AngularJS that can be included within an AngularJS
10-
* application to provide support for CSS and JavaScript animation hooks.
8+
* `ngAnimate` is an optional module that provides CSS and JavaScript animation hooks.
119
*
12-
* To make use of animations with AngularJS, the `angular-animate.js` JavaScript file must be included into your application
13-
* and the `ngAnimate` module must be included as a dependency.
10+
* {@installModule animate}
1411
*
15-
* <pre>
16-
* angular.module('App', ['ngAnimate']);
17-
* </pre>
12+
* # Usage
1813
*
19-
* Then, to see animations in action, all that is required is to define the appropriate CSS classes
14+
* To see animations in action, all that is required is to define the appropriate CSS classes
2015
* or to register a JavaScript animation via the $animation service. The directives that support animation automatically are:
2116
* `ngRepeat`, `ngInclude`, `ngSwitch`, `ngShow`, `ngHide` and `ngView`. Custom directives can take advantage of animation
2217
* by using the `$animate` service.
@@ -46,7 +41,7 @@
4641
* -o-transition:0.5s linear all;
4742
* transition:0.5s linear all;
4843
* }
49-
*
44+
*
5045
* .slide.ng-enter { } /&#42; starting animations for enter &#42;/
5146
* .slide.ng-enter-active { } /&#42; terminal animations for enter &#42;/
5247
* .slide.ng-leave { } /&#42; starting animations for leave &#42;/
@@ -190,11 +185,13 @@ angular.module('ngAnimate', ['ng'])
190185
* @name ngAnimate.$animateProvider
191186
* @description
192187
*
193-
* The $AnimationProvider provider allows developers to register and access custom JavaScript animations directly inside
188+
* The `$AnimationProvider` allows developers to register and access custom JavaScript animations directly inside
194189
* of a module. When an animation is triggered, the $animate service will query the $animation function to find any
195190
* animations that match the provided name value.
196191
*
197-
* Please visit the {@link ngAnimate ngAnimate} module overview page learn more about how to use animations in your application.
192+
* Requires the {@link ngAnimate `ngAnimate`} module to be installed.
193+
*
194+
* Please visit the {@link ngAnimate `ngAnimate`} module overview page learn more about how to use animations in your application.
198195
*
199196
*/
200197
.config(['$provide', '$animateProvider', function($provide, $animateProvider) {
@@ -206,7 +203,7 @@ angular.module('ngAnimate', ['ng'])
206203
var rootAnimateState = {running:true};
207204
$provide.decorator('$animate', ['$delegate', '$injector', '$sniffer', '$rootElement', '$timeout',
208205
function($delegate, $injector, $sniffer, $rootElement, $timeout) {
209-
206+
210207
$rootElement.data(NG_ANIMATE_STATE, rootAnimateState);
211208

212209
function lookup(name) {
@@ -248,7 +245,9 @@ angular.module('ngAnimate', ['ng'])
248245
* The `$animate` service is used behind the scenes with pre-existing directives and animation with these directives
249246
* will work out of the box without any extra configuration.
250247
*
251-
* Please visit the {@link ngAnimate ngAnimate} module overview page learn more about how to use animations in your application.
248+
* Requires the {@link ngAnimate `ngAnimate`} module to be installed.
249+
*
250+
* Please visit the {@link ngAnimate `ngAnimate`} module overview page learn more about how to use animations in your application.
252251
*
253252
*/
254253
return {

src/ngCookies/cookies.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
/**
44
* @ngdoc overview
55
* @name ngCookies
6+
* @description
7+
*
8+
* # ngCookies
9+
*
10+
* Provides the {@link ngCookies.$cookies `$cookies`} and
11+
* {@link ngCookies.$cookieStore `$cookieStore`} services.
12+
*
13+
* {@installModule cookies}
14+
*
15+
* See {@link ngCookies.$cookies `$cookies`} and
16+
* {@link ngCookies.$cookieStore `$cookieStore`} for usage.
617
*/
718

819

@@ -18,16 +29,7 @@ angular.module('ngCookies', ['ng']).
1829
* Only a simple Object is exposed and by adding or removing properties to/from
1930
* this object, new cookies are created/deleted at the end of current $eval.
2031
*
21-
* # Installation
22-
* To use $cookies make sure you have included the `angular-cookies.js` that comes in Angular
23-
* package. You can also find this file on Google CDN, bower as well as at
24-
* {@link http://code.angularjs.org/ code.angularjs.org}.
25-
*
26-
* Finally load the module in your application:
27-
*
28-
* angular.module('app', ['ngCookies']);
29-
*
30-
* and you are ready to get started!
32+
* Requires the {@link ngCookies `ngCookies`} module to be installed.
3133
*
3234
* @example
3335
<doc:example>
@@ -133,6 +135,9 @@ angular.module('ngCookies', ['ng']).
133135
* Provides a key-value (string-object) storage, that is backed by session cookies.
134136
* Objects put or retrieved from this storage are automatically serialized or
135137
* deserialized by angular's toJson/fromJson.
138+
*
139+
* Requires the {@link ngCookies `ngCookies`} module to be installed.
140+
*
136141
* @example
137142
*/
138143
factory('$cookieStore', ['$cookies', function($cookies) {

src/ngResource/resource.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ var $resourceMinErr = angular.$$minErr('$resource');
66
* @ngdoc overview
77
* @name ngResource
88
* @description
9+
*
10+
* # ngResource
11+
*
12+
* `ngResource` is the name of the optional Angular module that adds support for interacting with
13+
* [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources.
14+
* `ngReource` provides the {@link ngResource.$resource `$resource`} serivce.
15+
*
16+
* {@installModule resource}
17+
*
18+
* See {@link ngResource.$resource `$resource`} for usage.
919
*/
1020

1121
/**
@@ -20,16 +30,7 @@ var $resourceMinErr = angular.$$minErr('$resource');
2030
* The returned resource object has action methods which provide high-level behaviors without
2131
* the need to interact with the low level {@link ng.$http $http} service.
2232
*
23-
* # Installation
24-
* To use $resource make sure you have included the `angular-resource.js` that comes in Angular
25-
* package. You can also find this file on Google CDN, bower as well as at
26-
* {@link http://code.angularjs.org/ code.angularjs.org}.
27-
*
28-
* Finally load the module in your application:
29-
*
30-
* angular.module('app', ['ngResource']);
31-
*
32-
* and you are ready to get started!
33+
* Requires the {@link ngResource `ngResource`} module to be installed.
3334
*
3435
* @param {string} url A parametrized URL template with parameters prefixed by `:` as in
3536
* `/user/:username`. If you are using a URL with a port number (e.g.

src/ngRoute/directive/ngView.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ ngRouteModule.directive('ngView', ngViewFactory);
1414
* Every time the current route changes, the included view changes with it according to the
1515
* configuration of the `$route` service.
1616
*
17+
* Requires the {@link ngRoute `ngRoute`} module to be installed.
18+
*
1719
* @animations
1820
* enter - animation is used to bring new content into the browser.
1921
* leave - animation is used to animate existing content away.

src/ngRoute/route.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@
55
* @name ngRoute
66
* @description
77
*
8-
* ngRoute
9-
* =========
8+
* # ngRoute
109
*
11-
* The ngRoute module provides routing and deeplinking services and directives for angular apps.
10+
* The `ngRoute` module provides routing and deeplinking services and directives for angular apps.
1211
*
13-
* To make use of routing with AngularJS, the `angular-route.js` JavaScript file must be included into your application
14-
* and the `ngRoute` module must be included as a dependency.
15-
*
16-
* <pre>
17-
* angular.module('App', ['ngRoute']);
18-
* </pre>
12+
* {@installModule route}
1913
*
2014
*/
2115

@@ -30,6 +24,8 @@ var ngRouteModule = angular.module('ngRoute', ['ng']).
3024
* @description
3125
*
3226
* Used for configuring routes. See {@link ngRoute.$route $route} for an example.
27+
*
28+
* Requires the {@link ngRoute `ngRoute`} module to be installed.
3329
*/
3430
function $RouteProvider(){
3531
var routes = {};
@@ -231,13 +227,15 @@ function $RouteProvider(){
231227
* @property {Array.<Object>} routes Array of all configured routes.
232228
*
233229
* @description
234-
* Is used for deep-linking URLs to controllers and views (HTML partials).
230+
* `$route` is used for deep-linking URLs to controllers and views (HTML partials).
235231
* It watches `$location.url()` and tries to map the path to an existing route definition.
236232
*
233+
* Requires the {@link ngRoute `ngRoute`} module to be installed.
234+
*
237235
* You can define routes through {@link ngRoute.$routeProvider $routeProvider}'s API.
238236
*
239-
* The `$route` service is typically used in conjunction with {@link ngRoute.directive:ngView ngView}
240-
* directive and the {@link ngRoute.$routeParams $routeParams} service.
237+
* The `$route` service is typically used in conjunction with the {@link ngRoute.directive:ngView `ngView`}
238+
* directive and the {@link ngRoute.$routeParams `$routeParams`} service.
241239
*
242240
* @example
243241
This example shows how changing the URL hash causes the `$route` to match a route against the

src/ngRoute/routeParams.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ ngRouteModule.provider('$routeParams', $RouteParamsProvider);
99
* @requires $route
1010
*
1111
* @description
12-
* Current set of route parameters. The route parameters are a combination of the
13-
* {@link ng.$location $location} `search()`, and `path()`. The `path` parameters
14-
* are extracted when the {@link ngRoute.$route $route} path is matched.
12+
* The `$routeParams` service allows you to retrieve the current set of route parameters.
13+
*
14+
* Requires the {@link ngRoute `ngRoute`} module to be installed.
15+
*
16+
* The route parameters are a combination of {@link ng.$location `$location`}'s
17+
* {@link ng.$location#search `search()`} and {@link ng.$location#path `path()`}.
18+
* The `path` parameters are extracted when the {@link ngRoute.$route `$route`} path is matched.
1519
*
1620
* In case of parameter name collision, `path` params take precedence over `search` params.
1721
*

src/ngSanitize/filter/linky.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
* @function
55
*
66
* @description
7-
* Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and
8-
* plain email address links.
7+
* Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and
8+
* plain email address links.
9+
*
10+
* Requires the {@link ngSanitize `ngSanitize`} module to be installed.
911
*
1012
* @param {string} text Input text.
1113
* @param {string} target Window (_blank|_self|_parent|_top) or named frame to open links in.

src/ngSanitize/sanitize.js

+5-16
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,14 @@ var $sanitizeMinErr = angular.$$minErr('$sanitize');
66
* @ngdoc overview
77
* @name ngSanitize
88
* @description
9-
*
10-
* The `ngSanitize` module provides functionality to sanitize HTML.
11-
*
12-
* # Installation
13-
* As a separate module, it must be loaded after Angular core is loaded; otherwise, an 'Uncaught Error:
14-
* No module: ngSanitize' runtime error will occur.
159
*
16-
* <pre>
17-
* <script src="angular.js"></script>
18-
* <script src="angular-sanitize.js"></script>
19-
* </pre>
10+
* # ngSanitize
11+
*
12+
* The `ngSanitize` module provides functionality to sanitize HTML.
2013
*
21-
* # Usage
22-
* To make sure the module is available to your application, declare it as a dependency of you application
23-
* module.
14+
* {@installModule sanitize}
2415
*
25-
* <pre>
26-
* angular.module('app', ['ngSanitize']);
27-
* </pre>
16+
* See {@link ngSanitize.$sanitize `$sanitize`} for usage.
2817
*/
2918

3019
/*

src/ngTouch/directive/ngClick.js

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* the click event. This version handles them immediately, and then prevents the
1111
* following click event from propagating.
1212
*
13+
* Requires the {@link ngTouch `ngTouch`} module to be installed.
14+
*
1315
* This directive can fall back to using an ordinary click event, and so works on desktop
1416
* browsers as well as mobile.
1517
*

src/ngTouch/directive/ngSwipe.js

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* A leftward swipe is a quick, right-to-left slide of the finger.
1010
* Though ngSwipeLeft is designed for touch-based devices, it will work with a mouse click and drag too.
1111
*
12+
* Requires the {@link ngTouch `ngTouch`} module to be installed.
13+
*
1214
* @element ANY
1315
* @param {expression} ngSwipeLeft {@link guide/expression Expression} to evaluate
1416
* upon left swipe. (Event object is available as `$event`)
@@ -36,6 +38,8 @@
3638
* A rightward swipe is a quick, left-to-right slide of the finger.
3739
* Though ngSwipeRight is designed for touch-based devices, it will work with a mouse click and drag too.
3840
*
41+
* Requires the {@link ngTouch `ngTouch`} module to be installed.
42+
*
3943
* @element ANY
4044
* @param {expression} ngSwipeRight {@link guide/expression Expression} to evaluate
4145
* upon right swipe. (Event object is available as `$event`)

src/ngTouch/swipe.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
* The `$swipe` service is a service that abstracts the messier details of hold-and-drag swipe
99
* behavior, to make implementing swipe-related directives more convenient.
1010
*
11-
* It is used by the `ngSwipeLeft` and `ngSwipeRight` directives in `ngTouch`, and by
11+
* Requires the {@link ngTouch `ngTouch`} module to be installed.
12+
*
13+
* `$swipe` is used by the `ngSwipeLeft` and `ngSwipeRight` directives in `ngTouch`, and by
1214
* `ngCarousel` in a separate component.
1315
*
1416
* # Usage

src/ngTouch/touch.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44
* @ngdoc overview
55
* @name ngTouch
66
* @description
7-
* Touch events and other mobile helpers.
8-
* Based on jQuery Mobile touch event handling (jquerymobile.com)
7+
*
8+
* # ngTouch
9+
*
10+
* `ngTouch` is the name of the optional Angular module that provides touch events and other
11+
* helpers for touch-enabled devices.
12+
* The implementation is based on jQuery Mobile touch event handling
13+
* ([jquerymobile.com](http://jquerymobile.com/))
14+
*
15+
* {@installModule touch}
16+
*
17+
* See {@link ngTouch.$swipe `$swipe`} for usage.
918
*/
1019

1120
// define ngTouch module

0 commit comments

Comments
 (0)