shannonmoeller / gulp-hb

A sane Gulp plugin to compile Handlebars templates. Useful as a static site generator.

Home Page:http://npm.im/gulp-hb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Will this plugin, can I do the following ?

Avcajaraville opened this issue · comments

So, I have a node app.

I have some static pages, they only uses translations (i18n module), and nothing more.

There are no objects needed for this. The pages includes handlebars partials, layouts, etc (with .html extension).

The templates structure is something like this:

views
|-> layouts (folder with layouts)
|-> partials (folder with partials)
|-> pag1.html
|-> pag2.html

What I would like to do is a gulp plugin that generates those pages in all the languages we have.

The languages are in json files

This is a client request, who wants to serve the content as static pages.

Will this be possible with this plugin ?

You can do this, yes. You'd need to setup a gulp task that reads the language .json files then feed those into gulp-hb. Something like this:

var gulp = require('gulp');
var hb = require('gulp-hb');
var through = require('through2');

gulp.task('build', function() {
    return gulp
        .src('path/to/i18n/*.json')
        .pipe(through.obj(function(file, enc, done) {
            gulp
                .src('path/to/pages/*.html')
                .pipe(hb({
                    data: { i18n: JSON.parse(String(file.contents)) },
                    helpers: 'path/to/helpers/**/*.js',
                    partials: 'path/to/partials/**/*.hbs'
                }))
                .pipe(gulp.dest(path.join('path/to/output', file.stem)))
                .on('end', done);
        }));
});

This is untested code, so your milage may vary, but the principle is there. You start with your .json files, then one by one you build out separate copies of the site. I hope this helps!