mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
enable cache: parse and render
This commit is contained in:
+38
-22
@@ -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>');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user