2014-08-29 00:40:18 +03:00
|
|
|
var gulp = require('gulp');
|
|
|
|
var handlebars = require('gulp-handlebars');
|
|
|
|
var declare = require('gulp-declare');
|
|
|
|
var concat = require('gulp-concat');
|
|
|
|
var wrap = require("gulp-wrap");
|
|
|
|
var path = require('path');
|
|
|
|
var streamqueue = require('streamqueue');
|
2015-02-14 20:07:59 +02:00
|
|
|
var stripbom = require('gulp-stripbom');
|
2014-08-29 00:40:18 +03:00
|
|
|
|
|
|
|
var paths = require('./paths.js');
|
|
|
|
|
|
|
|
gulp.task('handlebars', function () {
|
|
|
|
|
|
|
|
var coreStream = gulp.src([paths.src.templates, '!*/**/*Partial.*'])
|
2015-02-14 20:07:59 +02:00
|
|
|
.pipe(stripbom({ showLog: false }))
|
2014-08-29 00:40:18 +03:00
|
|
|
.pipe(handlebars())
|
|
|
|
.pipe(declare({
|
|
|
|
namespace: 'T',
|
|
|
|
noRedeclare: true,
|
|
|
|
processName: function (filePath) {
|
|
|
|
|
|
|
|
filePath = path.relative(paths.src.root, filePath);
|
|
|
|
|
|
|
|
return filePath.replace(/\\/g, '/')
|
|
|
|
.toLocaleLowerCase()
|
|
|
|
.replace('template', '')
|
|
|
|
.replace('.js', '');
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
var partialStream = gulp.src([paths.src.partials])
|
2015-02-14 20:07:59 +02:00
|
|
|
.pipe(stripbom({ showLog: false }))
|
2014-08-29 00:40:18 +03:00
|
|
|
.pipe(handlebars())
|
|
|
|
.pipe(wrap('Handlebars.template(<%= contents %>)'))
|
|
|
|
.pipe(wrap('Handlebars.registerPartial(<%= processPartialName(file.relative) %>, <%= contents %>)', {}, {
|
|
|
|
imports: {
|
|
|
|
processPartialName: function (fileName) {
|
|
|
|
return JSON.stringify(
|
|
|
|
path.basename(fileName, '.js')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
return streamqueue({ objectMode: true },
|
|
|
|
partialStream,
|
|
|
|
coreStream
|
|
|
|
).pipe(concat('templates.js'))
|
2015-02-03 03:18:45 +02:00
|
|
|
|
2014-08-29 00:40:18 +03:00
|
|
|
.pipe(gulp.dest(paths.dest.root));
|
|
|
|
});
|