diff --git a/demo/nodejs/index.js b/demo/nodejs/index.js
index 1d65ae5d7..602db7323 100644
--- a/demo/nodejs/index.js
+++ b/demo/nodejs/index.js
@@ -1,10 +1,12 @@
const Liquid = require('../..')
-let engine = new Liquid()
-let src = 'Welcome to {{ name | capitalize}}, access time: {{date|date: "%H:%M:%S"}}'
+let engine = new Liquid({
+ root: __dirname,
+ extname: '.liquid'
+})
let ctx = {
- name: 'Liquid',
- date: new Date()
+ todos: ['fork and clone', 'make it better', 'make a pull request'],
+ title: 'Welcome to liquidjs!'
}
-engine.parseAndRender(src, ctx).then(console.log)
+engine.renderFile('todolist', ctx).then(console.log)
diff --git a/demo/nodejs/todolist.liquid b/demo/nodejs/todolist.liquid
new file mode 100644
index 000000000..77c3edb64
--- /dev/null
+++ b/demo/nodejs/todolist.liquid
@@ -0,0 +1,5 @@
+
+ {% for todo in todos %}
+ - {{forloop.index}} - {{todo}}
+ {% endfor %}
+
diff --git a/package.json b/package.json
index 0b31c76d7..7d2f8d116 100644
--- a/package.json
+++ b/package.json
@@ -10,14 +10,14 @@
"coveralls": "nyc report --reporter=text-lcov --require babel-core/register mocha test/ --recursive | coveralls",
"dist": "npm run babelify && npm run browserify && npm run uglify",
"babelify": "babel src -d build",
- "browserify": "browserify build/index.js -s Liquid --ignore path --global true > dist/liquid.js",
- "uglify": "uglifyjs dist/liquid.js --compress warnings=false --mangle --output dist/liquid.min.js",
- "demo:browser": "echo open http://localhost:8080/demo/browser && http-server",
+ "browserify": "browserify src/index.js -s Liquid --ignore path -t [ babelify --presets [ es2015 ] ] > dist/liquid.js",
+ "uglify": "uglifyjs dist/liquid.js --compress warnings=false --mangle toplevel --output dist/liquid.min.js",
+ "demo:browser": "echo open http://localhost:8080/demo/browser && http-server -c-1",
"demo:nodejs": "node ./demo/nodejs/index.js",
"demo:express": "cd ./demo/express/ && npm start",
"preversion": "npm run lint && npm test",
"version": "npm run dist && git add -A dist",
- "postversion": "git push && git push --tags"
+ "postversion": "git push --tags"
},
"repository": {
"type": "git",
diff --git a/src/index.js b/src/index.js
index a6faa49f0..7304a2350 100644
--- a/src/index.js
+++ b/src/index.js
@@ -14,7 +14,7 @@ import {isTruthy, isFalsy, evalExp, evalValue} from './syntax.js'
import tags from './tags'
import filters from './filters'
import {anySeries} from './util/promise.js'
-import Errors from './util/error.js'
+import {ParseError, TokenizationEroor, RenderBreakError, AssertionError} from './util/error.js'
let _engine = {
init: function (tag, filter, options) {
@@ -174,10 +174,10 @@ function normalizeStringArray (value) {
}
const Types = {
- ParseError: Errors.ParseError,
- TokenizationEroor: Errors.TokenizationError,
- RenderBreakError: Errors.RenderBreakError,
- AssertionError: Errors.AssertionError
+ ParseError,
+ TokenizationEroor,
+ RenderBreakError,
+ AssertionError
}
factory.isTruthy = isTruthy
diff --git a/src/tags/increment.js b/src/tags/increment.js
index bc881635b..7437470d4 100644
--- a/src/tags/increment.js
+++ b/src/tags/increment.js
@@ -1,5 +1,4 @@
-'use strict'
-const Liquid = require('..')
+const Liquid = require('../index')
const assert = require('../util/assert.js')
const lexical = Liquid.lexical
const types = require('../scope').types
diff --git a/src/util/error.js b/src/util/error.js
index f444b0b98..407cf2995 100644
--- a/src/util/error.js
+++ b/src/util/error.js
@@ -21,13 +21,13 @@ function initLiquidError (err, token) {
(err.stack ? '\nFrom ' + err.stack : '')
}
-function TokenizationError (message, token) {
+export function TokenizationError (message, token) {
initLiquidError.call(this, {message: message}, token)
}
TokenizationError.prototype = Object.create(Error.prototype)
TokenizationError.prototype.constructor = TokenizationError
-function ParseError (e, token) {
+export function ParseError (e, token) {
_.assign(this, e)
this.originalError = e
@@ -36,7 +36,7 @@ function ParseError (e, token) {
ParseError.prototype = Object.create(Error.prototype)
ParseError.prototype.constructor = ParseError
-function RenderError (e, tpl) {
+export function RenderError (e, tpl) {
// return the original render error
if (e instanceof RenderError) {
return e
@@ -49,14 +49,14 @@ function RenderError (e, tpl) {
RenderError.prototype = Object.create(Error.prototype)
RenderError.prototype.constructor = RenderError
-function RenderBreakError (message) {
+export function RenderBreakError (message) {
initError.call(this)
this.message = message + ''
}
RenderBreakError.prototype = Object.create(Error.prototype)
RenderBreakError.prototype.constructor = RenderBreakError
-function AssertionError (message) {
+export function AssertionError (message) {
initError.call(this)
this.message = message + ''
}
@@ -98,11 +98,3 @@ function mkMessage (msg, token) {
}
return msg
}
-
-module.exports = {
- TokenizationError,
- ParseError,
- RenderBreakError,
- AssertionError,
- RenderError
-}
diff --git a/test/options/strict.js b/test/options/strict.js
index 7583ea5fd..f699da17f 100644
--- a/test/options/strict.js
+++ b/test/options/strict.js
@@ -1,6 +1,7 @@
-const chai = require('chai')
+import Liquid from '../../src'
+import chai from 'chai'
+
const expect = chai.expect
-const Liquid = require('../../src')
chai.use(require('chai-as-promised'))
describe('strict options', function () {
diff --git a/test/tags/capture.js b/test/tags/capture.js
index 19e3eb698..0d38faed0 100644
--- a/test/tags/capture.js
+++ b/test/tags/capture.js
@@ -1,6 +1,6 @@
-'use strict'
-const Liquid = require('../..')
-const chai = require('chai')
+import Liquid from '../../src/index'
+import chai from 'chai'
+
const expect = chai.expect
chai.use(require('chai-as-promised'))
diff --git a/test/tags/case.js b/test/tags/case.js
index ef987a2ea..97f87a40f 100644
--- a/test/tags/case.js
+++ b/test/tags/case.js
@@ -1,5 +1,6 @@
-const Liquid = require('../..')
-const chai = require('chai')
+import Liquid from '../../src'
+import chai from 'chai'
+
const expect = chai.expect
chai.use(require('chai-as-promised'))
diff --git a/test/tags/comment.js b/test/tags/comment.js
index b428ccf99..5c930da2e 100644
--- a/test/tags/comment.js
+++ b/test/tags/comment.js
@@ -1,5 +1,6 @@
-const Liquid = require('../..')
-const chai = require('chai')
+import Liquid from '../../src'
+import chai from 'chai'
+
const expect = chai.expect
chai.use(require('chai-as-promised'))
diff --git a/test/tags/cycle.js b/test/tags/cycle.js
index ab2396f39..5d4a2edd3 100644
--- a/test/tags/cycle.js
+++ b/test/tags/cycle.js
@@ -1,5 +1,6 @@
-const Liquid = require('../..')
-const chai = require('chai')
+import Liquid from '../../src'
+import chai from 'chai'
+
const expect = chai.expect
chai.use(require('chai-as-promised'))
diff --git a/test/tags/decrement.js b/test/tags/decrement.js
index e7c0ac4d3..85cbeab9f 100644
--- a/test/tags/decrement.js
+++ b/test/tags/decrement.js
@@ -1,6 +1,6 @@
-'use strict'
-const Liquid = require('../..')
-const chai = require('chai')
+import Liquid from '../../src'
+import chai from 'chai'
+
const expect = chai.expect
chai.use(require('chai-as-promised'))
diff --git a/test/tags/for.js b/test/tags/for.js
index 682598d47..d9885d5b3 100644
--- a/test/tags/for.js
+++ b/test/tags/for.js
@@ -1,5 +1,6 @@
-const Liquid = require('../..')
-const chai = require('chai')
+import Liquid from '../../src'
+import chai from 'chai'
+
const expect = chai.expect
chai.use(require('chai-as-promised'))
diff --git a/test/tags/if.js b/test/tags/if.js
index be3dc8106..8fc417c48 100644
--- a/test/tags/if.js
+++ b/test/tags/if.js
@@ -1,5 +1,6 @@
-const Liquid = require('../..')
-const chai = require('chai')
+import Liquid from '../../src/index'
+import chai from 'chai'
+
const expect = chai.expect
chai.use(require('chai-as-promised'))
diff --git a/test/tags/include.js b/test/tags/include.js
index 0327d26fd..2b3599e57 100644
--- a/test/tags/include.js
+++ b/test/tags/include.js
@@ -1,6 +1,7 @@
-const Liquid = require('../..')
-const mock = require('mock-fs')
-const chai = require('chai')
+import Liquid from '../../src'
+import mock from 'mock-fs'
+import chai from 'chai'
+
const expect = chai.expect
chai.use(require('chai-as-promised'))
diff --git a/test/tags/increment.js b/test/tags/increment.js
index 6dafef3d7..a29adb48b 100644
--- a/test/tags/increment.js
+++ b/test/tags/increment.js
@@ -1,6 +1,6 @@
-'use strict'
-const Liquid = require('../..')
-const chai = require('chai')
+import Liquid from '../../src'
+import chai from 'chai'
+
const expect = chai.expect
chai.use(require('chai-as-promised'))
diff --git a/test/tags/layout.js b/test/tags/layout.js
index 7c98d04f9..244a5807c 100644
--- a/test/tags/layout.js
+++ b/test/tags/layout.js
@@ -1,6 +1,7 @@
-const Liquid = require('../..')
-const mock = require('mock-fs')
-const chai = require('chai')
+import Liquid from '../../src'
+import mock from 'mock-fs'
+import chai from 'chai'
+
const expect = chai.expect
chai.use(require('chai-as-promised'))
diff --git a/test/tags/raw.js b/test/tags/raw.js
index a367d57c7..ab6c45b8c 100644
--- a/test/tags/raw.js
+++ b/test/tags/raw.js
@@ -1,5 +1,6 @@
-const Liquid = require('../..')
-const chai = require('chai')
+import Liquid from '../../src'
+import chai from 'chai'
+
const expect = chai.expect
chai.use(require('chai-as-promised'))
diff --git a/test/tags/tablerow.js b/test/tags/tablerow.js
index 8c6c413a6..fa585541e 100644
--- a/test/tags/tablerow.js
+++ b/test/tags/tablerow.js
@@ -1,5 +1,6 @@
-const Liquid = require('../..')
-const chai = require('chai')
+import Liquid from '../../src'
+import chai from 'chai'
+
const expect = chai.expect
chai.use(require('chai-as-promised'))
diff --git a/test/tags/unless.js b/test/tags/unless.js
index 5c7d6c437..275247abf 100644
--- a/test/tags/unless.js
+++ b/test/tags/unless.js
@@ -1,5 +1,6 @@
-const Liquid = require('../..')
-const chai = require('chai')
+import Liquid from '../../src'
+import chai from 'chai'
+
const expect = chai.expect
chai.use(require('chai-as-promised'))
diff --git a/test/util/error.js b/test/util/error.js
index bfcf5f50d..9c1bc750c 100644
--- a/test/util/error.js
+++ b/test/util/error.js
@@ -1,11 +1,13 @@
-const chai = require('chai')
+import Liquid from '../../src'
+import mock from 'mock-fs'
+import chai from 'chai'
+import path from 'path'
+
const expect = chai.expect
-const mock = require('mock-fs')
-const path = require('path')
chai.use(require('chai-as-promised'))
-let engine = require('../..')()
-let strictEngine = require('../..')({
+let engine = Liquid()
+let strictEngine = Liquid({
strict_variables: true,
strict_filters: true
})
@@ -95,7 +97,7 @@ describe('error', function () {
describe('RenderError', function () {
beforeEach(function () {
- engine = require('../..')({
+ engine = Liquid({
root: '/'
})
engine.registerTag('throwingTag', {
@@ -269,7 +271,7 @@ describe('error', function () {
describe('ParseError', function () {
beforeEach(function () {
- engine = require('../..')()
+ engine = Liquid()
engine.registerTag('throwsOnParse', {
parse: function () {
throw new Error('intended parse error')
diff --git a/test/util/underscore.js b/test/util/underscore.js
index 7b9c1bf7a..2dfb5c8cf 100644
--- a/test/util/underscore.js
+++ b/test/util/underscore.js
@@ -1,6 +1,6 @@
import chai from 'chai'
import sinon from 'sinon'
-import Errors from '../../src/util/error.js'
+import {RenderError, RenderBreakError} from '../../src/util/error.js'
import _ from '../../src/util/underscore.js'
const expect = chai.expect
@@ -17,10 +17,10 @@ describe('util/underscore', function () {
input: 'xx'
}
}
- expect(_.isError(new Errors.RenderError(new Error(), tpl))).to.be.true
+ expect(_.isError(new RenderError(new Error(), tpl))).to.be.true
})
it('should return true for RenderBreakError', function () {
- expect(_.isError(new Errors.RenderBreakError())).to.be.true
+ expect(_.isError(new RenderBreakError())).to.be.true
})
})
describe('.isString()', function () {
diff --git a/test/util/url.js b/test/util/url.js
index ec6ded851..4622bfac7 100644
--- a/test/util/url.js
+++ b/test/util/url.js
@@ -1,6 +1,7 @@
-const chai = require('chai')
+import {resolve} from '../../src/util/url.js'
+import chai from 'chai'
+
const expect = chai.expect
-const url = require('../../src/util/url.js')
describe('util/url', function () {
if (process.version.match(/^v(\d+)/)[1] < 8) {
@@ -22,41 +23,41 @@ describe('util/url', function () {
describe('resolve', function () {
describe('root', function () {
it('should support width relative path', function () {
- expect(url.resolve('./views', 'foo'))
+ expect(resolve('./views', 'foo'))
.to.equal('https://example.com/foo/bar/views/foo')
- expect(url.resolve('./views/', 'foo'))
+ expect(resolve('./views/', 'foo'))
.to.equal('https://example.com/foo/bar/views/foo')
})
it('should support width absolute path', function () {
- expect(url.resolve('/views', 'foo'))
+ expect(resolve('/views', 'foo'))
.to.equal('https://example.com/views/foo')
- expect(url.resolve('/views/', 'foo'))
+ expect(resolve('/views/', 'foo'))
.to.equal('https://example.com/views/foo')
})
it('should support with empty', function () {
- expect(url.resolve('', 'page.html'))
+ expect(resolve('', 'page.html'))
.to.equal('https://example.com/foo/bar/page.html')
})
it('should support with url', function () {
- expect(url.resolve('https://example.com/views', 'page.html'))
+ expect(resolve('https://example.com/views', 'page.html'))
.to.equal('https://example.com/views/page.html')
- expect(url.resolve('https://example.com/views/', 'page.html'))
+ expect(resolve('https://example.com/views/', 'page.html'))
.to.equal('https://example.com/views/page.html')
})
it('should get the first value when argument is array', function () {
- expect(url.resolve(['https://example.com/views', 'https://google.com/views'], 'page.html'))
+ expect(resolve(['https://example.com/views', 'https://google.com/views'], 'page.html'))
.to.equal('https://example.com/views/page.html')
- expect(url.resolve(['https://example.com/views/', 'https://google.com/views'], 'page.html'))
+ expect(resolve(['https://example.com/views/', 'https://google.com/views'], 'page.html'))
.to.equal('https://example.com/views/page.html')
})
})
describe('path', function () {
it('should support width relative path', function () {
- expect(url.resolve('./views/', 'page.html'))
+ expect(resolve('./views/', 'page.html'))
.to.equal('https://example.com/foo/bar/views/page.html')
})
it('should support with absolute path', function () {
- expect(url.resolve('/views/', '/page.html'))
+ expect(resolve('/views/', '/page.html'))
.to.equal('https://example.com/page.html')
})
})
diff --git a/test/whitespace-control.js b/test/whitespace-control.js
index 69d440da9..a0856c24e 100644
--- a/test/whitespace-control.js
+++ b/test/whitespace-control.js
@@ -1,7 +1,8 @@
-const chai = require('chai')
-const expect = chai.expect
-const Liquid = require('..')
+import chai from 'chai'
+import Liquid from '../src'
+
const liquid = new Liquid()
+const expect = chai.expect
chai.use(require('chai-as-promised'))
const cases = [
diff --git a/test/xhr.js b/test/xhr.js
index 01e224966..9a35f76bc 100644
--- a/test/xhr.js
+++ b/test/xhr.js
@@ -1,4 +1,4 @@
-import Liquid from '..'
+import Liquid from '../src'
import sinon from 'sinon'
import chai from 'chai'
const expect = chai.expect