-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (38 loc) · 851 Bytes
/
index.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
'use strict';
/**
* # Toga Sample Formatter
*
* Walks a Toga abstract syntax tree, finds all samples, replaces the values
* with runnable iframed samples.
*/
var through = require('through2'),
mixin = require('mtil/object/mixin'),
traverse = require('traverse'),
/**
* Default options.
*/
defaults = {
keys: ['sample']
};
function runnable(value, options) {
console.log(value, options);
}
exports.formatter = function (options) {
options = mixin({}, defaults, options);
var keys = options.keys;
function format(value) {
// jshint validthis:true
if (keys.indexOf(this.key) === -1 || !value) {
return;
}
this.update(runnable(value, options));
}
function walk(file, enc, cb) {
var ast = file && file.ast;
if (ast) {
traverse(ast).forEach(format);
}
cb(null, file);
}
return through.obj(walk);
};