mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 20:30:39 -07:00
refactor: import babelify
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
"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",
|
||||
|
||||
+5
-5
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+5
-13
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
@@ -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'))
|
||||
|
||||
|
||||
+3
-2
@@ -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'))
|
||||
|
||||
|
||||
@@ -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'))
|
||||
|
||||
|
||||
+3
-2
@@ -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'))
|
||||
|
||||
|
||||
@@ -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'))
|
||||
|
||||
|
||||
+3
-2
@@ -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'))
|
||||
|
||||
|
||||
+3
-2
@@ -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'))
|
||||
|
||||
|
||||
@@ -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'))
|
||||
|
||||
|
||||
@@ -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'))
|
||||
|
||||
|
||||
+4
-3
@@ -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'))
|
||||
|
||||
|
||||
+3
-2
@@ -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'))
|
||||
|
||||
|
||||
@@ -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'))
|
||||
|
||||
|
||||
+3
-2
@@ -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'))
|
||||
|
||||
|
||||
+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 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')
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
+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 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')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import Liquid from '..'
|
||||
import Liquid from '../src'
|
||||
import sinon from 'sinon'
|
||||
import chai from 'chai'
|
||||
const expect = chai.expect
|
||||
|
||||
Reference in New Issue
Block a user