Passed
Push — master ( 5b3840...0dfdb8 )
by Björn
02:41
created

lib/adapters/sourcecode.js (1 issue)

1
2 1
var fs          = require('fs');
3 1
var glob        = require('glob');
4 1
var globAll     = require('glob-all');
5 1
var path        = require('path');
6 1
var extend      = require('util')._extend;
7 1
var format      = require('string-template');
8 1
var frontMatter = require('front-matter');
9 1
var escapeHTML  = require('escape-html');
10 1
var multiline   = require('multiline');
11 1
var highlightCode = require('../util/highlight-code');
12
13 1
var HTML_EXAMPLE_TEMPLATE = multiline(function() {/*
14
<div class="docs-code" data-patternlibrary-copycode>
15
<pre><code class="language-{0}">{1}</code></pre>
16
</div>
17
*/}).replace(/(^(\s)*)/gm, '');
18
19 1
module.exports = function(value, config, cb, pl) {
20
    var data = getSourceCode (value, config, pl);
21
    cb(null, processTree(data));
22
}
23
24 1
module.exports.config = {
25
    verbose: false
26
}
27
28 1
module.exports.search = function(items, link) {
29
    var results = [];
30
    // this => collider
31
    /* results.push({
32
        name: name,
33
        type: 'sass ' + type,
34
        description: description,
35
        link: link + hash
36
    }); */
37
38
    return results;
39
}
40
41
42
function getSourceCode(value, config, pl) {
43 4
    if (!fs.existsSync(value) || fs.statSync(value).isDirectory()) return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
44
45
    var sourceFile = frontMatter(fs.readFileSync(value).toString());
46
    var renderedCode = highlightCode('html', sourceFile.body);
47
    var output = format(HTML_EXAMPLE_TEMPLATE, ['html', renderedCode]);
48
49
    return {
50
        highlight : output,
51
        escaped   : escapeHTML(sourceFile.body),
52
        raw       : sourceFile.body
53
    };
54
}
55
56
57
function processTree(tree) {
58
    
59
    // do tree assignment stuff...
60
61
    return tree; //my_stuff;
62
}
63
64