diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..0e75fe557 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +node_modules +dist +coverage diff --git a/package.json b/package.json index 0d26ff873..41e985c6d 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Liquid template engine by pure JavaScript: compatible to shopify, easy to extend.", "main": "index.js", "scripts": { - "lint": "eslint src/ test/", + "lint": "eslint .", "test": "mocha --recursive", "coverage": "NODE_ENV=test istanbul cover --report html ./node_modules/mocha/bin/_mocha -- -R spec --recursive", "lcov": "NODE_ENV=test istanbul cover --report lcovonly ./node_modules/mocha/bin/_mocha -- -R spec --recursive", diff --git a/tags/capture.js b/tags/capture.js index da3fd3f2b..6dfee73dc 100644 --- a/tags/capture.js +++ b/tags/capture.js @@ -1,32 +1,30 @@ -const Liquid = require('..'); -const lexical = Liquid.lexical; -const re = new RegExp(`(${lexical.identifier.source})`); -const assert = require('../src/util/assert.js'); +const Liquid = require('..') +const lexical = Liquid.lexical +const re = new RegExp(`(${lexical.identifier.source})`) +const assert = require('../src/util/assert.js') -module.exports = function(liquid) { +module.exports = function (liquid) { + liquid.registerTag('capture', { + parse: function (tagToken, remainTokens) { + var match = tagToken.args.match(re) + assert(match, `${tagToken.args} not valid identifier`) - liquid.registerTag('capture', { - parse: function(tagToken, remainTokens) { - var match = tagToken.args.match(re); - assert(match, `${tagToken.args} not valid identifier`); + this.variable = match[1] + this.templates = [] - this.variable = match[1]; - this.templates = []; - - var stream = liquid.parser.parseStream(remainTokens); - stream.on('tag:endcapture', token => stream.stop()) - .on('template', tpl => this.templates.push(tpl)) - .on('end', x => { - throw new Error(`tag ${tagToken.raw} not closed`); - }); - stream.start(); - }, - render: function(scope, hash) { - return liquid.renderer.renderTemplates(this.templates, scope) - .then((html) => { - scope.set(this.variable, html); - }); - } - }); - -}; + var stream = liquid.parser.parseStream(remainTokens) + stream.on('tag:endcapture', token => stream.stop()) + .on('template', tpl => this.templates.push(tpl)) + .on('end', x => { + throw new Error(`tag ${tagToken.raw} not closed`) + }) + stream.start() + }, + render: function (scope, hash) { + return liquid.renderer.renderTemplates(this.templates, scope) + .then((html) => { + scope.set(this.variable, html) + }) + } + }) +} diff --git a/tags/comment.js b/tags/comment.js index e702fd0da..dc915f2dc 100644 --- a/tags/comment.js +++ b/tags/comment.js @@ -1,17 +1,15 @@ -module.exports = function(liquid) { - - liquid.registerTag('comment', { - parse: function(tagToken, remainTokens) { - var stream = liquid.parser.parseStream(remainTokens); - stream - .on('token', token => { - if(token.name === 'endcomment') stream.stop(); - }) - .on('end', x => { - throw new Error(`tag ${tagToken.raw} not closed`); - }); - stream.start(); - } - }); - -}; +module.exports = function (liquid) { + liquid.registerTag('comment', { + parse: function (tagToken, remainTokens) { + var stream = liquid.parser.parseStream(remainTokens) + stream + .on('token', token => { + if (token.name === 'endcomment') stream.stop() + }) + .on('end', x => { + throw new Error(`tag ${tagToken.raw} not closed`) + }) + stream.start() + } + }) +} diff --git a/tags/decrement.js b/tags/decrement.js index 1e5274406..080914821 100644 --- a/tags/decrement.js +++ b/tags/decrement.js @@ -1,20 +1,18 @@ -const Liquid = require('..'); -const lexical = Liquid.lexical; -const assert = require('../src/util/assert.js'); +const Liquid = require('..') +const lexical = Liquid.lexical +const assert = require('../src/util/assert.js') -module.exports = function(liquid) { - - liquid.registerTag('decrement', { - parse: function(token) { - var match = token.args.match(lexical.identifier); - assert(match, `illegal identifier ${token.args}`); - this.variable = match[0]; - }, - render: function(scope, hash) { - var v = scope.get(this.variable); - if (typeof v !== 'number') v = 0; - scope.set(this.variable, v - 1); - } - }); - -}; +module.exports = function (liquid) { + liquid.registerTag('decrement', { + parse: function (token) { + var match = token.args.match(lexical.identifier) + assert(match, `illegal identifier ${token.args}`) + this.variable = match[0] + }, + render: function (scope, hash) { + var v = scope.get(this.variable) + if (typeof v !== 'number') v = 0 + scope.set(this.variable, v - 1) + } + }) +} diff --git a/tags/increment.js b/tags/increment.js index ada4aeb89..ddba6fc85 100644 --- a/tags/increment.js +++ b/tags/increment.js @@ -1,20 +1,18 @@ -const Liquid = require('..'); -const assert = require('../src/util/assert.js'); -const lexical = Liquid.lexical; +const Liquid = require('..') +const assert = require('../src/util/assert.js') +const lexical = Liquid.lexical -module.exports = function(liquid) { - - liquid.registerTag('increment', { - parse: function(token) { - var match = token.args.match(lexical.identifier); - assert(match, `illegal identifier ${token.args}`); - this.variable = match[0]; - }, - render: function(scope, hash) { - var v = scope.get(this.variable); - if (typeof v !== 'number') v = 0; - scope.set(this.variable, v + 1); - } - }); - -}; +module.exports = function (liquid) { + liquid.registerTag('increment', { + parse: function (token) { + var match = token.args.match(lexical.identifier) + assert(match, `illegal identifier ${token.args}`) + this.variable = match[0] + }, + render: function (scope, hash) { + var v = scope.get(this.variable) + if (typeof v !== 'number') v = 0 + scope.set(this.variable, v + 1) + } + }) +} diff --git a/tags/unless.js b/tags/unless.js index e865ddfb2..0123be2c2 100644 --- a/tags/unless.js +++ b/tags/unless.js @@ -1,30 +1,31 @@ -const Liquid = require('..'); +const Liquid = require('..') -module.exports = function(liquid) { - liquid.registerTag('unless', { - parse: function(tagToken, remainTokens) { - this.templates = []; - this.elseTemplates = []; - var p, stream = liquid.parser.parseStream(remainTokens) - .on('start', x => { - p = this.templates; - this.cond = tagToken.args; - }) - .on('tag:else', token => p = this.elseTemplates) - .on('tag:endunless', token => stream.stop()) - .on('template', tpl => p.push(tpl)) - .on('end', x => { - throw new Error(`tag ${tagToken.raw} not closed`); - }); +module.exports = function (liquid) { + liquid.registerTag('unless', { + parse: function (tagToken, remainTokens) { + this.templates = [] + this.elseTemplates = [] + let p + let stream = liquid.parser.parseStream(remainTokens) + .on('start', x => { + p = this.templates + this.cond = tagToken.args + }) + .on('tag:else', () => (p = this.elseTemplates)) + .on('tag:endunless', token => stream.stop()) + .on('template', tpl => p.push(tpl)) + .on('end', x => { + throw new Error(`tag ${tagToken.raw} not closed`) + }) - stream.start(); - }, + stream.start() + }, - render: function(scope, hash) { - var cond = Liquid.evalExp(this.cond, scope); - return Liquid.isFalsy(cond) ? - liquid.renderer.renderTemplates(this.templates, scope) : - liquid.renderer.renderTemplates(this.elseTemplates, scope); - } - }); -}; + render: function (scope, hash) { + let cond = Liquid.evalExp(this.cond, scope) + return Liquid.isFalsy(cond) + ? liquid.renderer.renderTemplates(this.templates, scope) + : liquid.renderer.renderTemplates(this.elseTemplates, scope) + } + }) +}