var gulp = require('gulp'),
watch = require('gulp-watch'),
sass = require('gulp-ruby-sass'),
- html2txt = require('gulp-html2txt'),
inlineCss = require('gulp-inline-css'),
rename = require('gulp-rename'),
connect = require('gulp-connect'),
minifyHTML = require('gulp-minify-html'),
- concat = require('gulp-concat'),
extractMQ = require('media-query-extractor'),
inject = require('gulp-inject'),
inkyGulp = require('gulp-inky'),
handlebars = require('gulp-compile-handlebars'),
omglob = require('glob'),
+ gSync = require('gulp-sync')(gulp),
runOrder = require('run-sequence'),
rimraf = require('rimraf');
// Inject handlebars partials
gulp.task('compile-html', function() {
-
- omglob(dirs.src + '/pages/*.handlebars', function(er, files) {
-
- for (var i = 0; i < files.length; i++) {
- var filePath = files[i].replace(/\\/g, '/');
- var fileName = filePath.substring(filePath.lastIndexOf('/')+1, filePath.lastIndexOf('.'));
-
- var templateData = {},
- options = {
- batch : ['./src/partials']
- };
-
- gulp.src(files[i])
- .pipe(handlebars(templateData, options))
- .pipe(rename(fileName + '.html'))
- .pipe(gulp.dest(dirs.temp));
- }
- })
-
// silly gulp asynch. The previous task sometimes happens too fast, so it can't find
// the new temporary partials
- setTimeout(function() {
+ var injectHtml = function() {
omglob(dirs.temp + '/*.html', function(er, files) {
for (var i = 0; i < files.length; i++) {
var filePath = files[i].replace(/\\/g, '/');
var fileName = filePath.substring(filePath.lastIndexOf('/')+1, filePath.lastIndexOf('.'));
- gulp.src(dirs.src + '/layouts/default.html')
+ gulp.src(dirs.src + '/layouts/default.html')
.pipe(inject(gulp.src(files[i]), {
starttag: '<!-- inject:page:{{ext}} -->',
transform: function (filePath, file) {
.pipe(gulp.dest(dirs.temp))
}
})
- }, 100);
+ };
+
+ omglob(dirs.src + '/pages/*.handlebars', function(er, files) {
+
+ for (var i = 0; i < files.length; i++) {
+ var filePath = files[i].replace(/\\/g, '/');
+ var fileName = filePath.substring(filePath.lastIndexOf('/')+1, filePath.lastIndexOf('.'));
+
+ var templateData = {},
+ options = {
+ batch : ['./src/partials']
+ };
+
+ gulp.src(files[i])
+ .pipe(handlebars(templateData, options))
+ .pipe(rename(fileName + '.html'))
+ .pipe(gulp.dest(dirs.temp));
+ }
+
+ injectHtml();
+ })
+
});
+
// 6. Syntax Transformer
// - - - - - - - - - - - - - - -
// get the HTML from the body and run it through Inky parser
-gulp.task('query', ['compile-html'], function() {
+gulp.task('query', function() {
gulp.src(dirs.temp + '/*.html')
.pipe(inkyGulp())
.pipe(gulp.dest(dirs.dist))
// - - - - - - - - - - - - - - -
// Eventual Litmus/Mailgun integration
-gulp.task('test', function () {
+// gulp.task('test', function () {
-});
+// });
// 8. GO FORTH AND BUILD
// - - - - - - - - - - - - - - -
// Watch all HTML files and SCSS files for changes
// Live reloads on change
gulp.task('watch', ['serve'], function() {
- gulp.watch([dirs.src + '/*/*.*'], function(event) {
- runOrder('query', 'minify-html');
- });
+ gulp.watch([dirs.src + '/*/*.*'], ['compile-html']);
gulp.watch([dirs.styles], ['sass']);
- // watch([dirs.dist + '/*.*']).pipe(connect.reload());
- gulp.watch([dirs.dist + '/*.*'], function(event) {
- gulp.src(event.path)
- .pipe(connect.reload());
- })
});