26

I use PHP and JavaScript in my project, which I entirely code with netbeans 7.0.1. I really like how netbeans includes and uses the JavaDoc commenting style, both for PHP and JS code.

Now, I want to generate the code documentation from PHP as well as JS code. I know there are several ways doing it, but my main aim is to have the documentation for both parts in one documentation.

To explain it further: So e.g., I could use Doxygen and process the PHP files and JsDoc to process the JS files. The result would be, that I now have two different docs in two different folders - a result which I don't like. As I mentioned, I want both in one documentation.

So, first I went the way via using the doxygen helper js2doxy.pl (http://jsunit.berlios.de/internal.html), but that wasn't flexible enough. It works well with "normal" defined functions, but not with anonymous js functions.

After a bit of trying a lot I thought why not alter the FILE_PATTERNS option of document to process .js files, as the JavaDoc style of the comments are nearly identical to the ones used with PHP. And well, the result looks promising, but some functions are missing in the doc.

Here are examples:

/**
 * Definitions for the languages.
 * @memberof Language
 */
Language.Definitions = (function()
{
...
}

This works very well, I can see the documentation. But:

**
 * Definitions for the languages
 * @memberof Language
 */
Language.Definitions = (function()
{
    var Translations = {};

    /**
     * Replaces strings.
     * @memberof Language
     * @param string translation Translation string 
     * @param array parameters (optional) List of parameters
     * 
     * @return string replaced string
     */
    function replaceStrings(translation, parameters)
    {
       ...
    }

In this example I see the docs for Language.Definitions but not for replaceStrings(). Do you have any idea, what I am doing wrong? The same construct is process by JsDoc very well.

Also (part of Language.Definitions) ...

... 
return {
        /**
         * Initialize translations
         * 
         * @memberof Language
         */
        initTranslations: function()
        {
           ...
        } 
... 
}

... is not shown in the documentation.

I also wouldn't mind if someone would show me how to best merge the two outputs of doxygen and JsDoc into one documentation.

Thanks a lot in advance!

Greetings!

John Archer
  • 2,407
  • 2
  • 25
  • 33

1 Answers1

14

See the special command \fn to explicitly declare the function in the doxygen, preferably in the header of source, like this:

/*!
 * Language
 * Declare the root class
 * \Class Language
 */

/*! 
 * definitions is a property in the Language class
 * \property Definitions definitions
 */

/*!
 * Document the Definitions static class that used as property in the Language class
 * \Class Definitions
 */

/*!
 * Replaces strings
 * Document the static method for the Definitions class
 * \fn string replaceStrings(translation, parameters)
 * \memberof Definitions
 * \param string translation Translation string 
 * \param array parameters (optional) List of parameters
 * \return string replaced string
 */

Language.definitions = (function()
{
    var Translations = {};

    function replaceStrings(translation, parameters)
    {
       ...
    }
albert
  • 8,285
  • 3
  • 19
  • 32
Wagner Pinheiro
  • 339
  • 5
  • 14
  • 2
    After that long time, I finally could test it and it seems to work. Two things I had to change: `\Class` must be `\class` (lower case) and `\property Definitions definitions` must be `\property Definitions Definitions`. Unfortunately the class hierarchy is not considered. I tried things like `\property Language.Definitions Language.Definitions` and `\class Language.Definitions` which partly works, but there are still quirks left (e.g. doxygen compiler warnings). – John Archer Jan 23 '13 at 13:52
  • check the doxygen pages, there is support for Javascript. Apart from that , works for me. – Zane Oct 17 '13 at 15:01
  • 1
    @Zane, doxygen javascript [pages](http://www.stack.nl/~dimitri/doxygen/helpers.html#doxfilt_js) don't load could you please tell the steps to config it to support javascript? – user3806649 Aug 24 '15 at 19:16
  • @Wagner Pinheiro, Where the file located for make doxyden document js projects? – user3806649 Aug 24 '15 at 19:20
  • @user3933607, doxygen don't document js, you must use explicit [special commands](http://www.stack.nl/~dimitri/doxygen/manual/commands.html) to do that. Or, you can use a specific [script](https://www.stack.nl/~dimitri/doxygen/helpers.html) to parse the javascript. – Wagner Pinheiro Aug 24 '15 at 19:33
  • @WagnerPinheiro, Thanks, so what is this [about](http://www.stack.nl/~dimitri/doxygen/helpers.html#doxfilt_js) as its links don't load for me? and how can I document javascript using special commands or the script? – user3806649 Aug 24 '15 at 19:42
  • 1
    @user3933607, neither for me, i found out the script [here](https://github.com/mrdon/jsunit/blob/master/jsunit/util/js2doxy.pl). – Wagner Pinheiro Aug 24 '15 at 19:59
  • @WagnerPinheiro, where should I put the script? (My platform is windows). – user3806649 Aug 24 '15 at 21:50
  • @WagnerPinheiro, could you please help me to fix it out? – user3806649 Aug 25 '15 at 15:54
  • @user3933607, see: [How to run Perl script on a windows machine](http://stackoverflow.com/questions/13160223/how-to-run-perl-script-on-a-windows-machine) – Wagner Pinheiro Aug 25 '15 at 17:12
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/87929/discussion-between-user3933607-and-wagner-pinheiro). – user3806649 Aug 25 '15 at 21:14
  • 4
    @user3933607: here is something that helped me: http://coherent-labs.com/blog/documenting-javascript-with-doxygen/ You need doxygen.js - the page tells you where to find it and how to configure doxygen to make it work – Zane Aug 25 '15 at 21:35
  • @Zane, I am new to doxygen and I use its UI for documentation, I put doxygen.js and Doxyfile to its bin directory, how can I config it? – user3806649 Aug 26 '15 at 07:02