-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
assemble.js
77 lines (62 loc) · 1.75 KB
/
assemble.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
/**
* Assemble <http://assemble.io>
*
* Copyright (c) 2014, Jon Schlinkert, Brian Woodward, contributors.
* Licensed under the MIT License (MIT).
*/
'use strict';
var path = require('path');
var series = require('async-each-series');
var plugin = require('../lib/plugin');
// var mapper = require('../lib/mapper');
var utils = require('../lib/utils');
module.exports = function(grunt) {
grunt.registerMultiTask('assemble', 'static site generator', function() {
var cb = this.async();
/**
* Assemble task options
*/
var opts = this.options({
plugins: [],
helpers: [],
data: [],
assets: '',
ext: '.html',
engine: 'hbs',
collections: {},
partials: [],
layoutdir: '',
layout: '',
layouts: '',
layoutext: ''
});
opts.engine = utils.formatExt(opts.engine);
opts.layoutext = opts.layoutext ? utils.formatExt(opts.layoutext) : opts.engine;
opts.layouts = opts.layouts || path.resolve(opts.layoutdir, '*.' + opts.layoutext);
/**
* Get the instance of assemble to use
*/
var app = opts.app;
if (!utils.isObject(opts.app) || !opts.app.isAssemble) {
app = require('assemble-core')();
}
// set `grunt` and `task` on the assemble instance
app.grunt = grunt;
app.task = this;
app.use(plugin(opts));
/**
* Load templates
*/
app.partials(opts.partials);
app.layouts(opts.layouts);
series(app.task.files, function(files, next) {
app.pages(files.src, app.options);
app.toStream('pages')
.pipe(app.renderFile(app.options.engine))
.on('error', console.log)
.pipe(app.dest(utils.dest(app, files)))
.on('error', next)
.on('end', next);
}, cb);
});
};