2019-09-02 14:18:27 +03:00
|
|
|
const should = require('should');
|
2021-10-06 12:52:46 +03:00
|
|
|
const raw = require('../../../../core/frontend/helpers/raw');
|
|
|
|
const handlebars = require('../../../../core/frontend/services/theme-engine/engine').handlebars;
|
2019-09-02 14:18:27 +03:00
|
|
|
|
|
|
|
let defaultGlobals;
|
|
|
|
|
|
|
|
function compile(templateString) {
|
|
|
|
const template = handlebars.compile(templateString);
|
|
|
|
template.with = (locals = {}, globals) => {
|
|
|
|
globals = globals || defaultGlobals;
|
|
|
|
|
|
|
|
return template(locals, globals);
|
|
|
|
};
|
|
|
|
|
|
|
|
return template;
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('{{raw}} helper', function () {
|
|
|
|
before(function () {
|
2021-10-04 18:30:54 +03:00
|
|
|
handlebars.registerHelper('raw', raw);
|
2019-09-02 14:18:27 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can correctly compile space', function () {
|
|
|
|
compile('{{{{raw}}}} {{{{/raw}}}}')
|
|
|
|
.with({})
|
|
|
|
.should.eql(' ');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can correctly ignore handlebars', function () {
|
|
|
|
compile('{{{{raw}}}}{{test}}{{{{/raw}}}}')
|
|
|
|
.with({tag: {}})
|
|
|
|
.should.eql('{{test}}');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can correctly compile recursive', function () {
|
|
|
|
compile('{{{{raw}}}}{{{{raw}}}}{{{{/raw}}}}{{{{/raw}}}}')
|
|
|
|
.with({tag: {}})
|
|
|
|
.should.eql('{{{{raw}}}}{{{{/raw}}}}');
|
|
|
|
});
|
|
|
|
});
|