-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
123 lines (99 loc) · 3.34 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
(function(){
'use strict';
var through2 = require('through2'),
path = require('path'),
gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var helpers = require('./lib/helpers.js');
var Backend = require('./lib/backend.js');
var _ = require('underscore');
var vfs = require('vinyl-fs');
/**
* That's the plugin parser
*/
var streamParser = function (config) {
config = config || {};
config = helpers.configure(config);
var wp = new Backend(config);
var templateReady;
var parse = function(file, enc, next){
if (file.isNull()) return; // ignore
if (file.isStream()) return this.emit('error', new PluginError('gulp-docco', 'Streaming not supported'));
// Ignore unsupported files altogether
var lang = helpers.isSupported(file.path, config);
if (!lang) {
next();
return;
}
// Got template? process file and go on
if(templateReady){
wp.process(file);
this.push(file);
next();
return;
}
// Otherwise, grab the template and go with it
templateReady = [config.template];
if(config.css)
templateReady.push(config.css);
if(config['public'])
templateReady.push(config['public'] + '/**/*');
// Hold while we receive the template files
vfs.src(templateReady)
.pipe(through2.obj(function(f, e, n){
// Template hile itself? Process it
if(typeof config.template == 'string' && f.path == path.resolve(config.template)){
config.template = _.template(f.contents.toString('utf8'));
n();
return;
}
if(/\/public\//.test(f.path))
f.base = path.dirname(f.base);
// Insert into the stream if not template
this.push(f);
n();
}.bind(this), function(end){
end();
// So, we have the template complete - do the file itself now
wp.process(file);
this.push(file);
next();
}.bind(this)));
};
return through2.obj(parse);
};
// // Wrap reporter helper
// var wrapReporter = function(reporter){
// return function(options){
// return through2.obj(function(file, enc, next){
// var warnings = JSON.parse(file.contents.toString('utf8')).warnings;
// if(warnings && warnings.length){
// // Don't trust the (yahoo) reporter too much
// try{
// reporter(warnings, options);
// }catch(e){
// return this.emit('error', new PluginError('gulp-docco', 'Reporter crashed!' + e));
// }
// }
// this.push(file);
// next();
// });
// };
// };
// var docco = function(destination, template, infos, buildOptions){
// return gutil.combine(
// docco.parser(infos),
// // docco.reporter(),
// // docco.generator(destination, template, buildOptions)
// )();
// };
// // Yui default, provided reporter
// docco.yuiReporter = wrapReporter(require('./lib/uglyreporter'));
// // Our own reporter
// docco.chalkReporter = wrapReporter(require('./lib/chalkreporter'));
// // Default to chalk, nicier :)
// docco.reporter = docco.chalkReporter;
// docco.generator = streamGenerator;
// docco.parser = streamParser;
module.exports = streamParser;
}());