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 | - v1.1.0: |
23 | - Issue ♯3 : String.substr ( ) is deprecated... Replace... |
24 | Doc reviewed 20211111 |
25 | */ |
26 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
27 | |
28 | import theLinkBuilder from './LinkBuilder.js'; |
29 | |
30 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
31 | /** |
32 | Build the nav and footer HTMLElements for all the HTML pages |
33 | */ |
34 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
35 | |
36 | class NavHtmlBuilder { |
37 | |
38 | /** |
39 | The path between the html file and theConfig.destDir ( something like '../../../', depending of the folders tree ) |
40 | @type {String} |
41 | */ |
42 | |
43 | #rootPath; |
44 | |
45 | /** |
46 | The navigation html string |
47 | @type {String} |
48 | */ |
49 | |
50 | #navHtml; |
51 | |
52 | /** |
53 | The constructor |
54 | */ |
55 | |
56 | constructor ( ) { |
57 | Object.freeze ( this ); |
58 | } |
59 | |
60 | /** |
61 | Add the li html elements to the nav html string for variables and classes |
62 | @param {Array.<Array.<String>>} links The links to add |
63 | */ |
64 | |
65 | #buildList ( links ) { |
66 | let firstLetter = ''; |
67 | links.forEach ( |
68 | link => { |
69 | if ( firstLetter !== link [ 0 ] [ 0 ].toUpperCase ( ) ) { |
70 | firstLetter = link [ 0 ] [ 0 ].toUpperCase ( ); |
71 | this.#navHtml += `<li class="navLetter">${firstLetter}</li>`; |
72 | } |
73 | this.#navHtml += `<li><a href="${this.#rootPath + link [ 1 ]}">${link [ 0 ]}</a> </li>`; |
74 | } |
75 | ); |
76 | } |
77 | |
78 | /** |
79 | Add the li html elements to the nav html string for source files |
80 | @param {Array.<Array.<String>>} links The links to add |
81 | */ |
82 | |
83 | #buildSourcesList ( links ) { |
84 | let path = ''; |
85 | links.forEach ( |
86 | link => { |
87 | const filePath = link [ 0 ].substring ( 0, link [ 0 ].lastIndexOf ( '/' ) ); |
88 | const fileName = link [ 0 ].substring ( link [ 0 ].lastIndexOf ( '/' ) + 1 ); |
89 | if ( path !== filePath ) { |
90 | path = filePath; |
91 | this.#navHtml += `<li class="navLetter">${filePath}</li>`; |
92 | } |
93 | this.#navHtml += `<li><a href="${this.#rootPath + link [ 1 ]}">${fileName}</a> </li>`; |
94 | } |
95 | ); |
96 | } |
97 | |
98 | /** |
99 | Build the nav html element for an html page |
100 | @param {String} rootPath The path between the file where the nav will be inserted and theConfig.destDir |
101 | ( something like '../../../', depending of the folders tree ) |
102 | @return {String} The nav html |
103 | */ |
104 | |
105 | build ( rootPath ) { |
106 | |
107 | this.#rootPath = rootPath; |
108 | |
109 | this.#navHtml = '<nav>'; |
110 | |
111 | this.#navHtml += `<div id="homeNav"><a href="${this.#rootPath + 'index.html'}">🏠</a></div>`; |
112 | |
113 | this.#navHtml += '<div id="sourcesNav">Sources</div><ul id="sourcesNavList">'; |
114 | this.#buildSourcesList ( theLinkBuilder.sourcesLinks ); |
115 | this.#navHtml += '</ul>'; |
116 | |
117 | this.#navHtml += '<div id="variablesNav">Globals</div><ul id="variablesNavList">'; |
118 | this.#buildList ( theLinkBuilder.variablesLinks ); |
119 | this.#navHtml += '</ul>'; |
120 | |
121 | this.#navHtml += '<div id="classesNav">Classes</div><ul id="classesNavList">'; |
122 | this.#buildList ( theLinkBuilder.classesLinks ); |
123 | this.#navHtml += '</ul>'; |
124 | |
125 | this.#navHtml += '<div id="showPrivateNav" title="Show or hide private properties and methods">#</div>'; |
126 | |
127 | this.#navHtml += '</nav>'; |
128 | |
129 | return this.#navHtml; |
130 | } |
131 | |
132 | /** |
133 | The footer to be inserted in the html pages |
134 | @type {String} The fooder html |
135 | */ |
136 | |
137 | get footer ( ) { |
138 | return '<footer>Documentation generated with ' + |
139 | '<a href="https://github.com/wwwouaiebe/ESSimpleDoc" target="_blank" rel="noopener noreferrer">' + |
140 | 'ESSimpleDoc</a></footer>'; |
141 | } |
142 | } |
143 | |
144 | export default NavHtmlBuilder; |
145 | |
146 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
147 |