Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

grunt-ngdocs

m7r20kMITdeprecated0.2.11

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

grunt plugin for angularjs documentation

gruntplugin, angular, grunt, ngdocs, documention

readme

grunt-ngdocs

Grunt plugin to create a documentation like AngularJS NOTE: this plugin requires Grunt 0.4.x

ATTENTION: grunt-ngdocs 0.2+ is for angularjs 1.2+ grunt-ngdocs 0.2.5 supports angularjs 1.3+ too Please include angular.js and angular-animate.js with the scripts option

Getting Started

From the same directory as your project's Gruntfile and package.json, install this plugin with the following command:

npm install grunt-ngdocs --save-dev

Once that's done, add this line to your project's Gruntfile:

grunt.loadNpmTasks('grunt-ngdocs');

A full working example can be found at https://github.com/m7r/grunt-ngdocs-example

Config

Inside your Gruntfile.js file, add a section named ngdocs. Here's a simple example:

ngdocs: {
  all: ['src/**/*.js']
}

And with many options:

ngdocs: {
  options: {
    dest: 'docs',
    scripts: ['../app.min.js'],
    html5Mode: true,
    startPage: '/api',
    title: "My Awesome Docs",
    image: "path/to/my/image.png",
    imageLink: "http://my-domain.com",
    titleLink: "/api",
    inlinePartials: true,
    bestMatch: true,
    analytics: {
          account: 'UA-08150815-0'
    },
    discussions: {
          shortName: 'my',
          url: 'http://my-domain.com',
          dev: false
    }
  },
  tutorial: {
    src: ['content/tutorial/*.ngdoc'],
    title: 'Tutorial'
  },
  api: {
    src: ['src/**/*.js', '!src/**/*.spec.js'],
    title: 'API Documentation'
  }
}

Targets

Each grunt target creates a section in the documentation app.

src

[required] List of files to parse for documentation comments.

title

[default] 'API Documentation'

Set the name for the section in the documentation app.

api

[default] true for target api

Set the sidebar to advanced mode, with sections for modules, services, etc.

Options

dest

[default] 'docs'

Folder relative to your Gruntfile where the documentation should be built.

scripts

[default] ['angular.js']

Set which angular.js file or addional custom js files are loaded to the app. This allows the live examples to use custom directives, services, etc. The documentation app works with angular.js 1.2+ and 1.3+. If you include your own angular.js include angular-animate.js too.

Possible values:

  • ['angular.js'] use angular and angular-animate 1.2.16 delivered with grunt-ngdocs
  • ['path/to/file.js'] file will be copied into the docs, into a grunt-scripts folder
  • ['http://example.com/file.js', 'https://example.com/file.js', '//example.com/file.js'] reference remote files (eg from a CDN)
  • ['../app.js'] reference file relative to the dest folder

deferLoad

[default] false

If you want to use requirejs as loader set this to true.

Include 'js/angular-bootstrap.js', 'js/angular-bootstrap-prettify.js', 'js/docs-setup.js', 'js/docs.js' with requirejs and finally bootstrap the app angular.bootstrap(document, ['docsApp']);.

styles

[default] []

Copy additional css files to the documentation app

template

[default] null

Allow to use your own template. Use the default template at src/templates/index.tmpl as reference.

startPage

[default] '/api'

Set first page to open.

html5Mode

[default] false

Whether or not to enable html5Mode in the docs application. If true, then links will be absolute. If false, they will be prefixed by #/.

bestMatch

[default] false

The best matching page for a search query is highlighted and get selected on return. If this option is set to true the best match is shown below the search field in an dropdown menu. Use this for long lists where the highlight is often not visible.

title

[default] "name" or "title" field in pkg

Title to put on the navbar and the page's title attribute. By default, tries to find the title in the pkg. If it can't find it, it will go to an empty string.

[default] no anchor tag is used

Wraps the title text in an anchor tag with the provided URL.

image

A URL or relative path to an image file to use in the top navbar.

[default] no anchor tag is used

Wraps the navbar image in an anchor tag with the provided URL.

[default] null

Path to a template of a nav HTML template to include. The css for it should be that of listitems inside a bootstrap navbar:

<header class="header">
  <div class="navbar">
    <ul class="nav">
      {{links to all the docs pages}}
    </ul>
    {{YOUR_NAV_TEMPLATE_GOES_HERE}}
  </div>
</header>

Example: 'templates/my-nav.html'

The template, if specified, is pre-processed using grunt.template.

[default] true

Display "View source" link. Possible values are

  • true: try to read repository from package.json (currently only github is supported)
  • false: don't display link
  • string: template string like 'https://internal.server/repo/blob/{{sha}}/{{file}}#L{{codeline}}'

    available placeholders:

    • file: path and filename current file
    • filename: only filename of current file
    • filepath: directory of current file
    • line: first line of comment
    • codeline: first line after comment
    • version: version read from package.json
    • sha: first 7 characters of current git commit

[default] true

Display "Improve this doc" link. Same options as for sourceLink.

editExample

[default] true

Show Edit Button for examples.

inlinePartials

[default] false

If set to true this option will turn all partials into angular inline templates and place them inside the generated index.html file. The advantage over lazyloading with ajax is that the documentation will also work on the file:// system.

discussions

Optional include discussions in the documentation app.

{
  shortName: 'my',
  url: 'http://my-domain.com',
  dev: false
}

analytics

Optional include Google Analytics in the documentation app.

{
  account: 'UA-08150815-0'
}

How it works

The task parses the specified files for doc comments and extracts them into partial html files for the documentation app.

At first run, all necessary files will be copied to the destination folder. After that, only index.html, js/docs-setup.js, and the partials will be overwritten.

Partials that are no longer needed will not be deleted. Use, for example, the grunt-contrib-clean task to clean the docs folder before creating a distribution build.

After an update of grunt-ngdocs you should clean the docs folder too.

A doc comment looks like this:

/**
 * @ngdoc directive
 * @name rfx.directive:rAutogrow
 * @element textarea
 * @function
 *
 * @description
 * Resize textarea automatically to the size of its text content.
 *
 * **Note:** ie<9 needs polyfill for window.getComputedStyle
 *
 * @example
   <example module="rfx">
     <file name="index.html">
         <textarea ng-model="text"rx-autogrow class="input-block-level"></textarea>
         <pre>{{text}}</pre>
     </file>
   </example>
 */
angular.module('rfx', []).directive('rAutogrow', function() {
  //some nice code
});

Check out the Writing AngularJS documentation wiki article to see what's possible, or take a look at the AngularJS source code for more examples.

Batarang

If your examples are empty you maybe have batarang enabled for the docs site. This is the same issue as on http://docs.angular.js and the batarang team is informed about it #68.

License

MIT License

changelog

0.2.11 (2018-01-27)

Features

docs

  • visualize @deprecated in sizebar (847e1ce8)

ngdocs

  • improve error messages when name is missing from comment #147 (6c03cde5)

  • normalize path for different platforms #199 (580c525c)

  • make description of @param and @returns optional (aa1d76ad)

  • add commit {{rev}} in sourceLink (e7dcf87c)

  • add support for component type (cd71c95e)

  • use lodash (7963898f)

0.2.10 (2016-05-02)

Features

ngdocs

  • support Grunt 1.0 (6164a8b1)

  • add external links and link parsing to @requires (309edc40)

Bug fixes

docs

  • allow to load modules that use $animate #185 (25f573b1)

  • only $destroy existing embed rootScope #179 #183 (47c83b50)

0.2.9 (2015-08-12)

Features

ngdocs

Bug fixes

docs

0.2.8 (2015-06-29)

Features

docs

  • allow to inline partials (5980bb6d)

  • use current google analytics script (7037751b)

  • allow grunt variables in options.scripts (4c17f086)

  • allow custom template (c8057c32)

Bug fixes

docs

  • run from file:// url again (c9f528a5)

  • use correct provider url #151 (c1ddab43)

ngdocs

  • use correct options for ngdoc files (b5672949)

0.2.7 (2015-02-12)

Features

parameters

  • add parameter property support (e5fc7f72)

docs

  • ellipsis and title for long module names (c0795df1)

  • make use of ngAnimate optional #133 (99b8a5b8)

  • read package.json if pkg is not set in grunt.initConfig() (4c3d3c3a)

  • optional view source and improve this doc links #25 (a42e2f7b)

  • show edit in plunker as link (29b2b3bb)

  • html5Mode is now disabled by default (909c994b)

Bug fixes

ngdocs

  • add missing method to ngdoc location provider (a28000d8)

  • postDigestQueue not being processed (9a9de1f9)

  • don't break css for method close collapse #119 #126 (6639f06c)

0.2.6 (2014-10-27)

Features

ngdocs

  • parse all given files #58 #71 (793d797d)

Bug fixes

ngdocs

0.2.5 (2014-09-17)

Features

docs

  • allow to include angular.js 1.3+ (7744e914)

Bug fixes

ngdocs

  • parse dom before checking for broken links (53520ce4)

docs

  • use ngApp as an attribute #99 (94297107)

  • hide sections headers if angular.js 1.3+ is used (08e3b199)

0.2.4 (2014-09-09)

Bug fixes

docs

  • correct base url in ie #106 (fb8af0fb)

0.2.3 (2014-08-26)

Features

docs

Bug fixes

docs

  • remove jsfiddle from edit example options #101 (22870f19)

0.2.2 (2014-04-29)

Features

docs

  • make the app load deferrable (8b714eb9)

ngdocs

  • Support for documenting controllers and capitalized services, prettyprint custom usage examples (24a26807)

Bug fixes

docs

  • proper header img styling in ie8 (9c8ca7b3)

0.2.1 (2014-01-13)

Bug fixes

docs

  • allow requirejs in options.scripts (faaebd9f)

  • links in examples should show url of loaded files (like 0.1 version) (2b505a15)

ATTENTION

Clear your old docs js folder on upgrade

0.2.0 (2014-01-10)

Features

docs

  • updates for angularjs 1.2.7 (0eb8fa2f)

BRACKING CHANGE

Works only with angularjs 1.2+

ATTENTION

Clear your old docs js and css folder on upgrade

0.1.10 (2014-01-10)

Features

ngdocs

Bug fixes

ngdocs

  • pass options to js file too fix #54 (97f00b92)

  • @requires prefix only $name with ng. fix #61 (d407eb3c)

0.1.9 (2014-01-09)

Features

ngdocs

  • update parser to angularjs 1.2.7 code (7261eade)

    markdown parser has switched from showdown to marked.

  • import parser unit tests from angularjs 1.2.7 (fdeaddc1)

  • check broken links (6d22869b)

0.1.8 (2014-01-06)

Features

docs

  • remove angularjs favicon (8ca93964)
  • Preprocess navTemplate via grunt.template (8840d036)

ngdocs

  • override module name parsing (3a92ae93)

Bug fixes

docs

readme

0.1.7 (2013-09-13)

Features

ngdocs

  • hide param.property in all usage examples (3ba0464b)

  • adds image option to the navbar for custom image (1e2a8f7e)

docs

  • highlight search best match (3f8d8512)

  • make search pulldown optional (e774db97)

Bug fixes

docs

  • adjust search field width in ie8 (173d8f3d)

0.1.6 (2013-08-01)

Features

docs

  • optimize sidebar & breadcrum style (6947ed47)

  • smaller font size for headings (a1a8eb5b)

Bug fixes

docs

0.1.5 (2013-07-30)

Bug fixes

docs

  • display pages in none html5 mode (f61fd5a2)

0.1.4 (2013-07-29)

Features

docs

  • allow custom routes in examples #23 (2836e465)

0.1.3 (2013-07-19)

Features

ngdocs

  • @param support for object properties (5e3c402c)

    @param {Object} param Some obj @param {String} param.name some name on the obj

    Object properties are not included in the method signature

  • support custom items with @requires (d0f488c2)

    @requires $cookie => $cookie href = currentsection/ng.$cookie @requires module.directive:tabs => tabs href = currentsection/module.directive:tabs @requires /section2/module.directive:tabs => tabs href = section2/module.directive:tabs

Bug fixes

ngdocs

  • make @methodOf work in all sections #21 (468904ab)

task

  • make backward compatible to 0.1.1 (64f656ff)

0.1.2 (2013-06-27)

Features

global

  • add module name to none overview module page (5b58367a)

  • allow multiple API sections or custom name for API section (3ebc5153)

  • make start page configurable #8 (5e764f54)

  • allow additional custom types (df3103be)

docs

  • make remote css files work (2d4e2aeb)

  • show section title in breadcrum (5b4e1a71)

Bug fixes

global

  • name overview pages for modules with dots correctly #13 (c804b1d1)

  • build ngdocs on windows #17 (27a884aa)

ngdocs

  • remove hardcoded section 'api' for js files (951db22e)

docs

  • take out 'IE restrictions' warning (a376ff3c)

  • search form submit load page in both url modes (183f67ce)

0.1.1 (2013-06-01)

Features

docs

  • Add partial support for dot in module name #4 (bf9b22b)

  • Add navbar customizable template, title option (7a8775a)

  • Add active class to active navbar item (c89ceb2)

  • Make remote scripts not be copied, only referenced (da75892)

  • Add 'html5mode' option and copy scripts to docs destination (b1f7413)

Bug fixes

docs

  • remove sidebar flicker at navigation in large docs (77f1521)

0.1.0 (2013-05-15)

Features

grunt-ngdocs

  • Build docs with grunt (8f61393)

docs

  • show current script urls and load these to plunk & jsfiddle (fc39352)

  • make compatible with angular 1.0.+ and 1.1.+ (28e55bd)

Bug fixes

docs

  • sidebar css (be5df81)