Skip to content

Instantly share code, notes, and snippets.

@gipp
Last active August 29, 2015 14:25
Show Gist options
  • Save gipp/5821794acd9cd0c85dbb to your computer and use it in GitHub Desktop.
Save gipp/5821794acd9cd0c85dbb to your computer and use it in GitHub Desktop.
var fs = require('fs');
var gulp = require('gulp');
var Handlebars = require('handlebars');
var globby = require('globby');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
// var transform = require('vinyl-transform');
var through = require('through2');
function registerPartials() {
// register all the partials
globby(['_partials/*.hbs'], function(error, partials) {
partials.forEach(function(path, i) {
Handlebars.registerPartial(path.split('_partials/')[1].split('.hbs')[0], fs.readFileSync(path).toString());
});
});
}
gulp.task('build', function() {
registerPartials();
var handlebars = through.obj(function (file, encoding, next) {
// STEP 1: get the 'template'
var compiled = Handlebars.compile(file.contents.toString())({
title: 'HECK',
body: 'YEAH'
});
file.contents = new Buffer(compiled);
this.push(file);
next(null);
});
gulp.src(['**/*.html', '!_build/**/*.html', '!node_modules/**/*.html'])
.pipe(handlebars)
.pipe(gulp.dest('_build/'));
// globby(['**/*.html', '!_build/**/*.html'], function(error, pages) {
// pages.forEach(function(path, i) {
// var rendered = Handlebars.compile(fs.readFileSync(path).toString())({
// title: 'HECK',
// body: 'YEAH'
// });
//
// // TODO: write file into _build/$PATH
// fs.writeFileSync('_build/' + path, rendered);
//
// });
// });
// fs.readFile('index.html', function(error, data) {
// var rendered = Handlebars.compile(data.toString())({
// title: 'HECK',
// body: 'YEAH'
// });
// // console.log(rendered);
// });
// return stream;
});
gulp.task('default', ['build']);
// gulp.task('default', function() {
//
//
//
// // through()
// // .pipe(function() {
// // fs.readFile('_templates/one.hbs', function(error, data) {
// // Handlebars.registerPartial('one', data.toString());
// // });
// // })
//
//
// // globby(['_templates/*.hbs'], function(error, entries) {
// // entries.forEach(function(e, i) {
// //
// // fs.readFile(e, function(error, data) {
// // var rendered = Handlebars.compile(data.toString())({
// // title: 'HECK',
// // body: 'YEAH'
// // });
// // console.log(rendered);
// // });
// //
// // });
// // });
//
//
//
// // console.log(gulp.src(['_templates/*.hbs']));
// // return gulp.src('_templates/*.hbs')
// // .pipe(source);
//
// // var t = transform(function(filename) {
// // console.log(fs.readFile(filename));
// // });
// //
// // gulp.src(['_templates/*.hbs'])
// // .pipe(t);
//
// // .pipe(function() {
// // console.log(arguments);
// // });
//
//
//
// //Handlebars.registerPartial('one', '{{name}}')
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment