mirror of
https://github.com/harttle/liquidjs.git
synced 2026-10-02 16:45:14 -07:00
refactor: import babelify
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
const Liquid = require('../..')
|
const Liquid = require('../..')
|
||||||
|
|
||||||
let engine = new Liquid()
|
let engine = new Liquid({
|
||||||
let src = 'Welcome to {{ name | capitalize}}, access time: {{date|date: "%H:%M:%S"}}'
|
root: __dirname,
|
||||||
|
extname: '.liquid'
|
||||||
|
})
|
||||||
let ctx = {
|
let ctx = {
|
||||||
name: 'Liquid',
|
todos: ['fork and clone', 'make it better', 'make a pull request'],
|
||||||
date: new Date()
|
title: 'Welcome to liquidjs!'
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.parseAndRender(src, ctx).then(console.log)
|
engine.renderFile('todolist', ctx).then(console.log)
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<ul>
|
||||||
|
{% for todo in todos %}
|
||||||
|
<li>{{forloop.index}} - {{todo}}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
+4
-4
@@ -10,14 +10,14 @@
|
|||||||
"coveralls": "nyc report --reporter=text-lcov --require babel-core/register mocha test/ --recursive | coveralls",
|
"coveralls": "nyc report --reporter=text-lcov --require babel-core/register mocha test/ --recursive | coveralls",
|
||||||
"dist": "npm run babelify && npm run browserify && npm run uglify",
|
"dist": "npm run babelify && npm run browserify && npm run uglify",
|
||||||
"babelify": "babel src -d build",
|
"babelify": "babel src -d build",
|
||||||
"browserify": "browserify build/index.js -s Liquid --ignore path --global true > dist/liquid.js",
|
"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 --output dist/liquid.min.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",
|
"demo:browser": "echo open http://localhost:8080/demo/browser && http-server -c-1",
|
||||||
"demo:nodejs": "node ./demo/nodejs/index.js",
|
"demo:nodejs": "node ./demo/nodejs/index.js",
|
||||||
"demo:express": "cd ./demo/express/ && npm start",
|
"demo:express": "cd ./demo/express/ && npm start",
|
||||||
"preversion": "npm run lint && npm test",
|
"preversion": "npm run lint && npm test",
|
||||||
"version": "npm run dist && git add -A dist",
|
"version": "npm run dist && git add -A dist",
|
||||||
"postversion": "git push && git push --tags"
|
"postversion": "git push --tags"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
+5
-5
@@ -14,7 +14,7 @@ import {isTruthy, isFalsy, evalExp, evalValue} from './syntax.js'
|
|||||||
import tags from './tags'
|
import tags from './tags'
|
||||||
import filters from './filters'
|
import filters from './filters'
|
||||||
import {anySeries} from './util/promise.js'
|
import {anySeries} from './util/promise.js'
|
||||||
import Errors from './util/error.js'
|
import {ParseError, TokenizationEroor, RenderBreakError, AssertionError} from './util/error.js'
|
||||||
|
|
||||||
let _engine = {
|
let _engine = {
|
||||||
init: function (tag, filter, options) {
|
init: function (tag, filter, options) {
|
||||||
@@ -174,10 +174,10 @@ function normalizeStringArray (value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Types = {
|
const Types = {
|
||||||
ParseError: Errors.ParseError,
|
ParseError,
|
||||||
TokenizationEroor: Errors.TokenizationError,
|
TokenizationEroor,
|
||||||
RenderBreakError: Errors.RenderBreakError,
|
RenderBreakError,
|
||||||
AssertionError: Errors.AssertionError
|
AssertionError
|
||||||
}
|
}
|
||||||
|
|
||||||
factory.isTruthy = isTruthy
|
factory.isTruthy = isTruthy
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
'use strict'
|
const Liquid = require('../index')
|
||||||
const Liquid = require('..')
|
|
||||||
const assert = require('../util/assert.js')
|
const assert = require('../util/assert.js')
|
||||||
const lexical = Liquid.lexical
|
const lexical = Liquid.lexical
|
||||||
const types = require('../scope').types
|
const types = require('../scope').types
|
||||||
|
|||||||
+5
-13
@@ -21,13 +21,13 @@ function initLiquidError (err, token) {
|
|||||||
(err.stack ? '\nFrom ' + err.stack : '')
|
(err.stack ? '\nFrom ' + err.stack : '')
|
||||||
}
|
}
|
||||||
|
|
||||||
function TokenizationError (message, token) {
|
export function TokenizationError (message, token) {
|
||||||
initLiquidError.call(this, {message: message}, token)
|
initLiquidError.call(this, {message: message}, token)
|
||||||
}
|
}
|
||||||
TokenizationError.prototype = Object.create(Error.prototype)
|
TokenizationError.prototype = Object.create(Error.prototype)
|
||||||
TokenizationError.prototype.constructor = TokenizationError
|
TokenizationError.prototype.constructor = TokenizationError
|
||||||
|
|
||||||
function ParseError (e, token) {
|
export function ParseError (e, token) {
|
||||||
_.assign(this, e)
|
_.assign(this, e)
|
||||||
this.originalError = e
|
this.originalError = e
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ function ParseError (e, token) {
|
|||||||
ParseError.prototype = Object.create(Error.prototype)
|
ParseError.prototype = Object.create(Error.prototype)
|
||||||
ParseError.prototype.constructor = ParseError
|
ParseError.prototype.constructor = ParseError
|
||||||
|
|
||||||
function RenderError (e, tpl) {
|
export function RenderError (e, tpl) {
|
||||||
// return the original render error
|
// return the original render error
|
||||||
if (e instanceof RenderError) {
|
if (e instanceof RenderError) {
|
||||||
return e
|
return e
|
||||||
@@ -49,14 +49,14 @@ function RenderError (e, tpl) {
|
|||||||
RenderError.prototype = Object.create(Error.prototype)
|
RenderError.prototype = Object.create(Error.prototype)
|
||||||
RenderError.prototype.constructor = RenderError
|
RenderError.prototype.constructor = RenderError
|
||||||
|
|
||||||
function RenderBreakError (message) {
|
export function RenderBreakError (message) {
|
||||||
initError.call(this)
|
initError.call(this)
|
||||||
this.message = message + ''
|
this.message = message + ''
|
||||||
}
|
}
|
||||||
RenderBreakError.prototype = Object.create(Error.prototype)
|
RenderBreakError.prototype = Object.create(Error.prototype)
|
||||||
RenderBreakError.prototype.constructor = RenderBreakError
|
RenderBreakError.prototype.constructor = RenderBreakError
|
||||||
|
|
||||||
function AssertionError (message) {
|
export function AssertionError (message) {
|
||||||
initError.call(this)
|
initError.call(this)
|
||||||
this.message = message + ''
|
this.message = message + ''
|
||||||
}
|
}
|
||||||
@@ -98,11 +98,3 @@ function mkMessage (msg, token) {
|
|||||||
}
|
}
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
TokenizationError,
|
|
||||||
ParseError,
|
|
||||||
RenderBreakError,
|
|
||||||
AssertionError,
|
|
||||||
RenderError
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const chai = require('chai')
|
import Liquid from '../../src'
|
||||||
|
import chai from 'chai'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
const Liquid = require('../../src')
|
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
describe('strict options', function () {
|
describe('strict options', function () {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict'
|
import Liquid from '../../src/index'
|
||||||
const Liquid = require('../..')
|
import chai from 'chai'
|
||||||
const chai = require('chai')
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -1,5 +1,6 @@
|
|||||||
const Liquid = require('../..')
|
import Liquid from '../../src'
|
||||||
const chai = require('chai')
|
import chai from 'chai'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const Liquid = require('../..')
|
import Liquid from '../../src'
|
||||||
const chai = require('chai')
|
import chai from 'chai'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -1,5 +1,6 @@
|
|||||||
const Liquid = require('../..')
|
import Liquid from '../../src'
|
||||||
const chai = require('chai')
|
import chai from 'chai'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict'
|
import Liquid from '../../src'
|
||||||
const Liquid = require('../..')
|
import chai from 'chai'
|
||||||
const chai = require('chai')
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -1,5 +1,6 @@
|
|||||||
const Liquid = require('../..')
|
import Liquid from '../../src'
|
||||||
const chai = require('chai')
|
import chai from 'chai'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -1,5 +1,6 @@
|
|||||||
const Liquid = require('../..')
|
import Liquid from '../../src/index'
|
||||||
const chai = require('chai')
|
import chai from 'chai'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const Liquid = require('../..')
|
import Liquid from '../../src'
|
||||||
const mock = require('mock-fs')
|
import mock from 'mock-fs'
|
||||||
const chai = require('chai')
|
import chai from 'chai'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict'
|
import Liquid from '../../src'
|
||||||
const Liquid = require('../..')
|
import chai from 'chai'
|
||||||
const chai = require('chai')
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -1,6 +1,7 @@
|
|||||||
const Liquid = require('../..')
|
import Liquid from '../../src'
|
||||||
const mock = require('mock-fs')
|
import mock from 'mock-fs'
|
||||||
const chai = require('chai')
|
import chai from 'chai'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -1,5 +1,6 @@
|
|||||||
const Liquid = require('../..')
|
import Liquid from '../../src'
|
||||||
const chai = require('chai')
|
import chai from 'chai'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const Liquid = require('../..')
|
import Liquid from '../../src'
|
||||||
const chai = require('chai')
|
import chai from 'chai'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -1,5 +1,6 @@
|
|||||||
const Liquid = require('../..')
|
import Liquid from '../../src'
|
||||||
const chai = require('chai')
|
import chai from 'chai'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
|
|||||||
+9
-7
@@ -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 expect = chai.expect
|
||||||
const mock = require('mock-fs')
|
|
||||||
const path = require('path')
|
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
let engine = require('../..')()
|
let engine = Liquid()
|
||||||
let strictEngine = require('../..')({
|
let strictEngine = Liquid({
|
||||||
strict_variables: true,
|
strict_variables: true,
|
||||||
strict_filters: true
|
strict_filters: true
|
||||||
})
|
})
|
||||||
@@ -95,7 +97,7 @@ describe('error', function () {
|
|||||||
|
|
||||||
describe('RenderError', function () {
|
describe('RenderError', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
engine = require('../..')({
|
engine = Liquid({
|
||||||
root: '/'
|
root: '/'
|
||||||
})
|
})
|
||||||
engine.registerTag('throwingTag', {
|
engine.registerTag('throwingTag', {
|
||||||
@@ -269,7 +271,7 @@ describe('error', function () {
|
|||||||
|
|
||||||
describe('ParseError', function () {
|
describe('ParseError', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
engine = require('../..')()
|
engine = Liquid()
|
||||||
engine.registerTag('throwsOnParse', {
|
engine.registerTag('throwsOnParse', {
|
||||||
parse: function () {
|
parse: function () {
|
||||||
throw new Error('intended parse error')
|
throw new Error('intended parse error')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import chai from 'chai'
|
import chai from 'chai'
|
||||||
import sinon from 'sinon'
|
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'
|
import _ from '../../src/util/underscore.js'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
@@ -17,10 +17,10 @@ describe('util/underscore', function () {
|
|||||||
input: 'xx'
|
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 () {
|
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 () {
|
describe('.isString()', function () {
|
||||||
|
|||||||
+14
-13
@@ -1,6 +1,7 @@
|
|||||||
const chai = require('chai')
|
import {resolve} from '../../src/util/url.js'
|
||||||
|
import chai from 'chai'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
const url = require('../../src/util/url.js')
|
|
||||||
|
|
||||||
describe('util/url', function () {
|
describe('util/url', function () {
|
||||||
if (process.version.match(/^v(\d+)/)[1] < 8) {
|
if (process.version.match(/^v(\d+)/)[1] < 8) {
|
||||||
@@ -22,41 +23,41 @@ describe('util/url', function () {
|
|||||||
describe('resolve', function () {
|
describe('resolve', function () {
|
||||||
describe('root', function () {
|
describe('root', function () {
|
||||||
it('should support width relative path', 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')
|
.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')
|
.to.equal('https://example.com/foo/bar/views/foo')
|
||||||
})
|
})
|
||||||
it('should support width absolute path', function () {
|
it('should support width absolute path', function () {
|
||||||
expect(url.resolve('/views', 'foo'))
|
expect(resolve('/views', 'foo'))
|
||||||
.to.equal('https://example.com/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')
|
.to.equal('https://example.com/views/foo')
|
||||||
})
|
})
|
||||||
it('should support with empty', function () {
|
it('should support with empty', function () {
|
||||||
expect(url.resolve('', 'page.html'))
|
expect(resolve('', 'page.html'))
|
||||||
.to.equal('https://example.com/foo/bar/page.html')
|
.to.equal('https://example.com/foo/bar/page.html')
|
||||||
})
|
})
|
||||||
it('should support with url', function () {
|
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')
|
.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')
|
.to.equal('https://example.com/views/page.html')
|
||||||
})
|
})
|
||||||
it('should get the first value when argument is array', function () {
|
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')
|
.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')
|
.to.equal('https://example.com/views/page.html')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
describe('path', function () {
|
describe('path', function () {
|
||||||
it('should support width relative 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')
|
.to.equal('https://example.com/foo/bar/views/page.html')
|
||||||
})
|
})
|
||||||
it('should support with absolute path', function () {
|
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')
|
.to.equal('https://example.com/page.html')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
const chai = require('chai')
|
import chai from 'chai'
|
||||||
const expect = chai.expect
|
import Liquid from '../src'
|
||||||
const Liquid = require('..')
|
|
||||||
const liquid = new Liquid()
|
const liquid = new Liquid()
|
||||||
|
const expect = chai.expect
|
||||||
chai.use(require('chai-as-promised'))
|
chai.use(require('chai-as-promised'))
|
||||||
|
|
||||||
const cases = [
|
const cases = [
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import Liquid from '..'
|
import Liquid from '../src'
|
||||||
import sinon from 'sinon'
|
import sinon from 'sinon'
|
||||||
import chai from 'chai'
|
import chai from 'chai'
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|||||||
Reference in New Issue
Block a user