UNPKG

1.28 kBJavaScriptView Raw
1/**
2 * 处理模版任务
3 * @author lukezhu
4 * @date 2016-03-24
5 */
6
7var combiner = require('stream-combiner2');
8var merge = require('merge-stream');
9
10module.exports = function(gulp, $, conf, browserSync) {
11 // swig 配置信息
12 // Docs: http://paularmstrong.github.io/swig/docs/
13 var swighljs = require('../config/swig_hljs.js');
14 var swigLocals = conf.build.templateVars;
15 var swigOptions = {
16 defaults : { cache: false, locals: swigLocals },
17 data : { page: {} },
18 setup : function(swig) {
19 // 在 swig 模版引擎中增加 highlight 标签 用于高亮代码片段
20 // Usage: {% highlight 'js' %}code...{% endhighlight %}
21 swig.setExtension(swighljs.ext.name, swighljs.ext.obj);
22 swig.setTag('highlight', swighljs.parse, swighljs.compile, swighljs.ends, swighljs.block);
23 }
24 }
25
26 gulp.task('template', function() {
27 var combined = combiner.obj([
28 gulp.src(conf.parsePwd(conf.tmplFiles), { base: conf.parsePwd(conf.app) }),
29 $.swig(swigOptions),
30 gulp.dest(conf.parsePwd(conf.tmp)),
31 browserSync.stream()
32 ]);
33
34 combined.on('error', console.error.bind(console));
35
36 return combined;
37 });
38}