mirror of
https://github.com/harttle/liquidjs.git
synced 2026-10-03 00:55:13 -07:00
style: fix code style
This commit is contained in:
@@ -2,7 +2,7 @@ import { isComparable } from '../drop/comparable'
|
|||||||
import { Context } from '../context'
|
import { Context } from '../context'
|
||||||
import { isFunction, toValue } from '../util'
|
import { isFunction, toValue } from '../util'
|
||||||
import { isFalsy, isTruthy } from '../render/boolean'
|
import { isFalsy, isTruthy } from '../render/boolean'
|
||||||
import { isArray } from '../util/underscore';
|
import { isArray } from '../util/underscore'
|
||||||
|
|
||||||
export type UnaryOperatorHandler = (operand: any, ctx: Context) => boolean;
|
export type UnaryOperatorHandler = (operand: any, ctx: Context) => boolean;
|
||||||
export type BinaryOperatorHandler = (lhs: any, rhs: any, ctx: Context) => boolean;
|
export type BinaryOperatorHandler = (lhs: any, rhs: any, ctx: Context) => boolean;
|
||||||
@@ -42,7 +42,7 @@ export const defaultOperators: Operators = {
|
|||||||
'or': (l: any, r: any, ctx: Context) => isTruthy(toValue(l), ctx) || isTruthy(toValue(r), ctx)
|
'or': (l: any, r: any, ctx: Context) => isTruthy(toValue(l), ctx) || isTruthy(toValue(r), ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
function equal(lhs: any, rhs: any): boolean {
|
function equal (lhs: any, rhs: any): boolean {
|
||||||
if (isComparable(lhs)) return lhs.equals(rhs)
|
if (isComparable(lhs)) return lhs.equals(rhs)
|
||||||
if (isComparable(rhs)) return rhs.equals(lhs)
|
if (isComparable(rhs)) return rhs.equals(lhs)
|
||||||
lhs = toValue(lhs)
|
lhs = toValue(lhs)
|
||||||
@@ -53,7 +53,7 @@ function equal(lhs: any, rhs: any): boolean {
|
|||||||
return lhs === rhs
|
return lhs === rhs
|
||||||
}
|
}
|
||||||
|
|
||||||
function arrayEqual(lhs: any[], rhs: any[]): boolean {
|
function arrayEqual (lhs: any[], rhs: any[]): boolean {
|
||||||
if (lhs.length !== rhs.length) return false
|
if (lhs.length !== rhs.length) return false
|
||||||
return !lhs.some((value, i) => !equal(value, rhs[i]))
|
return !lhs.some((value, i) => !equal(value, rhs[i]))
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -390,7 +390,7 @@ describe('Issues', function () {
|
|||||||
const html = await liquid.parseAndRender(tpl, ctx)
|
const html = await liquid.parseAndRender(tpl, ctx)
|
||||||
expect(html.trim()).to.equal('<a href="https://example.com">Lot more code here</a>')
|
expect(html.trim()).to.equal('<a href="https://example.com">Lot more code here</a>')
|
||||||
})
|
})
|
||||||
it('#70 strip multiline content of <style>', async() => {
|
it('#70 strip multiline content of <style>', async () => {
|
||||||
const str = `
|
const str = `
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
.test-one-line {display: none;}
|
.test-one-line {display: none;}
|
||||||
@@ -400,13 +400,13 @@ describe('Issues', function () {
|
|||||||
const html = await engine.parseAndRender(template, { str })
|
const html = await engine.parseAndRender(template, { str })
|
||||||
expect(html).to.match(/^\s*$/)
|
expect(html).to.match(/^\s*$/)
|
||||||
})
|
})
|
||||||
it('#589 Arrays should compare values', async() => {
|
it('#589 Arrays should compare values', async () => {
|
||||||
const engine = new Liquid()
|
const engine = new Liquid()
|
||||||
const template = `
|
const template = `
|
||||||
{% assign people1 = "alice, bob, carol" | split: ", " -%}
|
{% assign people1 = "alice, bob, carol" | split: ", " -%}
|
||||||
{% assign people2 = "alice, bob, carol" | split: ", " -%}
|
{% assign people2 = "alice, bob, carol" | split: ", " -%}
|
||||||
{% if people1 == people2 %}true{%else%}false{% endif %}
|
{% if people1 == people2 %}true{%else%}false{% endif %}
|
||||||
`;
|
`
|
||||||
const html = await engine.parseAndRender(template)
|
const html = await engine.parseAndRender(template)
|
||||||
expect(html).to.contain('true')
|
expect(html).to.contain('true')
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import { Liquid } from '../../../src/liquid'
|
|||||||
|
|
||||||
describe('filters/html', function () {
|
describe('filters/html', function () {
|
||||||
let liquid: Liquid
|
let liquid: Liquid
|
||||||
beforeEach(() => liquid = new Liquid())
|
beforeEach(() => {
|
||||||
|
liquid = new Liquid()
|
||||||
|
})
|
||||||
describe('escape', function () {
|
describe('escape', function () {
|
||||||
it('should escape \' and &', function () {
|
it('should escape \' and &', function () {
|
||||||
return test('{{ "Have you read \'James & the Giant Peach\'?" | escape }}',
|
return test('{{ "Have you read \'James & the Giant Peach\'?" | escape }}',
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ describe('Expression', function () {
|
|||||||
const ctx = new Context({
|
const ctx = new Context({
|
||||||
arr1: [1, 2],
|
arr1: [1, 2],
|
||||||
arr2: [1, 2],
|
arr2: [1, 2],
|
||||||
arr3: [1, 2, 3],
|
arr3: [1, 2, 3]
|
||||||
})
|
})
|
||||||
expect(await toPromise(create('arr1==arr2').evaluate(ctx, false))).to.equal(true)
|
expect(await toPromise(create('arr1==arr2').evaluate(ctx, false))).to.equal(true)
|
||||||
expect(await toPromise(create('arr1==arr3').evaluate(ctx, false))).to.equal(false)
|
expect(await toPromise(create('arr1==arr3').evaluate(ctx, false))).to.equal(false)
|
||||||
|
|||||||
Reference in New Issue
Block a user