-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
logging.js
46 lines (39 loc) · 1.08 KB
/
logging.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
/**
* Assemble <http://assemble.io>
*
* Copyright (c) 2014-2017, Jon Schlinkert, Brian Woodward, contributors.
* Licensed under the MIT License (MIT).
*/
var sort = require('sort-object');
module.exports.register = function(Handlebars) {
'use strict';
Handlebars.registerHelper('inspect', function(context, options) {
var hash = options.hash || {};
var ext = hash.ext || '.html';
context = JSON.stringify(sort(context), null, 2);
// Wrap the returned JSON in either markdown code fences
// or HTML, depending on the extension.
var md = '\n```json\n' + context + '\n```';
var html = '<pre><code class="json">\n' + context + '\n</code></pre>';
var result = switchOutput(ext, md, html);
return new Handlebars.SafeString(result);
});
};
function switchOutput(ext, markdown, html) {
var output;
switch (ext) {
// return markdown
case '.markdown':
case '.md':
output = markdown;
break;
// return HTML
case '.html':
case '.htm':
output = html;
break;
default:
output = html;
}
return output;
}