This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
52 lines (47 loc) · 1.43 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
var fs = require('fs')
var gutil = require('gulp-util')
var through = require('through2')
var mustache = require('mustache')
function reveal (content, option, callback) {
var view = {}
var slides = ''
content.split('\n<hr>\n').forEach(function (slide, i) {
var state = ''
if (slide.match(/<h2.*\?<\/h2>/)) {
state = ' data-state=q'
} else if (slide.indexOf('<h2') !== -1) {
state = ' data-state=title'
}
if (i === 0) {
view.title = slide.replace(/\<h2.*\>(.*)\<(.|\n)*/g, '$1')
state = ' data-state=front'
}
slides = slides.concat('\n<section' + state + '>\n' + slide + '\n</section>\n')
})
view.slides = slides
var template = fs.readFileSync(__dirname + '/template.mustache', 'utf8')
var data = mustache.to_html(template, view)
callback(null, data)
}
module.exports = function (options) {
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
this.push(file)
return cb()
}
if (file.isStream()) {
this.emit('error', new gutil.PluginError('gulp-reveal', 'Streaming not supported'))
return cb()
}
reveal(file.contents.toString(), options, function (err, data) {
if (err) {
this.emit('error', new gutil.PluginError('gulp-reveal', err))
} else {
file.contents = new Buffer(data)
file.path = gutil.replaceExtension(file.path, '.html')
}
this.push(file)
cb()
}.bind(this))
})
}