1 | /**
|
2 | @module plugins/sourcetag
|
3 | @author Michael Mathews <micmath@gmail.com>
|
4 | */
|
5 | ;
|
6 |
|
7 | var logger = require('jsdoc/util/logger');
|
8 |
|
9 | exports.handlers = {
|
10 | /**
|
11 | Support @source tag. Expected value like:
|
12 | { "filename": "myfile.js", "lineno": 123 }
|
13 | Modifies the corresponding meta values on the given doclet.
|
14 |
|
15 | WARNING: If you are using a JSDoc template that generates pretty-printed source files,
|
16 | such as JSDoc's default template, this plugin can cause JSDoc to crash. To fix this issue,
|
17 | update your template settings to disable pretty-printed source files.
|
18 |
|
19 | @source { "filename": "sourcetag.js", "lineno": 13 }
|
20 | */
|
21 | newDoclet: function(e) {
|
22 | var tags = e.doclet.tags,
|
23 | tag,
|
24 | value;
|
25 |
|
26 | // any user-defined tags in this doclet?
|
27 | if (typeof tags !== 'undefined') {
|
28 | // only interested in the @source tags
|
29 | tags = tags.filter(function($) {
|
30 | return $.title === 'source';
|
31 | });
|
32 |
|
33 | if (tags.length) {
|
34 | // take the first one
|
35 | tag = tags[0];
|
36 |
|
37 | try {
|
38 | value = JSON.parse(tag.value);
|
39 | }
|
40 | catch(e) {
|
41 | logger.error('@source tag expects a valid JSON value, like { "filename": "myfile.js", "lineno": 123 }.');
|
42 | return;
|
43 | }
|
44 |
|
45 | e.doclet.meta = e.doclet.meta || {};
|
46 | e.doclet.meta.filename = value.filename || '';
|
47 | e.doclet.meta.lineno = value.lineno || '';
|
48 | }
|
49 | }
|
50 | }
|
51 | };
|