Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge e200157 into 33358ce
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis535 committed Dec 30, 2015
2 parents 33358ce + e200157 commit 4a3db22
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions index.js
Expand Up @@ -5,6 +5,7 @@ var Promise = require('bluebird');
var _ = require('lodash');
var Path = require('path');
var writable = require('./lib/writable');
var path = require('path');

/**
* Duck-typing to allow different promise implementations to work.
Expand Down Expand Up @@ -67,6 +68,7 @@ function getPromises(obj, fn) {
module.exports = function (data, options) {
var dataDependencies;
options = options || {};
options.pages || {};
var dependencies = [];
Handlebars = instance();
//Go through a partials object
Expand Down Expand Up @@ -117,8 +119,25 @@ module.exports = function (data, options) {
return through.obj(function (file, enc, callback) {
var self = this;
Promise.all(dependencies).then(function () {
file.contents = new Buffer(Handlebars.compile(file.contents.toString())(data));
self.push(file);
var parsedPath = path.parse(file.path);
var pages = options.pages[ parsedPath.base ];
var tpl = Handlebars.compile(file.contents.toString());

if( pages == null ) {
file.contents = new Buffer(tpl(data));
self.push(file);
} else {
pages.forEach(function (pageName, i) {
var pageFile = file.clone();
parsedPath.base = pageName;
pageFile.path = path.format(parsedPath);
data._pageNum = i;
data._file = pageFile;

pageFile.contents = new Buffer(tpl(data));
self.push(pageFile);
});
}
}.bind(this)).catch(function (err) {
self.emit('error', new gutil.PluginError('gulp-static-handlebars', err));
}).finally(function () {
Expand Down

0 comments on commit 4a3db22

Please sign in to comment.