Code coverage report for master/plugins/sourcetag.js

Statements: 86.67% (13 / 15)      Branches: 60% (6 / 10)      Functions: 100% (2 / 2)      Lines: 86.67% (13 / 15)      Ignored: none     

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