enable cache: parse and render

This commit is contained in:
harttle
2016-06-20 00:34:54 +08:00
parent aa1df95714
commit 54bc206d36
16 changed files with 182 additions and 118 deletions
+38 -22
View File
@@ -1,31 +1,47 @@
const chai = require("chai");
const expect = chai.expect;
var liquid = require('..')(),
ctx;
function test(src, dst) {
ctx = {
date: new Date(),
foo: 'bar',
arr: [-2, 'a'],
obj: {
foo: 'bar'
},
posts: [{
category: 'foo'
}, {
category: 'bar'
}]
};
expect(liquid.render(src, ctx)).to.equal(dst);
}
const should = chai.should;
const Liquid = require('..');
describe('liquid', function() {
var engine, ctx;
beforeEach(function() {
engine = Liquid();
ctx = {
date: new Date(),
foo: 'bar',
arr: [-2, 'a'],
obj: {
foo: 'bar'
},
posts: [{
category: 'foo'
}, {
category: 'bar'
}]
};
});
it('should output object', function() {
test('{{obj}}', '{"foo":"bar"}');
engine.parseAndRender('{{obj}}', ctx).should.equal('{"foo":"bar"}');
});
it('should output array', function() {
test('{{arr}}', '[-2,"a"]');
engine.parseAndRender('{{arr}}', ctx).should.equal('[-2,"a"]');
});
it('should parse html', function() {
(function(){
engine.parse('{{obj}}');
}).should.not.throw();
(function(){
engine.parse('<html><head>{{obj}}</head></html>');
}).should.not.throw();
});
it('should render template multiple times', function() {
var template = engine.parse('{{obj}}');
engine.render(template, ctx).should.equal('{"foo":"bar"}');
engine.render(template, ctx).should.equal('{"foo":"bar"}');
});
it('should render filters', function() {
var template = engine.parse('<p>{{arr | join: "_"}}</p>');
engine.render(template, ctx).should.equal('<p>-2_a</p>');
});
});