Документация ngdoc для контроллера
Я новичок в написании документации и пытаюсь задокументировать мое угловое приложение с помощью grunt-ngdocs.
Я клонировал рабочий пример с: https://github.com/m7r/grunt-ngdocs-example
В данном примере отсутствует документированный контроллер, поэтому я добавил свой документированный контроллер с этим кодом:
/**
* @ngdoc controller
* @name rfx.controller:testCtrl
* @description
* Description of controller.
*/
.controller('testCtrl', function() {
});
Когда я пытаюсь собрать документацию, запустив grunt из командной строки, я получаю следующее сообщение об ошибке:
Warning: Don't know how to format @ngdoc: controller Use --force to continue.
Как это исправить? Я прочитал это руководство http://www.shristitechlabs.com/adding-automatic-documentation-for-angularjs-apps/ и не могу понять, почему я продолжаю получать сообщение об ошибке, если я пытаюсь задокументировать контроллер:(Спасибо за любую помощь!
3 ответа
Похоже, что пример репо имеет устаревшую версию grunt-ngdocs
указан как зависимость. @ngdoc controller
поддерживается с 0.2.2, в то время как grunt-ngdocs-example
списки ~0.1.1. Используйте последние grunt-ngdocs
и тебе должно быть хорошо идти.
Стоит отметить, что "официальным" инструментом для создания документации Angular является dgeni + dgeni-packages. Он используется Angular 1.x для создания собственной документации. Очень гибкий и расширяемый, хотя установка может занять некоторое время.
Редактировать я разветвляюсь grunt-ngdocs-example
здесь, модернизировал grunt-ngdocs
версия и добавил пример контроллера.
Вот как вы можете документировать пример контроллера:
/**
* @ngdoc function
* @name appModernizationApp.controller:DetailsCtrl
* @description
* # DetailsCtrl
* Controller of the appModernizationApp
* This controller is responsible for showing the details of the page.
* It gets initialized by requesting the JSON for types of rooms which is hosted on the server.
* It also requests for the details of the room for an existing reservation if the reservation id is present in the route using <b>HRS.getRegisteredData(reservationId)</b>.
* @requires $scope
* @requires $http
* @requires HRS
* @requires $location
* @requires $routeParams
* @requires breadcrumbs
* @requires UtilitiesService
*
* @property {object} breadcrumbs:object breadcrumbs Handles the page level/navigation at the top.
* @property {array} reservationDetails:array This holds the reservation details of the current/selected reservation.
* @property {string} registerationErrorMsg:string This variable holds the error message for all registration services.
* @property {string} roomSearchErrorMsg:string This variable holds the error message for all room search services.
* @property {array} roomDetails:array This holds the room details object. This will be a fresh object coming from service response and will be manipulated as per the view model.
* @property {boolean} submitted:boolean Holds the submitted boolean flag. Initialized with false. Changes to true when we store the details.
* @property {number} reservationId:number Gets the reservation id from the route params.
* @property {date} minDate:date Date filled in the minimum date vatiable
* @property {boolean} isRoomDetailsVisible:boolean Controls the boolean flag for visibility of room details. Initialized with false.
* @property {array} roomTypes:array Holds types of rooms from JSON.
* @property {array} expirymonth:array Months from Jan to Dec
* @property {array} expiryYear:array Years of a particular range
* @property {array} cardtype:array Type of cards
*/
Используйте dgeni и добавьте пользовательский шаблон контроллера:
- Создайте
controller.template.html
вconfig/template/ngdoc/api
с содержанием{% extends "api/object.template.html" %}
(он будет наследоваться от шаблона объекта, но вы можете написать свой собственный шаблон) Перейдите к вашему конфигу dgeni и расширьте
idTemplates
вcomputeIdsProcessor
config(function (computeIdsProcessor) { computeIdsProcessor.idTemplates.find(function (idTempl) { return idTempl.idTemplate === "module:${module}.${docType}:${name}"; }).docTypes.push("controller");})
Не забудьте включить
"controller"
вcomputePathsProcessor
.config(function (computePathsProcessor) { computePathsProcessor.pathTemplates.push({ docTypes: ['provider', 'service', 'directive', 'input', 'object', 'function', 'filter', 'type', 'controller'], pathTemplate: '${area}/${module}/${docType}/${name}', outputPathTemplate: 'partials/${area}/${module}/${docType}/${name}.html' });})