This commit is contained in:
harttle
2019-01-28 18:06:47 +08:00
parent 7a2e036c79
commit 8a881ac69a
41 changed files with 116 additions and 116 deletions
+3 -3
View File
@@ -1,11 +1,11 @@
import shim from 'rollup-plugin-shim'
import alias from 'rollup-plugin-alias'
import babel from 'rollup-plugin-babel'
import {uglify} from 'rollup-plugin-uglify'
import { uglify } from 'rollup-plugin-uglify'
import pkg from './package.json'
import nodeResolve from 'rollup-plugin-node-resolve'
const fake = {fs: `export default {}`, path: `export default {}`}
const fake = { fs: `export default {}`, path: `export default {}` }
const version = process.env.VERSION || pkg.version
const sourcemap = true
const banner = `/*
@@ -20,7 +20,7 @@ const input = 'src/index.js'
const babelConf = {
babelrc: false,
'presets': [['env', {'modules': false}]],
'presets': [['env', { 'modules': false }]],
'plugins': ['external-helpers']
}
+2 -2
View File
@@ -1,7 +1,7 @@
import * as lexical from './lexical.js'
import {evalValue} from './syntax.js'
import { evalValue } from './syntax.js'
import assert from './util/assert.js'
import {assign, create} from './util/underscore.js'
import { assign, create } from './util/underscore.js'
const valueRE = new RegExp(`${lexical.value.source}`, 'g')
+1 -1
View File
@@ -1,6 +1,6 @@
import strftime from './util/strftime.js'
import * as _ from './util/underscore.js'
import {isTruthy} from './syntax.js'
import { isTruthy } from './syntax.js'
const escapeMap = {
'&': '&',
+2 -2
View File
@@ -8,8 +8,8 @@ import Render from './render.js'
import Tag from './tag.js'
import Filter from './filter.js'
import Parser from './parser'
import {isTruthy, isFalsy, evalExp, evalValue} from './syntax.js'
import {ParseError, TokenizationError, RenderBreakError, AssertionError} from './util/error.js'
import { isTruthy, isFalsy, evalExp, evalValue } from './syntax.js'
import { ParseError, TokenizationError, RenderBreakError, AssertionError } from './util/error.js'
import tags from './tags/index.js'
import filters from './filters.js'
+2 -2
View File
@@ -1,6 +1,6 @@
import * as lexical from './lexical.js'
import {create} from './util/underscore.js'
import {ParseError} from './util/error.js'
import { create } from './util/underscore.js'
import { ParseError } from './util/error.js'
import assert from './util/assert.js'
export default function (Tag, Filter) {
+3 -3
View File
@@ -1,6 +1,6 @@
import {evalExp} from './syntax.js'
import {RenderBreakError, RenderError} from './util/error.js'
import {stringify, create} from './util/underscore.js'
import { evalExp } from './syntax.js'
import { RenderBreakError, RenderError } from './util/error.js'
import { stringify, create } from './util/underscore.js'
import assert from './util/assert.js'
const render = {
+3 -3
View File
@@ -1,6 +1,6 @@
import {hashCapture} from './lexical.js'
import {create} from './util/underscore.js'
import {evalValue} from './syntax.js'
import { hashCapture } from './lexical.js'
import { create } from './util/underscore.js'
import { evalValue } from './syntax.js'
import assert from './util/assert.js'
function hash (markup, scope) {
+3 -3
View File
@@ -1,10 +1,10 @@
import assert from '../util/assert.js'
import {identifier} from '../lexical.js'
import {create} from '../util/underscore.js'
import { identifier } from '../lexical.js'
import { create } from '../util/underscore.js'
export default function (liquid, Liquid) {
const re = new RegExp(`(${identifier.source})\\s*=([^]*)`)
const {AssignScope} = Liquid.Types
const { AssignScope } = Liquid.Types
liquid.registerTag('assign', {
parse: function (token) {
+3 -3
View File
@@ -1,10 +1,10 @@
import assert from '../util/assert.js'
import {create} from '../util/underscore.js'
import {identifier} from '../lexical.js'
import { create } from '../util/underscore.js'
import { identifier } from '../lexical.js'
export default function (liquid, Liquid) {
const re = new RegExp(`(${identifier.source})`)
const {CaptureScope} = Liquid.Types
const { CaptureScope } = Liquid.Types
liquid.registerTag('capture', {
parse: function (tagToken, remainTokens) {
+1 -1
View File
@@ -1,5 +1,5 @@
import assert from '../util/assert.js'
import {value as rValue} from '../lexical.js'
import { value as rValue } from '../lexical.js'
export default function (liquid, Liquid) {
const groupRE = new RegExp(`^(?:(${rValue.source})\\s*:\\s*)?(.*)$`)
+3 -3
View File
@@ -1,9 +1,9 @@
import {create} from '../util/underscore.js'
import { create } from '../util/underscore.js'
import assert from '../util/assert.js'
import {identifier} from '../lexical.js'
import { identifier } from '../lexical.js'
export default function (liquid, Liquid) {
const {CaptureScope, AssignScope, DecrementScope} = Liquid.Types
const { CaptureScope, AssignScope, DecrementScope } = Liquid.Types
liquid.registerTag('decrement', {
parse: function (token) {
+4 -4
View File
@@ -1,7 +1,7 @@
import {mapSeries} from '../util/promise.js'
import {isString, isObject, isArray} from '../util/underscore.js'
import { mapSeries } from '../util/promise.js'
import { isString, isObject, isArray } from '../util/underscore.js'
import assert from '../util/assert.js'
import {identifier, value, hash} from '../lexical.js'
import { identifier, value, hash } from '../lexical.js'
export default function (liquid, Liquid) {
const RenderBreakError = Liquid.Types.RenderBreakError
@@ -11,7 +11,7 @@ export default function (liquid, Liquid) {
`(?:\\s+(reversed))?` +
`(?:\\s+${hash.source})*$`)
liquid.registerTag('for', {parse, render})
liquid.registerTag('for', { parse, render })
function parse (tagToken, remainTokens) {
const match = re.exec(tagToken.args)
+1 -1
View File
@@ -1,5 +1,5 @@
import assert from '../util/assert.js'
import {value, quotedLine} from '../lexical.js'
import { value, quotedLine } from '../lexical.js'
const staticFileRE = /[^\s,]+/
+3 -3
View File
@@ -1,9 +1,9 @@
import assert from '../util/assert.js'
import {create} from '../util/underscore.js'
import {identifier} from '../lexical.js'
import { create } from '../util/underscore.js'
import { identifier } from '../lexical.js'
export default function (liquid, Liquid) {
const {CaptureScope, AssignScope, IncrementScope} = Liquid.Types
const { CaptureScope, AssignScope, IncrementScope } = Liquid.Types
liquid.registerTag('increment', {
parse: function (token) {
+1 -1
View File
@@ -1,5 +1,5 @@
import assert from '../util/assert.js'
import {value as rValue} from '../lexical.js'
import { value as rValue } from '../lexical.js'
/*
* blockMode:
+2 -2
View File
@@ -1,6 +1,6 @@
import {mapSeries} from '../util/promise.js'
import { mapSeries } from '../util/promise.js'
import assert from '../util/assert.js'
import {identifier, value, hash} from '../lexical.js'
import { identifier, value, hash } from '../lexical.js'
export default function (liquid, Liquid) {
const re = new RegExp(`^(${identifier.source})\\s+in\\s+` +
+1 -1
View File
@@ -1,4 +1,4 @@
import {last, isArray} from './util/underscore'
import { last, isArray } from './util/underscore'
function domResolve (root, path) {
const base = document.createElement('base')
+1 -1
View File
@@ -1,6 +1,6 @@
import * as _ from './util/underscore.js'
import path from 'path'
import {anySeries} from './util/promise.js'
import { anySeries } from './util/promise.js'
import fs from 'fs'
const statFileAsync = _.promisify(fs.stat)
+2 -2
View File
@@ -1,10 +1,10 @@
import * as lexical from './lexical.js'
import {TokenizationError} from './util/error.js'
import { TokenizationError } from './util/error.js'
import * as _ from './util/underscore.js'
import assert from './util/assert.js'
import whiteSpaceCtrl from './whitespace-ctrl.js'
export {default as whiteSpaceCtrl} from './whitespace-ctrl.js'
export { default as whiteSpaceCtrl } from './whitespace-ctrl.js'
export function parse (input, file, options) {
assert(_.isString(input), 'illegal input')
+1 -1
View File
@@ -1,4 +1,4 @@
import {AssertionError} from './error.js'
import { AssertionError } from './error.js'
export default function (predicate, message) {
if (!predicate) {
+1 -1
View File
@@ -22,7 +22,7 @@ function initLiquidError (err, token) {
}
export function TokenizationError (message, token) {
initLiquidError.call(this, {message: message}, token)
initLiquidError.call(this, { message: message }, token)
}
TokenizationError.prototype = _.create(Error.prototype)
TokenizationError.prototype.constructor = TokenizationError
+1 -1
View File
@@ -1,4 +1,4 @@
import {assign} from './util/underscore.js'
import { assign } from './util/underscore.js'
export default function whiteSpaceCtrl (tokens, options) {
options = assign({ greedy: true }, options)
+3 -3
View File
@@ -13,7 +13,7 @@ describe('.parseAndRender()', function () {
})
})
it('should value object', function () {
var ctx = { obj: {foo: 'bar'} }
var ctx = { obj: { foo: 'bar' } }
return expect(engine.parseAndRender('{{obj}}', ctx)).to.eventually.equal('{"foo":"bar"}')
})
it('should value array', function () {
@@ -39,7 +39,7 @@ describe('.parseAndRender()', function () {
}).to.not.throw()
})
it('should render template multiple times', function () {
var ctx = {obj: {foo: 'bar'}}
var ctx = { obj: { foo: 'bar' } }
var template = engine.parse('{{obj}}')
return engine.render(template, ctx)
.then(result => expect(result).to.equal('{"foo":"bar"}'))
@@ -47,7 +47,7 @@ describe('.parseAndRender()', function () {
.then((result) => expect(result).to.equal('{"foo":"bar"}'))
})
it('should render filters', function () {
var ctx = {names: ['alice', 'bob']}
var ctx = { names: ['alice', 'bob'] }
var template = engine.parse('<p>{{names | join: ","}}</p>')
return expect(engine.render(template, ctx)).to.eventually.equal('<p>alice,bob</p>')
})
+3 -3
View File
@@ -29,7 +29,7 @@ describe('#renderFile()', function () {
.to.eventually.equal('foo')
})
it('should find files without extname', function () {
var engine = Liquid({root: '/root'})
var engine = Liquid({ root: '/root' })
return expect(engine.renderFile('/root/files/bar', {}))
.to.eventually.equal('bar')
})
@@ -57,11 +57,11 @@ describe('#renderFile()', function () {
.to.eventually.equal('FOO')
})
it('should render file with context', function () {
return expect(engine.renderFile('/root/files/name.html', {name: 'harttle'}))
return expect(engine.renderFile('/root/files/name.html', { name: 'harttle' }))
.to.eventually.equal('My name is harttle.')
})
it('should use default extname', function () {
return expect(engine.renderFile('files/name', {name: 'harttle'})).to.eventually.equal('My name is harttle.')
return expect(engine.renderFile('files/name', { name: 'harttle' })).to.eventually.equal('My name is harttle.')
})
it('should throw with lookup list when file not exist', function () {
engine = Liquid({
+22 -22
View File
@@ -15,7 +15,7 @@ describe('xhr', () => {
server = sinon.createFakeServer()
server.autoRespond = true
server.respondWith('GET', 'https://example.com/views/hello.html',
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
var dom = new JSDOM('', {
url: 'https://example.com/foo/bar.html',
contentType: 'text/html',
@@ -35,29 +35,29 @@ describe('xhr', () => {
})
describe('#renderFile()', () => {
it('should support without extname', () => {
return expect(engine.renderFile('hello', {name: 'alice1'}))
return expect(engine.renderFile('hello', { name: 'alice1' }))
.to.eventually.equal('hello alice1')
})
it('should support with extname', () => {
return expect(engine.renderFile('hello.html', {name: 'alice2'}))
return expect(engine.renderFile('hello.html', { name: 'alice2' }))
.to.eventually.equal('hello alice2')
})
it('should support with absolute path', () => {
server.respondWith('GET', 'https://example.com/foo.html',
[200, {'Content-Type': 'text/plain'}, 'foo'])
[200, { 'Content-Type': 'text/plain' }, 'foo'])
return expect(engine.renderFile('/foo.html'))
.to.eventually.equal('foo')
})
it('should support with url', () => {
return expect(engine.renderFile('https://example.com/views/hello.html', {name: 'alice4'}))
return expect(engine.renderFile('https://example.com/views/hello.html', { name: 'alice4' }))
.to.eventually.equal('hello alice4')
})
it('should support include', () => {
server.respondWith('GET', 'https://example.com/views/hello.html',
[200, {'Content-Type': 'text/plain'}, "hello {% include 'name.html' %}"])
[200, { 'Content-Type': 'text/plain' }, "hello {% include 'name.html' %}"])
server.respondWith('GET', 'https://example.com/views/name.html',
[200, {'Content-Type': 'text/plain'}, '{{name}}'])
return expect(engine.renderFile('hello.html', {name: 'alice5'}))
[200, { 'Content-Type': 'text/plain' }, '{{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
})
it('should throw 404', () => {
@@ -82,8 +82,8 @@ describe('xhr', () => {
extname: '.html'
})
server.respondWith('GET', 'https://example.com/foo/hello.html',
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', {name: 'alice5'}))
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
})
it('should support empty root', () => {
@@ -92,8 +92,8 @@ describe('xhr', () => {
extname: '.html'
})
server.respondWith('https://example.com/foo/hello.html',
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', {name: 'alice5'}))
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
})
it('should support with relative path', () => {
@@ -102,8 +102,8 @@ describe('xhr', () => {
extname: '.html'
})
server.respondWith('GET', 'https://example.com/foo/views/hello.html',
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', {name: 'alice5'}))
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
})
it('should support with absolute path', () => {
@@ -112,8 +112,8 @@ describe('xhr', () => {
extname: '.html'
})
server.respondWith('GET', 'https://example.com/views/hello.html',
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', {name: 'alice5'}))
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
})
it('should support with url', () => {
@@ -122,20 +122,20 @@ describe('xhr', () => {
extname: '.html'
})
server.respondWith('GET', 'https://foo.com/bar/hello.html',
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', {name: 'alice5'}))
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
})
})
describe('cache options', () => {
it('should be disabled by default', () => {
server.respondWith('GET', 'https://example.com/views/foo.html',
[200, {'Content-Type': 'text/plain'}, 'foo1'])
[200, { 'Content-Type': 'text/plain' }, 'foo1'])
return engine.renderFile('foo.html')
.then((html) => {
expect(html).to.equal('foo1')
server.respondWith('GET', 'https://example.com/views/foo.html',
[200, {'Content-Type': 'text/plain'}, 'foo2'])
[200, { 'Content-Type': 'text/plain' }, 'foo2'])
return engine.renderFile('foo.html')
})
.then(html => expect(html).to.equal('foo2'))
@@ -147,12 +147,12 @@ describe('xhr', () => {
cache: true
})
server.respondWith('GET', 'https://example.com/views/foo.html',
[200, {'Content-Type': 'text/plain'}, 'foo1'])
[200, { 'Content-Type': 'text/plain' }, 'foo1'])
return engine.renderFile('foo.html')
.then((html) => {
expect(html).to.equal('foo1')
server.respondWith('GET', 'https://example.com/views/foo.html',
[200, {'Content-Type': 'text/plain'}, 'foo2'])
[200, { 'Content-Type': 'text/plain' }, 'foo2'])
return engine.renderFile('foo.html')
})
.then(html => expect(html).to.equal('foo1'))
+1 -1
View File
@@ -2,7 +2,7 @@ import chai from 'chai'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
import Filter from '../../src/filter.js'
import {factory as scopeFactory} from '../../src/scope.js'
import { factory as scopeFactory } from '../../src/scope.js'
chai.use(sinonChai)
const expect = chai.expect
+3 -3
View File
@@ -31,7 +31,7 @@ describe('Liquid', function () {
})
})
describe('#express()', function () {
const liquid = new Liquid({root: '/root'})
const liquid = new Liquid({ root: '/root' })
const render = liquid.express()
before(function () {
mock({
@@ -42,14 +42,14 @@ describe('Liquid', function () {
mock.restore()
})
it('should render single template', function (done) {
render.call({root: '.'}, 'foo', null, (err, result) => {
render.call({ root: '.' }, 'foo', null, (err, result) => {
if (err) return done(err)
expect(result).to.equal('foo')
done()
})
})
it('should render single template with Array-typed root', function (done) {
render.call({root: ['.']}, 'foo', null, (err, result) => {
render.call({ root: ['.'] }, 'foo', null, (err, result) => {
if (err) return done(err)
expect(result).to.equal('foo')
done()
+2 -2
View File
@@ -6,7 +6,7 @@ const expect = chai.expect
chai.use(chaiAsPromised)
describe('trimming', function () {
const ctx = {name: 'harttle'}
const ctx = { name: 'harttle' }
describe('tag trimming', function () {
it('should respect trim_tag_left', function () {
@@ -50,7 +50,7 @@ describe('trimming', function () {
.to.eventually.equal('aharttle')
})
it('should respect to greedy:false by default', function () {
const engine = Liquid({greedy: false})
const engine = Liquid({ greedy: false })
return expect(engine.parseAndRender(src, ctx))
.to.eventually.equal('\n a \nharttle ')
})
+4 -4
View File
@@ -3,7 +3,7 @@ import chaiAsPromised from 'chai-as-promised'
import sinonChai from 'sinon-chai'
import sinon from 'sinon'
import Tag from '../../src/tag.js'
import {factory as scopeFactory} from '../../src/scope.js'
import { factory as scopeFactory } from '../../src/scope.js'
import Filter from '../../src/filter'
import Render from '../../src/render.js'
import parser from '../../src/parser.js'
@@ -31,7 +31,7 @@ describe('render', function () {
it('should render html', function () {
const scope = scopeFactory({})
return expect(render.renderTemplates([{type: 'html', value: '<p>'}], scope)).to.eventually.equal('<p>')
return expect(render.renderTemplates([{ type: 'html', value: '<p>' }], scope)).to.eventually.equal('<p>')
})
})
@@ -59,7 +59,7 @@ describe('render', function () {
return expect(render.renderValue(tpl, scope)).to.eventually.equal('{"num":2,"circular":{"bar":"bar"}}')
})
it('should skip function property', function () {
const scope = scopeFactory({obj: {foo: 'foo', bar: x => x}})
const scope = scopeFactory({ obj: { foo: 'foo', bar: x => x } })
const tpl = Template.parseValue('obj')
return expect(render.renderValue(tpl, scope)).to.eventually.equal('{"foo":"foo"}')
})
@@ -92,7 +92,7 @@ describe('render', function () {
filter.register('time', time)
const tpl = Template.parseValue('foo.bar | date: "b" | time:2')
const scope = scopeFactory({
foo: {bar: 'bar'}
foo: { bar: 'bar' }
})
render.evalValue(tpl, scope)
expect(date).to.have.been.calledWith('bar', 'b')
+11 -11
View File
@@ -1,5 +1,5 @@
import chai from 'chai'
import {factory as scopeFactory} from '../../src/scope.js'
import { factory as scopeFactory } from '../../src/scope.js'
const expect = chai.expect
@@ -97,18 +97,18 @@ describe('scope', function () {
})
it('should respect to to_liquid', function () {
const scope = scopeFactory({foo: {
to_liquid: () => ({bar: 'BAR'}),
const scope = scopeFactory({ foo: {
to_liquid: () => ({ bar: 'BAR' }),
bar: 'bar'
}})
} })
expect(scope.get('foo.bar')).to.equal('BAR')
})
it('should respect to toLiquid', function () {
const scope = scopeFactory({foo: {
toLiquid: () => ({bar: 'BAR'}),
const scope = scopeFactory({ foo: {
toLiquid: () => ({ bar: 'BAR' }),
bar: 'bar'
}})
} })
expect(scope.get('foo.bar')).to.equal('BAR')
})
@@ -152,12 +152,12 @@ describe('scope', function () {
expect(scope.get('a.b.c.d')).to.equal('COO')
})
it('should keep other properties of parent', function () {
scope.push({obj: {foo: 'FOO'}})
scope.push({ obj: { foo: 'FOO' } })
scope.set('obj.bar', 'BAR')
expect(scope.get('obj.foo')).to.equal('FOO')
})
it('should abort if property cannot be set', function () {
scope.push({obj: {foo: 'FOO'}})
scope.push({ obj: { foo: 'FOO' } })
scope.set('obj.foo.bar', 'BAR')
expect(scope.get('obj.foo')).to.equal('FOO')
})
@@ -220,8 +220,8 @@ describe('scope', function () {
expect(scope.get('bar')).to.equal('bar')
})
it('should hide deep properties by push', function () {
scope.set('bar', {bar: 'bar'})
scope.push({bar: {foo: 'foo'}})
scope.set('bar', { bar: 'bar' })
scope.push({ bar: { foo: 'foo' } })
expect(scope.get('bar.foo')).to.equal('foo')
expect(scope.get('bar.bar')).to.equal(undefined)
})
+1 -1
View File
@@ -1,6 +1,6 @@
import chai from 'chai'
import Tag from '../../src/tag.js'
import {factory as scopeFactory} from '../../src/scope.js'
import { factory as scopeFactory } from '../../src/scope.js'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
+1 -1
View File
@@ -23,7 +23,7 @@ describe('tags/assign', function () {
.to.eventually.equal('10086')
})
it('should shading rather than overwriting', function () {
const ctx = {foo: 'foo'}
const ctx = { foo: 'foo' }
const src = '{% assign foo="FOO" %}{{foo}}'
return liquid.parseAndRender(src, ctx)
.then(x => {
+1 -1
View File
@@ -15,7 +15,7 @@ describe('tags/capture', function () {
it('should shading rather than overwriting', function () {
const src = '{% capture var %}10{% endcapture %}{{var}}'
const ctx = {'var': 20}
const ctx = { 'var': 20 }
return liquid.parseAndRender(src, ctx)
.then(x => {
expect(x).to.equal('10')
+1 -1
View File
@@ -20,7 +20,7 @@ describe('tags/decrement', function () {
it('should decrement defined variable', function () {
const src = '{% decrement var %}{% decrement var %}{% decrement var %}'
const ctx = {'var': 10}
const ctx = { 'var': 10 }
return liquid.parseAndRender(src, ctx)
.then(x => {
expect(x).to.equal('987')
+3 -3
View File
@@ -17,7 +17,7 @@ describe('tags/for', function () {
strObj: new String(''),
emptyObj: {},
nullProtoObj: Object.create(null),
obj: {foo: 'bar', coo: 'haa'},
obj: { foo: 'bar', coo: 'haa' },
alpha: ['a', 'b', 'c'],
emptyArray: []
}
@@ -37,12 +37,12 @@ describe('tags/for', function () {
describe('scope', function () {
it('should read super scope', function () {
const src = '{%for a in (1..2)%}{{num}}{%endfor%}'
return expect(liquid.parseAndRender(src, {num: 1}))
return expect(liquid.parseAndRender(src, { num: 1 }))
.to.eventually.equal('11')
})
it('should write super scope', function () {
const src = '{%for a in (1..2)%}{{num}}{%assign num = 2%}{%endfor%}'
return expect(liquid.parseAndRender(src, {num: 1}))
return expect(liquid.parseAndRender(src, { num: 1 }))
.to.eventually.equal('12')
})
})
+5 -5
View File
@@ -29,7 +29,7 @@ describe('tags/include', function () {
'/current.html': 'bar{% include "bar/{{name}}" %}bar',
'/bar/foo.html': 'foo'
})
return expect(liquid.renderFile('/current.html', {name: 'foo.html'})).to
return expect(liquid.renderFile('/current.html', { name: 'foo.html' })).to
.eventually.equal('barfoobar')
})
@@ -114,7 +114,7 @@ describe('tags/include', function () {
'/parent.html': 'X{% include child.html color:"red" %}Y',
'/child.html': 'child with {{color}}'
})
const staticLiquid = new Liquid({dynamicPartials: false, root: '/'})
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/' })
return expect(staticLiquid.renderFile('parent.html')).to
.eventually.equal('Xchild with redY')
})
@@ -124,7 +124,7 @@ describe('tags/include', function () {
'/parent.html': 'X{% include bar/./../foo/child.html %}Y',
'/foo/child.html': 'child'
})
const staticLiquid = new Liquid({dynamicPartials: false, root: '/'})
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/' })
return expect(staticLiquid.renderFile('parent.html')).to
.eventually.equal('XchildY')
})
@@ -134,7 +134,7 @@ describe('tags/include', function () {
'/parent.html': 'X{% include foo/child.html %}Y',
'/foo/child.html': 'child'
})
const staticLiquid = new Liquid({dynamicPartials: false, root: '/'})
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/' })
return expect(staticLiquid.renderFile('parent.html')).to
.eventually.equal('XchildY')
})
@@ -144,7 +144,7 @@ describe('tags/include', function () {
'/parent.html': 'X{% include child.html, color:"red" %}Y',
'/child.html': 'child with {{color}}'
})
const staticLiquid = new Liquid({dynamicPartials: false, root: '/'})
const staticLiquid = new Liquid({ dynamicPartials: false, root: '/' })
return expect(staticLiquid.renderFile('parent.html')).to
.eventually.equal('Xchild with redY')
})
+1 -1
View File
@@ -15,7 +15,7 @@ describe('tags/increment', function () {
it('should increment defined variable', function () {
const src = '{% increment one %}{% increment one %}{% increment one %}'
const ctx = {one: 7}
const ctx = { one: 7 }
return liquid.parseAndRender(src, ctx)
.then(x => {
expect(x).to.equal('789')
+1 -1
View File
@@ -1,4 +1,4 @@
import {resolve} from '../../src/template-browser.js'
import { resolve } from '../../src/template-browser.js'
import chai from 'chai'
const expect = chai.expect
+3 -3
View File
@@ -1,4 +1,4 @@
import {resolve} from '../../src/template.js'
import { resolve } from '../../src/template.js'
import mock from 'mock-fs'
import chai from 'chai'
import path from 'path'
@@ -15,12 +15,12 @@ describe('template', function () {
})
describe('#resolve()', function () {
it('should resolve based on root', function () {
const filepath = resolve('bar.html', '/foo', {root: []})
const filepath = resolve('bar.html', '/foo', { root: [] })
const expected = path.resolve('/foo/bar.html')
return expect(filepath).to.eventually.equal(expected)
})
it('should resolve based on root', function () {
return expect(resolve('foo.html', '/foo', {root: []}))
return expect(resolve('foo.html', '/foo', { root: [] }))
.to.rejectedWith(/Failed to lookup foo.html in: \/foo/)
})
})
+4 -4
View File
@@ -1,7 +1,7 @@
import chai from 'chai'
import sinonChai from 'sinon-chai'
import sinon from 'sinon'
import {RenderError, RenderBreakError} from '../../../src/util/error.js'
import { RenderError, RenderBreakError } from '../../../src/util/error.js'
import * as _ from '../../../src/util/underscore.js'
const expect = chai.expect
@@ -37,13 +37,13 @@ describe('util/underscore', function () {
})
describe('.stringify()', function () {
it('should respect to to_liquid() method', function () {
expect(_.stringify({to_liquid: () => 'foo'})).to.equal('foo')
expect(_.stringify({ to_liquid: () => 'foo' })).to.equal('foo')
})
it('should respect to toLiquid() method', function () {
expect(_.stringify({toLiquid: () => 'foo'})).to.equal('foo')
expect(_.stringify({ toLiquid: () => 'foo' })).to.equal('foo')
})
it('should recursively call toLiquid()', function () {
expect(_.stringify({toLiquid: () => ({toLiquid: () => 'foo'})})).to.equal('foo')
expect(_.stringify({ toLiquid: () => ({ toLiquid: () => 'foo' }) })).to.equal('foo')
})
it('should return "null" for null', function () {
expect(_.stringify(null)).to.equal('null')
+2 -2
View File
@@ -1,4 +1,4 @@
import {read} from '../../src/template-browser.js'
import { read } from '../../src/template-browser.js'
import sinon from 'sinon'
import chai from 'chai'
@@ -16,7 +16,7 @@ describe('template-browser', () => {
server = sinon.createFakeServer()
server.autoRespond = true
server.respondWith('GET', 'https://example.com/views/hello.html',
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
global.XMLHttpRequest = sinon.useFakeXMLHttpRequest()
})
afterEach(() => {