mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
chore(TypeScript): ship Liquid to class
BREAKING CHANGE: calling `Liquid()` without `new` now becomes invalid
This commit is contained in:
@@ -9,7 +9,7 @@ chai.use(chaiAsPromised)
|
||||
describe('cache options', function () {
|
||||
let engine
|
||||
beforeEach(function () {
|
||||
engine = Liquid({
|
||||
engine = new Liquid({
|
||||
root: '/root/',
|
||||
extname: '.html'
|
||||
})
|
||||
@@ -28,7 +28,7 @@ describe('cache options', function () {
|
||||
.then(x => expect(x).to.equal('bar'))
|
||||
})
|
||||
it('should respect cache=true option', function () {
|
||||
engine = Liquid({
|
||||
engine = new Liquid({
|
||||
root: '/root/',
|
||||
extname: '.html',
|
||||
cache: true
|
||||
|
||||
@@ -8,7 +8,7 @@ describe('strict options', function () {
|
||||
let engine
|
||||
const ctx = {}
|
||||
beforeEach(function () {
|
||||
engine = Liquid({
|
||||
engine = new Liquid({
|
||||
root: '/root/',
|
||||
extname: '.html'
|
||||
})
|
||||
|
||||
@@ -10,34 +10,34 @@ describe('trimming', function () {
|
||||
|
||||
describe('tag trimming', function () {
|
||||
it('should respect trim_tag_left', function () {
|
||||
const engine = Liquid({ trim_tag_left: true })
|
||||
const engine = new Liquid({ trim_tag_left: true })
|
||||
return expect(engine.parseAndRender(' \n \t{%if true%}foo{%endif%} '))
|
||||
.to.eventually.equal('foo ')
|
||||
})
|
||||
it('should respect trim_tag_right', function () {
|
||||
const engine = Liquid({ trim_tag_right: true })
|
||||
const engine = new Liquid({ trim_tag_right: true })
|
||||
return expect(engine.parseAndRender('\t{%if true%}foo{%endif%} \n'))
|
||||
.to.eventually.equal('\tfoo')
|
||||
})
|
||||
it('should not trim value', function () {
|
||||
const engine = Liquid({ trim_tag_left: true, trim_tag_right: true })
|
||||
const engine = new Liquid({ trim_tag_left: true, trim_tag_right: true })
|
||||
return expect(engine.parseAndRender('{%if true%}a {{name}} b{%endif%}', ctx))
|
||||
.to.eventually.equal('a harttle b')
|
||||
})
|
||||
})
|
||||
describe('value trimming', function () {
|
||||
it('should respect trim_value_left', function () {
|
||||
const engine = Liquid({ trim_value_left: true })
|
||||
const engine = new Liquid({ trim_value_left: true })
|
||||
return expect(engine.parseAndRender(' \n \t{{name}} ', ctx))
|
||||
.to.eventually.equal('harttle ')
|
||||
})
|
||||
it('should respect trim_value_right', function () {
|
||||
const engine = Liquid({ trim_value_right: true })
|
||||
const engine = new Liquid({ trim_value_right: true })
|
||||
return expect(engine.parseAndRender(' \n \t{{name}} ', ctx))
|
||||
.to.eventually.equal(' \n \tharttle')
|
||||
})
|
||||
it('should respect not trim tag', function () {
|
||||
const engine = Liquid({ trim_value_left: true, trim_value_right: true })
|
||||
const engine = new Liquid({ trim_value_left: true, trim_value_right: true })
|
||||
return expect(engine.parseAndRender('\t{% if true %} aha {%endif%}\t'))
|
||||
.to.eventually.equal('\t aha \t')
|
||||
})
|
||||
@@ -45,19 +45,19 @@ describe('trimming', function () {
|
||||
describe('greedy', function () {
|
||||
const src = '\n {%-if true-%}\n a \n{{-name-}}{%-endif-%}\n '
|
||||
it('should enable greedy by default', function () {
|
||||
const engine = Liquid()
|
||||
const engine = new Liquid()
|
||||
return expect(engine.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('aharttle')
|
||||
})
|
||||
it('should respect to greedy:false by default', function () {
|
||||
const engine = Liquid({ greedy: false })
|
||||
const engine = new Liquid({ greedy: false })
|
||||
return expect(engine.parseAndRender(src, ctx))
|
||||
.to.eventually.equal('\n a \nharttle ')
|
||||
})
|
||||
})
|
||||
describe('markup', function () {
|
||||
it('should support trim using markup', function () {
|
||||
const engine = Liquid()
|
||||
const engine = new Liquid()
|
||||
const src = [
|
||||
'{%- assign username = "John G. Chalmers-Smith" -%}',
|
||||
'{%- if username and username.length > 10 -%}',
|
||||
@@ -70,7 +70,7 @@ describe('trimming', function () {
|
||||
return expect(engine.parseAndRender(src)).to.eventually.equal(dst)
|
||||
})
|
||||
it('should not trim when not specified', function () {
|
||||
const engine = Liquid()
|
||||
const engine = new Liquid()
|
||||
const src = [
|
||||
'{% assign username = "John G. Chalmers-Smith" %}',
|
||||
'{% if username and username.length > 10 %}',
|
||||
|
||||
@@ -6,7 +6,7 @@ chai.use(sinonChai)
|
||||
const expect = chai.expect
|
||||
|
||||
describe('tags/assign', function () {
|
||||
const liquid = Liquid()
|
||||
const liquid = new Liquid()
|
||||
it('should throw when variable expression illegal', function () {
|
||||
const src = '{% assign / %}'
|
||||
const ctx = {}
|
||||
|
||||
@@ -5,7 +5,7 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/capture', function () {
|
||||
const liquid = Liquid()
|
||||
const liquid = new Liquid()
|
||||
|
||||
it('should support capture', function () {
|
||||
const src = '{% capture f %}{{"a" | capitalize}}{%endcapture%}{{f}}'
|
||||
|
||||
@@ -5,7 +5,7 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/case', function () {
|
||||
const liquid = Liquid()
|
||||
const liquid = new Liquid()
|
||||
|
||||
it('should reject if not closed', function () {
|
||||
const src = '{% case "foo"%}'
|
||||
|
||||
@@ -5,7 +5,7 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/comment', function () {
|
||||
const liquid = Liquid()
|
||||
const liquid = new Liquid()
|
||||
it('should support empty content', function () {
|
||||
const src = '{% comment %}{% raw%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
|
||||
@@ -5,7 +5,7 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/cycle', function () {
|
||||
const liquid = Liquid()
|
||||
const liquid = new Liquid()
|
||||
|
||||
it('should support cycle', function () {
|
||||
const src = "{% cycle '1', '2', '3' %}"
|
||||
|
||||
@@ -5,7 +5,7 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/decrement', function () {
|
||||
const liquid = Liquid()
|
||||
const liquid = new Liquid()
|
||||
it('should throw when variable expression illegal', function () {
|
||||
const src = '{% decrement / %}{{var}}'
|
||||
const ctx = {}
|
||||
|
||||
@@ -7,7 +7,7 @@ chai.use(require('chai-as-promised'))
|
||||
describe('tags/for', function () {
|
||||
let liquid, ctx
|
||||
before(function () {
|
||||
liquid = Liquid()
|
||||
liquid = new Liquid()
|
||||
liquid.registerTag('throwingTag', {
|
||||
render: function () { throw new Error('intended render error') }
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/if', function () {
|
||||
const liquid = Liquid()
|
||||
const liquid = new Liquid()
|
||||
const ctx = {
|
||||
one: 1,
|
||||
two: 2,
|
||||
|
||||
@@ -8,7 +8,7 @@ chai.use(require('chai-as-promised'))
|
||||
describe('tags/include', function () {
|
||||
let liquid
|
||||
before(function () {
|
||||
liquid = Liquid({
|
||||
liquid = new Liquid({
|
||||
root: '/',
|
||||
extname: '.html'
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/increment', function () {
|
||||
const liquid = Liquid()
|
||||
const liquid = new Liquid()
|
||||
|
||||
it('should increment undefined variable', function () {
|
||||
const src = '{% increment one %}{% increment one %}{% increment one %}'
|
||||
|
||||
@@ -8,7 +8,7 @@ chai.use(require('chai-as-promised'))
|
||||
describe('tags/layout', function () {
|
||||
let liquid
|
||||
before(function () {
|
||||
liquid = Liquid({
|
||||
liquid = new Liquid({
|
||||
root: '/',
|
||||
extname: '.html'
|
||||
})
|
||||
@@ -113,7 +113,7 @@ describe('tags/layout', function () {
|
||||
'/parent.html': '{{color}}{%block%}{%endblock%}',
|
||||
'/main.html': '{% layout parent.html color:"black"%}{%block%}A{%endblock%}'
|
||||
})
|
||||
const staticLiquid = Liquid({ root: '/', dynamicPartials: false })
|
||||
const staticLiquid = new Liquid({ root: '/', dynamicPartials: false })
|
||||
return expect(staticLiquid.renderFile('/main.html')).to
|
||||
.eventually.equal('blackA')
|
||||
})
|
||||
@@ -123,7 +123,7 @@ describe('tags/layout', function () {
|
||||
'/foo/parent.html': '{{color}}{%block%}{%endblock%}',
|
||||
'/main.html': '{% layout bar/../foo/parent.html color:"black"%}{%block%}A{%endblock%}'
|
||||
})
|
||||
const staticLiquid = Liquid({ root: '/', dynamicPartials: false })
|
||||
const staticLiquid = new Liquid({ root: '/', dynamicPartials: false })
|
||||
return expect(staticLiquid.renderFile('/main.html')).to
|
||||
.eventually.equal('blackA')
|
||||
})
|
||||
@@ -133,7 +133,7 @@ describe('tags/layout', function () {
|
||||
'/foo/parent.html': '{{color}}{%block%}{%endblock%}',
|
||||
'/main.html': '{% layout foo/parent.html color:"black"%}{%block%}A{%endblock%}'
|
||||
})
|
||||
const staticLiquid = Liquid({ root: '/', dynamicPartials: false })
|
||||
const staticLiquid = new Liquid({ root: '/', dynamicPartials: false })
|
||||
return expect(staticLiquid.renderFile('/main.html')).to
|
||||
.eventually.equal('blackA')
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/raw', function () {
|
||||
const liquid = Liquid()
|
||||
const liquid = new Liquid()
|
||||
it('should support raw 1', async function () {
|
||||
const p = liquid.parseAndRender('{% raw%}')
|
||||
return expect(p).be.rejectedWith(/{% raw%} not closed/)
|
||||
|
||||
@@ -5,7 +5,7 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/tablerow', function () {
|
||||
const liquid = Liquid()
|
||||
const liquid = new Liquid()
|
||||
|
||||
it('should support tablerow', function () {
|
||||
const src = '{% tablerow i in (1..3)%}{{ i }}{% endtablerow %}'
|
||||
|
||||
@@ -5,7 +5,7 @@ const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/unless', function () {
|
||||
const liquid = Liquid()
|
||||
const liquid = new Liquid()
|
||||
|
||||
it('should render else when predicate yields true', function () {
|
||||
// 0 is truthy
|
||||
|
||||
@@ -6,8 +6,8 @@ import * as path from 'path'
|
||||
const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
let engine = Liquid()
|
||||
const strictEngine = Liquid({
|
||||
let engine = new Liquid()
|
||||
const strictEngine = new Liquid({
|
||||
strict_variables: true,
|
||||
strict_filters: true
|
||||
})
|
||||
@@ -76,7 +76,7 @@ describe('error', function () {
|
||||
|
||||
describe('RenderError', function () {
|
||||
beforeEach(function () {
|
||||
engine = Liquid({
|
||||
engine = new Liquid({
|
||||
root: '/'
|
||||
})
|
||||
engine.registerTag('throwingTag', {
|
||||
@@ -217,7 +217,7 @@ describe('error', function () {
|
||||
|
||||
describe('ParseError', function () {
|
||||
beforeEach(function () {
|
||||
engine = Liquid()
|
||||
engine = new Liquid()
|
||||
engine.registerTag('throwsOnParse', {
|
||||
parse: function () {
|
||||
throw new Error('intended parse error')
|
||||
|
||||
Reference in New Issue
Block a user