File : VariablesHtmlBuilder.js

1
/*
2
Copyright - 2021 - wwwouaiebe - Contact: https://www.ouaie.be/
3
4
This  program is free software;
5
you can redistribute it and/or modify it under the terms of the
6
GNU General Public License as published by the Free Software Foundation;
7
either version 3 of the License, or any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
*/
18
/*
19
Changes:
20
    - v1.0.0:
21
        - created
22
Doc reviewed 20211111
23
*/
24
/* ------------------------------------------------------------------------------------------------------------------------- */
25
26
import fs from 'fs';
27
import theConfig from './Config.js';
28
import theLinkBuilder from './LinkBuilder.js';
29
import NavHtmlBuilder from './NavHtmlBuilder.js';
30
31
/* ------------------------------------------------------------------------------------------------------------------------- */
32
/**
33
Build the HTML page for all the variables
34
*/
35
/* ------------------------------------------------------------------------------------------------------------------------- */
36
37
class VariablesHtmlBuilder {
38
39
    /**
40
    The html with the varables documentation
41
    @type {String}
42
    */
43
44
    #html = '';
45
46
    /**
47
    The constructor
48
    */
49
50
    constructor ( ) {
51
        Object.freeze ( this );
52
    }
53
54
    /**
55
    Build the html var a variable
56
    @param {VariableDoc} variableDoc The doc object of the variable
57
    */
58
59
    #buildVariable ( variableDoc ) {
60
61
        // type
62
        const typePostfix =
63
            variableDoc?.commentsDoc?.type
64
                ?
65
                ' : ' + theLinkBuilder.getClassLink ( variableDoc?.commentsDoc?.type, '' )
66
                :
67
                '';
68
69
        this.#html +=
70
            `<a id="${variableDoc.name}"></a><h3><span>${variableDoc?.kind ?? ''} </span>` +
71
            `${variableDoc.name}<span>${typePostfix}</span></h3>`;
72
73
        // description
74
        const desc =
75
            variableDoc?.commentsDoc?.desc
76
                ?
77
                theLinkBuilder.getDescLink ( variableDoc.commentsDoc.desc, '' )
78
                :
79
                ' ...No description provided. Coming soon?';
80
81
        this.#html += `<div>${desc}</div>`;
82
83
        // source
84
85
        const sourceLink = theLinkBuilder.getSourceLink ( variableDoc );
86
        this.#html += `<div>Source : <a href="${sourceLink}"> file ${variableDoc.file} at line ${variableDoc.line}</a></div>`;
87
    }
88
89
    /**
90
    Build the variables.html page
91
    @param {Array.<VariableDoc>} variablesDocs The docs objects for all variables
92
    */
93
94
    build ( variablesDocs ) {
95
96
        const navHtmlBuilder = new NavHtmlBuilder ( );
97
98
        // Sorting the docs
99
        variablesDocs.sort ( ( first, second ) => first.name.localeCompare ( second.name ) );
100
101
        // head
102
        this.#html =
103
            '<!DOCTYPE html><html><head><meta charset="UTF-8">' +
104
            '<link type="text/css" rel="stylesheet" href="ESSimpleDoc.css"></head><body>';
105
106
        // nav
107
        this.#html += navHtmlBuilder.build ( '' );
108
109
        // header
110
        this.#html += '<h1>Global variables</h1>';
111
112
        // loop on variables
113
        variablesDocs.forEach ( variableDoc => this.#buildVariable ( variableDoc ) );
114
115
        // footer
116
        this.#html += navHtmlBuilder.footer;
117
118
        this.#html += '</body></html>';
119
120
        // writting file
121
        fs.writeFileSync ( theConfig.destDir + 'variables.html', this.#html );
122
    }
123
}
124
125
export default VariablesHtmlBuilder;
126
127
/* --- End of file --------------------------------------------------------------------------------------------------------- */
128