bminer / node-blade

Blade - HTML Template Compiler, inspired by Jade & Haml
Other
320 stars 28 forks source link

support in hapijs #205

Closed rutaihwa closed 9 years ago

rutaihwa commented 9 years ago

I would like to give blade a try, but it does not seem to get work with hapijs. When i try to get views to read a .blade template I get the strange error 500. Is it me or its not supported by hapi?

bminer commented 9 years ago

@rutaihwa - Blade will certainly work with hapijs, but it might not work out of the box. From what I've read here, you will need to specify Blade as your view engine explicitly.

Something like this might work:

server.views({
    engines: {
        'blade': {
            module: require('blade'),
            compileMode: 'async' // engine specific
        }
    }
});

Problem is... this might not work since the compiled template returned is of the form tmpl(context, cb) not what hapijs expects tmpl(context, options, cb). Therefore, you might need to do something tricky like this...

server.views({
    engines: {
        'blade': {
            module: {
                "compile": function(template, options, cb) {
                    require("blade").compile(template, options, function(err, tmpl) {
                        cb(err, function(context, options, cb) {
                            tmpl(context, cb);
                        });
                    });
                }
            },
            compileMode: 'async' // engine specific
        }
    }
});

I dunno... give it a shot and let me know if you have any issues. Closing this issue for now.