xtemplate / xtpl

nodejs wrapper around xtemplate engine (easier for expressjs and koajs)
MIT License
100 stars 25 forks source link

support koa #5

Closed yiminghe closed 10 years ago

yiminghe commented 10 years ago
var xtplKoa = require('xtpl/lib/koa');
var path = require('path');
var app = xtplKoa(require('koa')(), {
    views: path.resolve(__dirname, '../fixture/')
});
app.use(function *() {
    var html = yield* this.render('main', {
        y: '<',
        x: '>'
    });
    expect(html).to.equal('<&gt;');
});
app.listen(9000);
var request = require('request');
setTimeout(function () {
    request({url: 'http://localhost:9000'}, function (error, response, body) {
        expect(body).to.equal('<&gt;');
        done();
    });
}, 100);
imsobear commented 9 years ago

@yiminghe

感觉现在这种语法稍微有点奇怪,而且不能统一配置 layoutpartials 的位置,想象中的调用方法应该是下面这样的:

var xtpl = require('xtpl/koa');

var app = koa();

app.use(xtpl({
  views: __dirname + '/view',
  partials: __dirname + '/view/partials',
  layout: __dirname + '/view/layout'
}));

这样更符合中间件的思路,并且不用每次都去声明 {{extend ("./layout")}}, 恩,个人的一点建议~

yiminghe commented 9 years ago

@dead-horse 怎么看,我觉得不需要制配置partial layout,模版就是和模块一样,extend include 指定路径的模版即可

dead-horse commented 9 years ago

嗯,模版中自己 extend 自己想要的 layout 好了,现在的中间件使用模式也符合 koa 的一类中间件用法,并且性能更高。