【问题标题】:How to document jQuery-ui widgets with jsdoc-toolkit?如何使用 jsdoc-toolkit 记录 jQuery-ui 小部件?
【发布时间】:2013-08-11 13:47:47
【问题描述】:

我如何记录这个小部件,以便工具包可以公开方法和选项。
我尝试过的所有东西都不会在闭包内看到任何东西。

/**
* @fileOverview
* @version 1.0
*/

(function($) {
    "use strict";
    $.widget('mynamespace.nameofwidget', {

        // foo should show up in the docs
        options: {
            'foo': 'bar'
        },

        // public function name and parameters should be documented
        myPublic function () {
            // code here....
        },

        // private function no need to document
        _create: function () {
            // code here....
        },

        // private function no need to document
        _setOption: function (key, value) {
            // code here....
        },
    });

})(jQuery);

[编辑]

这是我的配置文件

{
    // source files to use
    _: ['js/test/'],

    // document all functions, even uncommented ones
    a: true,

    // including those marked @private
    p: true,

    // use this directory as the output directory
    d: "js/docs/",

    // use this template
    t: "jsdoc-toolkit/templates/jsdoc",

}

这是我正在使用的命令行命令。

java -jar jsdoc-toolkit/jsrun.jar jsdoc-toolkit/app/run.js  -c=js/docs/conf/ilo.conf

[更新配置]

{
    "opts": {
        "destination": "../js/out/",
        "private": true
    },
    "tags": {
        "allowUnknownTags": true
    },
    "source": {
        "include": [ "../js/test" ],
        "includePattern": ".+\\.js(doc)?$",
        "excludePattern": "(^|\\/|\\\\)_"
    },
    "plugins": [],
    "templates": {
        "cleverLinks": false,
        "monospaceLinks": false,
        "default": {
            "outputSourceFiles": true
        }
    }
}

【问题讨论】:

    标签: javascript jquery jquery-ui documentation jsdoc


    【解决方案1】:

    使用@name 和@namespace 指令(或者,您可以在构造函数上使用@name 指令)。以下是您的代码的示例文档:

    /**                                                                                                                                                                                           
     *@fileOverview                                                                                                                                                                               
     *@version 1.0                                                                                                                                                                                
     *                                                                                                                                                                                            
     * @namespace mynamespace.nameofwidget                                                                                                                                                        
     */                                                                                                                                                                                           
    
    (function($) {                                                                                                                                                                                
        "use strict";                                                                                                                                                                             
        $.widget('mynamespace.nameofwidget', {                                                                                                                                                    
    
            /**                                                                                                                                                                                   
             * @name mynamespace.nameofwidget#foo                                                                                                                                                 
             * @description Description of Foo                                                                                                                                                    
             */                                                                                                                                                                                   
            options: {                                                                                                                                                                            
                'foo': 'bar'                                                                                                                                                                      
            },                                                                                                                                                                                    
    
            /**                                                                                                                                                                                   
             * @name mynamespace.nameofwidget#myPublic
             * @function
             * @description some description                                                                                                                                                      
             */                                                                                                                                                                                   
            myPublic: function () {                                                                                                                                                               
                // code here....                                                                                                                                                                  
            },                                                                                                                                                                                    
    
            /**                                                                                                                                                                                   
             * @name mynamespace.nameofwidget#_create                                                                                                                                             
             * @function
             * @private                                                                                                                                                                           
             * @description will not show up in HTML docs, but the comments are good to have                                                                                                      
             */                                                                                                                                                                                   
            // private function no need to document                                                                                                                                               
            _create: function () {                                                                                                                                                                
                // code here....                                                                                                                                                                  
            },                                                                                                                                                                                    
    
            /**                                                                                                                                                                                   
             * @name mynamespace.nameofwidget#_setOption                                                                                    
             * @function
             * @private                                                                                                                                                                           
             * @param {String} key                                                                                                                                                                
             * @param {String} value                                                                                                                                                              
             * @description will not show up in HTML docs, but the comments are good to have                                                                                                      
             */                                                                                                                                                                                   
            // private function no need to document                                                                                                                                               
            _setOption: function (key, value) {                                                                                                                                                   
                // code here....                                                                                                                                                                  
            }                                                                                                                                                                                     
        });                                                                                                                                                                                       
    
    })(jQuery);
    

    请注意,如果在命令行中使用了-p 参数,@private 指令将不会从生成的文档中隐藏命令。

    有关名称路径的更多信息,请参阅this page,有关@private 指令的更多信息,请参阅this page。

    【讨论】:

    • 我将其复制并粘贴到一个文件中,然后在该文件上运行它。我收到“警告:试图将 XXXX 记录为未记录符号 mynamespace.nameofwidget 的成员。”对于小部件中的每个方法,当我查看输出的 index.html 时,nameofwidget 找不到,但在文件索引下,nameofwidget.js 文件被列出并被解析。
    • 我没有收到 jsdoc v3.2.0 的任何错误。你用的是什么版本?
    • 也许问题是我使用的是 jsdoc-toolkit,它被描述为 jsdoc 的包装器。我现在正在尝试通过 node.js 安装它,但它正在识别 git,所以可能需要我一点时间来弄清楚如何让 git 与 node.js 一起工作
    • 我使用自述文件中的这个命令来安装它:npm install -g git://github.com/jsdoc3/jsdoc.git。
    • 是的,这给了我一个错误“npm ERR!未找到:git”。我最终手动下载它并将其添加到我的项目中,我让它使用“jsdoc -c conf.json”运行,它在 out 文件夹中创建文件 nameofwidget.js.html 但 index.html 中没有列出任何内容我发布了新的 conf 文件
    猜你喜欢
    • 2011-12-25
    • 1970-01-01
    • 2017-03-09
    • 1970-01-01
    • 2019-04-06
    • 2012-11-04
    • 2021-02-20
    • 2013-05-30
    • 1970-01-01
    相关资源
    最近更新 更多