mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
feat: exported Drop interface for #107
Deprecate snake_cased options and APIs, sed #109
This commit is contained in:
@@ -19,7 +19,7 @@ describe('filters/array', function () {
|
||||
return test(src, 'tiger')
|
||||
})
|
||||
it('should support map', function () {
|
||||
return test('{{posts | map: "category"}}', '["foo","bar"]')
|
||||
return test('{{posts | map: "category"}}', 'foo,bar')
|
||||
})
|
||||
it('should support reverse', function () {
|
||||
return test('{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}',
|
||||
|
||||
@@ -15,6 +15,6 @@ describe('filters/date', function () {
|
||||
return test('{{ "foo" | date: "%Y"}}', 'foo')
|
||||
})
|
||||
it('should render object as string if not valid', function () {
|
||||
return test('{{ obj | date: "%Y"}}', '{"foo":"bar"}')
|
||||
return test('{{ obj | date: "%Y"}}', '[object Object]')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('tags/assign', function () {
|
||||
it('should assign as array', async function () {
|
||||
const src = '{% assign foo=(1..3) %}{{foo}}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('[1,2,3]')
|
||||
return expect(html).to.equal('1,2,3')
|
||||
})
|
||||
it('should assign as filter result', async function () {
|
||||
const src = '{% assign foo="a b" | capitalize | split: " " | first %}{{foo}}'
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { expect } from 'chai'
|
||||
import Liquid from '../../../src/liquid'
|
||||
|
||||
describe('drop/drop', function () {
|
||||
let liquid: Liquid
|
||||
before(() => (liquid = new Liquid()))
|
||||
|
||||
class CustomDrop extends Liquid.Types.Drop {
|
||||
name: string = 'NAME'
|
||||
getName() {
|
||||
return 'GETNAME'
|
||||
}
|
||||
}
|
||||
class CustomDropWithMethodMissing extends CustomDrop {
|
||||
liquidMethodMissing(key: string) {
|
||||
return key.toUpperCase()
|
||||
}
|
||||
}
|
||||
it('should call corresponding method', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.getName}}`, {obj: new CustomDrop()})
|
||||
expect(html).to.equal('GETNAME')
|
||||
})
|
||||
it('should read corresponding property', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.name}}`, {obj: new CustomDrop()})
|
||||
expect(html).to.equal('NAME')
|
||||
})
|
||||
it('should output empty string if not exist', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.foo}}`, {obj: new CustomDrop()})
|
||||
expect(html).to.equal('')
|
||||
})
|
||||
it('should respect liquidMethodMissing', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.foo}}`, {obj: new CustomDropWithMethodMissing()})
|
||||
expect(html).to.equal('FOO')
|
||||
})
|
||||
})
|
||||
@@ -4,26 +4,26 @@ import Liquid from '../../../src/liquid'
|
||||
describe('LiquidOptions#*_delimiter_*', function () {
|
||||
it('should respect tag_delimiter_*', async function () {
|
||||
const engine = new Liquid({
|
||||
tag_delimiter_left: '<%=',
|
||||
tag_delimiter_right: '%>'
|
||||
tagDelimiterLeft: '<%=',
|
||||
tagDelimiterRight: '%>'
|
||||
})
|
||||
const html = await engine.parseAndRender('<%=if true%>foo<%=endif%> ')
|
||||
return expect(html).to.equal('foo ')
|
||||
})
|
||||
it('should respect output_delimiter_*', async function () {
|
||||
const engine = new Liquid({
|
||||
output_delimiter_left: '<<',
|
||||
output_delimiter_right: '>>'
|
||||
outputDelimiterLeft: '<<',
|
||||
outputDelimiterRight: '>>'
|
||||
})
|
||||
const html = await engine.parseAndRender('<< "liquid" | capitalize >>')
|
||||
return expect(html).to.equal('Liquid')
|
||||
})
|
||||
it('should support trimming with tag_delimiter_* set', async function () {
|
||||
const engine = new Liquid({
|
||||
tag_delimiter_left: '<%=',
|
||||
tag_delimiter_right: '%>',
|
||||
trim_tag_left: true,
|
||||
trim_tag_right: true
|
||||
tagDelimiterLeft: '<%=',
|
||||
tagDelimiterRight: '%>',
|
||||
trimTagLeft: true,
|
||||
trimTagRight: true
|
||||
})
|
||||
const html = await engine.parseAndRender(' <%=if true%> \tfoo\t <%=endif%> ')
|
||||
return expect(html).to.equal('foo')
|
||||
|
||||
@@ -10,22 +10,22 @@ describe('LiquidOptions#strict_*', function () {
|
||||
extname: '.html'
|
||||
})
|
||||
})
|
||||
it('should not throw when strict_variables false (default)', async function () {
|
||||
it('should not throw when strictVariables false (default)', async function () {
|
||||
const html = await engine.parseAndRender('before{{notdefined}}after', ctx)
|
||||
return expect(html).to.equal('beforeafter')
|
||||
})
|
||||
it('should throw when strict_variables true', function () {
|
||||
it('should throw when strictVariables true', function () {
|
||||
const tpl = engine.parse('before{{notdefined}}after')
|
||||
const opts = {
|
||||
strict_variables: true
|
||||
strictVariables: true
|
||||
}
|
||||
return expect(engine.render(tpl, ctx, opts)).to
|
||||
.be.rejectedWith(/undefined variable: notdefined/)
|
||||
})
|
||||
it('should pass strict_variables to render by parseAndRender', function () {
|
||||
it('should pass strictVariables to render by parseAndRender', function () {
|
||||
const html = 'before{{notdefined}}after'
|
||||
const opts = {
|
||||
strict_variables: true
|
||||
strictVariables: true
|
||||
}
|
||||
return expect(engine.parseAndRender(html, ctx, opts)).to
|
||||
.be.rejectedWith(/undefined variable: notdefined/)
|
||||
|
||||
@@ -6,34 +6,34 @@ describe('LiquidOptions#trimming', function () {
|
||||
|
||||
describe('tag trimming', function () {
|
||||
it('should respect trim_tag_left', async function () {
|
||||
const engine = new Liquid({ trim_tag_left: true })
|
||||
const engine = new Liquid({ trim_tag_left: true } as any)
|
||||
const html = await engine.parseAndRender(' \n \t{%if true%}foo{%endif%} ')
|
||||
return expect(html).to.equal('foo ')
|
||||
})
|
||||
it('should respect trim_tag_right', async function () {
|
||||
const engine = new Liquid({ trim_tag_right: true })
|
||||
const engine = new Liquid({ trim_tag_right: true } as any)
|
||||
const html = await engine.parseAndRender('\t{%if true%}foo{%endif%} \n')
|
||||
return expect(html).to.equal('\tfoo')
|
||||
})
|
||||
it('should not trim value', async function () {
|
||||
const engine = new Liquid({ trim_tag_left: true, trim_tag_right: true })
|
||||
const engine = new Liquid({ trim_tag_left: true, trim_tag_right: true } as any)
|
||||
const html = await engine.parseAndRender('{%if true%}a {{name}} b{%endif%}', ctx)
|
||||
return expect(html).to.equal('a harttle b')
|
||||
})
|
||||
})
|
||||
describe('value trimming', function () {
|
||||
it('should respect trim_output_left', async function () {
|
||||
const engine = new Liquid({ trim_output_left: true })
|
||||
const engine = new Liquid({ trim_output_left: true } as any)
|
||||
const html = await engine.parseAndRender(' \n \t{{name}} ', ctx)
|
||||
return expect(html).to.equal('harttle ')
|
||||
})
|
||||
it('should respect trim_output_right', async function () {
|
||||
const engine = new Liquid({ trim_output_right: true })
|
||||
const engine = new Liquid({ trim_output_right: true } as any)
|
||||
const html = await engine.parseAndRender(' \n \t{{name}} ', ctx)
|
||||
return expect(html).to.equal(' \n \tharttle')
|
||||
})
|
||||
it('should respect not trim tag', async function () {
|
||||
const engine = new Liquid({ trim_output_left: true, trim_output_right: true })
|
||||
const engine = new Liquid({ trim_output_left: true, trim_output_right: true } as any)
|
||||
const html = await engine.parseAndRender('\t{% if true %} aha {%endif%}\t')
|
||||
return expect(html).to.equal('\t aha \t')
|
||||
})
|
||||
@@ -46,7 +46,7 @@ describe('LiquidOptions#trimming', function () {
|
||||
return expect(html).to.equal('aharttle')
|
||||
})
|
||||
it('should respect to greedy:false by default', async function () {
|
||||
const engine = new Liquid({ greedy: false })
|
||||
const engine = new Liquid({ greedy: false } as any)
|
||||
const html = await engine.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal('\n a \nharttle ')
|
||||
})
|
||||
|
||||
@@ -5,8 +5,8 @@ import { mock, restore } from '../../stub/mockfs'
|
||||
|
||||
let engine = new Liquid()
|
||||
const strictEngine = new Liquid({
|
||||
strict_variables: true,
|
||||
strict_filters: true
|
||||
strictVariables: true,
|
||||
strictFilters: true
|
||||
})
|
||||
|
||||
describe('error', function () {
|
||||
|
||||
Reference in New Issue
Block a user