简体   繁体   English

对AngularJS应用程序使用JSDoc

[英]Using JSDoc for an AngularJS application

I am looking into adding documentation for my angular application and JSDoc seems to be a popular choice from my findings so far. 我正在考虑为我的有角度的应用程序添加文档,到目前为止,从我的发现来看,JSDoc似乎是一个受欢迎的选择。

I am now struggling to get some documentation to generate in a structure that follows the modules and the associated controllers\\directives\\services\\etc that are defined within. 我现在正在努力获取一些文档,这些文档将按照结构以及其中定义的模块和关联的控制器\\指令\\服务\\ etc生成。

First here is a sample of the sort of code I have in the application I am working on: 首先,这是我在正在处理的应用程序中拥有的那种代码的示例:

angular.module('app', [
  'app.core',
  'app.features'
]);


(function() {
  'use strict';

  angular.module('app.features', [
    'app.login',
    'app.home',
    'app.operations',
    'app.management',
    'app.customers'
  ]);
})();

(function() {
  'use strict';

  angular.module('app.customers', [
    'app.layout'
  ]);
})();


(function() {
  'use strict';

  angular
      .module('app.customers')
      .controller('CustomersListController', Controller);

  Controller.$inject = ['customerService', '$state'];

  function Controller(customerService, $state) {
    var vm = this,
      searchText;
    vm.customerService = customerService;
    vm.fetchCollection = fetchCollection;
    vm.deleteCustomer = deleteCustomer;
    vm.goToEdit = goToEdit;

    initialise();

    function initialise() {
      //some cool setup code here...

    }

    function fetchCollection(page, perPage){
      //some logic here
    }

    function deleteCustomer(model) {
      //delete logic
    }

    function goToEdit(model) {
      $state.go('customer.edit', {customerId:model.id});
    }

  }
})();

So now I want to write some documentation to cover the functions defined in the CustomersListController. 因此,现在我想写一些文档来介绍CustomersListController中定义的功能。

I have seen this post with the accepted answer demonstrating a way to define the relationships so I have attempted to use this in my code like so: 我看过这篇帖子,并给出了可接受的答案,它说明了一种定义关系的方法,因此我尝试在代码中像下面这样使用它:

/**
 * @namespace app
 */
angular.module('app', [
  'app.core',
  'app.features'
]);

/**
 * @class app.features
 * @memberOf app
 */
(function() {
  'use strict';

  angular.module('app.features', [
    'app.login',
    'app.home',
    'app.operations',
    'app.management',
    'app.customers'
  ]);
})();

/**
 * @class app.customers
 * @memberOf app.features
 */
(function() {
  'use strict';

  angular.module('app.customers', [
    'app.layout'
  ]);
})();

/**
 * @class app.customers.CustomersListController
 */
(function() {
  'use strict';

  angular
      .module('app.customers')
      .controller('CustomersListController', Controller);

  Controller.$inject = ['customerService', '$state'];

  function Controller(customerService, $state) {
    var vm = this,
      searchText;
    vm.customerService = customerService;
    vm.fetchCollection = fetchCollection;
    vm.deleteCustomer = deleteCustomer;
    vm.goToEdit = goToEdit;

    initialise();

    function initialise() {
      //some cool setup code here...

    }
        /**
     * @name fetchCollection
     * @function
     * @param {Number} page
     * @param {Number} perPage
     * @memberOf app.customers.CustomersListController
     * @description This is the Customers List controller
     * @returns {Array} An array of customer records
     */
    function fetchCollection(page, perPage){
      //some logic here
    }

    function deleteCustomer(model) {
      //delete logic
    }

    function goToEdit(model) {
      $state.go('customer.edit', {customerId:model.id});
    }

  }
})();

I am using gulp-documentation and have a task set up like so: 我正在使用gulp文档,并设置了一个像这样的任务:

gulp.task('build_docs', [], function () {
  var documentation = require('gulp-documentation');
  gulp.src(paths.angularAppFiles)
    .pipe(documentation({ format: 'html' }))
    .pipe(gulp.dest('./docs-html'))
});

Which when is run, produces the following output 运行时会产生以下输出

在此处输入图片说明

I was hoping for something more readable in terms of showing the correct hierarchy in the nav on the left, so app at top level, followed by app.features in second level and app.customers at third in a directory style display. 我希望在左侧的导航栏中显示正确的层次结构方面更具可读性,因此应用程序位于顶层,其次是目录样式显示中的app.features,第二层是app.features,第三层是app.customers。

Also, I notice 'module' is listed in the output too, but I'm not sure how that has been generated. 另外,我注意到在输出中也列出了“模块”,但是我不确定它是如何生成的。 I have module declarations and then a controller declaration on one of my modules in the code I have shared above, so where is JSDoc picking this up from? 我在上面共享的代码中有一个模块声明,然后在我的一个模块上声明了一个控制器声明,那么JSDoc是从哪里提取的呢?

What is the correct way using JSDoc syntax to define the relationships between modules declared in an angular application and their associated classes (controllers, services, directives, etc) so they appear in a pleasant nested view for easy navigation in the generated output? 使用JSDoc语法定义在角度应用程序中声明的模块与其关联的类(控制器,服务,指令等)之间的关系的正确方法是什么,以便它们出现在令人愉悦的嵌套视图中以便在生成的输出中轻松导航?

EDIT 编辑

I have also come across ngdocs and the gulp-ngdocs plugin but it seems to not be a very active repo with a number of issues still open. 我也遇到过ngdocs和gulp -ngdocs插件,但这似乎不是一个非常活跃的回购协议,但仍有许多问题尚未解决。 Can anyone offer any comments on this plugin and it suitability? 谁能对此插件及其适用性发表任何评论? I have downloaded and run the sample grunt-docs version which seems to work well enough, although clicking on the parent 'rfx' module fails to load a page (seeing 404's in browser console) - makes me a little nervous to be honest! 我已经下载并运行了示例grunt-docs版本,该版本似乎运行良好,尽管单击父级“ rfx”模块无法加载页面(在浏览器控制台中看到404),但老实说让我有些紧张!

The syntax for calling the gulp task has changed slightly since this post. 自从这篇文章以来,调用gulp任务的语法已稍有更改。

Latest syntax is below. 最新语法如下。

gulp.task('docs', function() {
var documentation = require('gulp-documentation');
gulp.src(tscConfig.compilerOptions.outDir)
    .pipe(documentation('html'))
    .pipe(gulp.dest('./docs-html'))
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM