-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
74 lines (55 loc) · 1.69 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
'use strict'
var File = require('vinyl')
var path = require('path')
var gutil = require('gulp-util')
var source = require('vinyl-source-stream')
var jade = require('jade')
var marked = require('marked')
var handlebars = require('handlebars')
var through = require('through2')
var fs = require('fs')
var dss = require('dss')
module.exports = function(options) {
// Setup options
options = options || {}
var files = []
var styleguide = []
var template = options.template || './templates/default/'
var parsers = options.parsers || {}
parsers = Array.prototype.slice.apply(parsers)
// Register parsers
parsers.forEach(function (name, callback) {
dss.parser(name, callback)
})
// Process files
function process (file, encoding, callback) {
if (file.isNull()) {
callback(null, file)
return
}
if (file.isStream()) {
callback(new gutil.PluginError('gulp-dss', 'Streaming not supported'))
return
}
dss.parse(file.contents.toString(), {}, function (parsed) {
// Add filename
parsed.file = file.path
// Generate files for individual blocks
parsed.blocks.forEach(function (block) {
var contents = jade.renderFile(template + 'view.jade', block)
var path = file.path + '-' + block.name + '.html'
var temp = new File({ path: path, contents: new Buffer(contents) })
callback(null, temp)
})
// Add file to styleguide object
styleguide.push(parsed)
// Return without the original file
callback(null, file)
})
}
function end (callback) {
jade.renderFile(template + 'index.jade', { locals: styleguide })
callback()
}
return through.obj(process, end)
}