Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 404c9a6

Browse files
matskomhevery
authored andcommitted
feat(ngdocs): add variable type hinting with colors
1 parent ee26890 commit 404c9a6

File tree

2 files changed

+101
-23
lines changed

2 files changed

+101
-23
lines changed

docs/src/ngdoc.js

+62-23
Original file line numberDiff line numberDiff line change
@@ -348,28 +348,59 @@ Doc.prototype = {
348348

349349
},
350350

351+
prepare_type_hint_class_name : function(type) {
352+
var typeClass = type.toLowerCase().match(/^[-\w]+/) || [];
353+
typeClass = typeClass[0] ? typeClass[0] : 'object';
354+
return 'label type-hint type-hint-' + typeClass;
355+
},
356+
351357
html_usage_parameters: function(dom) {
352-
dom.h('Parameters', this.param, function(param){
353-
dom.tag('code', function() {
354-
dom.text(param.name);
355-
if (param.optional) {
356-
dom.tag('i', function() {
357-
dom.text('(optional');
358-
if(param['default']) {
359-
dom.text('=' + param['default']);
360-
}
361-
dom.text(')');
362-
});
358+
var self = this;
359+
var params = this.param ? this.param : [];
360+
if(params.length > 0) {
361+
dom.html('<h2 id="parameters">Parameters</h2>');
362+
dom.html('<table class="variables-matrix table table-bordered table-striped">');
363+
dom.html('<thead>');
364+
dom.html('<tr>');
365+
dom.html('<th>Param</th>');
366+
dom.html('<th>Type</th>');
367+
dom.html('<th>Details</th>');
368+
dom.html('</tr>');
369+
dom.html('</thead>');
370+
dom.html('<tbody>');
371+
for(var i=0;i<params.length;i++) {
372+
param = params[i];
373+
var name = param.name;
374+
var types = param.type;
375+
if(types[0]=='(') {
376+
types = types.substr(1);
363377
}
364-
dom.text(' – {');
365-
dom.text(param.type);
378+
379+
var limit = types.length - 1;
380+
if(types.charAt(limit) == ')' && types.charAt(limit-1) != '(') {
381+
types = types.substr(0,limit);
382+
}
383+
types = types.split(/\|(?![\(\)\w\|\s]+>)/);
384+
var description = param.description;
366385
if (param.optional) {
367-
dom.text('=');
386+
name += ' <div><em>(optional)</em></div>';
368387
}
369-
dom.text('} – ');
370-
});
371-
dom.html(param.description);
372-
});
388+
dom.html('<tr>');
389+
dom.html('<td>' + name + '</td>');
390+
dom.html('<td>');
391+
for(var j=0;j<types.length;j++) {
392+
var type = types[j];
393+
dom.html('<a href="" class="' + self.prepare_type_hint_class_name(type) + '">');
394+
dom.text(type);
395+
dom.html('</a>');
396+
}
397+
dom.html('</td>');
398+
dom.html('<td>' + description + '</td>');
399+
dom.html('</tr>');
400+
};
401+
dom.html('</tbody>');
402+
dom.html('</table>');
403+
}
373404
if(this.animations) {
374405
dom.h('Animations', this.animations, function(animations){
375406
dom.html('<ul>');
@@ -387,11 +418,19 @@ Doc.prototype = {
387418
html_usage_returns: function(dom) {
388419
var self = this;
389420
if (self.returns) {
390-
dom.h('Returns', function() {
391-
dom.tag('code', '{' + self.returns.type + '}');
392-
dom.text('– ');
393-
dom.html(self.returns.description);
394-
});
421+
dom.html('<h2 id="returns">Returns</h2>');
422+
dom.html('<table class="variables-matrix">');
423+
dom.html('<tr>');
424+
dom.html('<td>');
425+
dom.html('<a href="" class="' + self.prepare_type_hint_class_name(self.returns.type) + '">');
426+
dom.text(self.returns.type);
427+
dom.html('</a>');
428+
dom.html('</td>');
429+
dom.html('<td>');
430+
dom.html(self.returns.description);
431+
dom.html('</td>');
432+
dom.html('</tr>');
433+
dom.html('</table>');
395434
}
396435
},
397436

docs/src/templates/css/docs.css

+39
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,42 @@ ul.events > li > h3 {
202202
.clear {
203203
clear: both;
204204
}
205+
206+
.variables-matrix td {
207+
vertical-align:top;
208+
padding:5px;
209+
}
210+
211+
.type-hint {
212+
display:inline-block;
213+
}
214+
215+
.variables-matrix .type-hint {
216+
text-align:center;
217+
display:block;
218+
min-width:60px;
219+
}
220+
221+
.type-hint + .type-hint {
222+
margin-top:5px;
223+
}
224+
225+
.type-hint-string {
226+
background:#3a87ad;
227+
}
228+
229+
.type-hint-object {
230+
background:#999;
231+
}
232+
233+
.type-hint-array {
234+
background:#F90;;
235+
}
236+
237+
.type-hint-boolean {
238+
background:rgb(18, 131, 39);
239+
}
240+
241+
.type-hint-number {
242+
background:rgb(189, 63, 66);
243+
}

0 commit comments

Comments
 (0)