mirror of
https://github.com/harttle/liquidjs.git
synced 2026-10-03 00:55:13 -07:00
fix linting
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
coverage
|
||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
"description": "Liquid template engine by pure JavaScript: compatible to shopify, easy to extend.",
|
"description": "Liquid template engine by pure JavaScript: compatible to shopify, easy to extend.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint src/ test/",
|
"lint": "eslint .",
|
||||||
"test": "mocha --recursive",
|
"test": "mocha --recursive",
|
||||||
"coverage": "NODE_ENV=test istanbul cover --report html ./node_modules/mocha/bin/_mocha -- -R spec --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",
|
"lcov": "NODE_ENV=test istanbul cover --report lcovonly ./node_modules/mocha/bin/_mocha -- -R spec --recursive",
|
||||||
|
|||||||
+19
-21
@@ -1,32 +1,30 @@
|
|||||||
const Liquid = require('..');
|
const Liquid = require('..')
|
||||||
const lexical = Liquid.lexical;
|
const lexical = Liquid.lexical
|
||||||
const re = new RegExp(`(${lexical.identifier.source})`);
|
const re = new RegExp(`(${lexical.identifier.source})`)
|
||||||
const assert = require('../src/util/assert.js');
|
const assert = require('../src/util/assert.js')
|
||||||
|
|
||||||
module.exports = function(liquid) {
|
|
||||||
|
|
||||||
|
module.exports = function (liquid) {
|
||||||
liquid.registerTag('capture', {
|
liquid.registerTag('capture', {
|
||||||
parse: function(tagToken, remainTokens) {
|
parse: function (tagToken, remainTokens) {
|
||||||
var match = tagToken.args.match(re);
|
var match = tagToken.args.match(re)
|
||||||
assert(match, `${tagToken.args} not valid identifier`);
|
assert(match, `${tagToken.args} not valid identifier`)
|
||||||
|
|
||||||
this.variable = match[1];
|
this.variable = match[1]
|
||||||
this.templates = [];
|
this.templates = []
|
||||||
|
|
||||||
var stream = liquid.parser.parseStream(remainTokens);
|
var stream = liquid.parser.parseStream(remainTokens)
|
||||||
stream.on('tag:endcapture', token => stream.stop())
|
stream.on('tag:endcapture', token => stream.stop())
|
||||||
.on('template', tpl => this.templates.push(tpl))
|
.on('template', tpl => this.templates.push(tpl))
|
||||||
.on('end', x => {
|
.on('end', x => {
|
||||||
throw new Error(`tag ${tagToken.raw} not closed`);
|
throw new Error(`tag ${tagToken.raw} not closed`)
|
||||||
});
|
})
|
||||||
stream.start();
|
stream.start()
|
||||||
},
|
},
|
||||||
render: function(scope, hash) {
|
render: function (scope, hash) {
|
||||||
return liquid.renderer.renderTemplates(this.templates, scope)
|
return liquid.renderer.renderTemplates(this.templates, scope)
|
||||||
.then((html) => {
|
.then((html) => {
|
||||||
scope.set(this.variable, html);
|
scope.set(this.variable, html)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
}
|
||||||
};
|
|
||||||
|
|||||||
+9
-11
@@ -1,17 +1,15 @@
|
|||||||
module.exports = function(liquid) {
|
module.exports = function (liquid) {
|
||||||
|
|
||||||
liquid.registerTag('comment', {
|
liquid.registerTag('comment', {
|
||||||
parse: function(tagToken, remainTokens) {
|
parse: function (tagToken, remainTokens) {
|
||||||
var stream = liquid.parser.parseStream(remainTokens);
|
var stream = liquid.parser.parseStream(remainTokens)
|
||||||
stream
|
stream
|
||||||
.on('token', token => {
|
.on('token', token => {
|
||||||
if(token.name === 'endcomment') stream.stop();
|
if (token.name === 'endcomment') stream.stop()
|
||||||
})
|
})
|
||||||
.on('end', x => {
|
.on('end', x => {
|
||||||
throw new Error(`tag ${tagToken.raw} not closed`);
|
throw new Error(`tag ${tagToken.raw} not closed`)
|
||||||
});
|
})
|
||||||
stream.start();
|
stream.start()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
}
|
||||||
};
|
|
||||||
|
|||||||
+14
-16
@@ -1,20 +1,18 @@
|
|||||||
const Liquid = require('..');
|
const Liquid = require('..')
|
||||||
const lexical = Liquid.lexical;
|
const lexical = Liquid.lexical
|
||||||
const assert = require('../src/util/assert.js');
|
const assert = require('../src/util/assert.js')
|
||||||
|
|
||||||
module.exports = function(liquid) {
|
|
||||||
|
|
||||||
|
module.exports = function (liquid) {
|
||||||
liquid.registerTag('decrement', {
|
liquid.registerTag('decrement', {
|
||||||
parse: function(token) {
|
parse: function (token) {
|
||||||
var match = token.args.match(lexical.identifier);
|
var match = token.args.match(lexical.identifier)
|
||||||
assert(match, `illegal identifier ${token.args}`);
|
assert(match, `illegal identifier ${token.args}`)
|
||||||
this.variable = match[0];
|
this.variable = match[0]
|
||||||
},
|
},
|
||||||
render: function(scope, hash) {
|
render: function (scope, hash) {
|
||||||
var v = scope.get(this.variable);
|
var v = scope.get(this.variable)
|
||||||
if (typeof v !== 'number') v = 0;
|
if (typeof v !== 'number') v = 0
|
||||||
scope.set(this.variable, v - 1);
|
scope.set(this.variable, v - 1)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
}
|
||||||
};
|
|
||||||
|
|||||||
+14
-16
@@ -1,20 +1,18 @@
|
|||||||
const Liquid = require('..');
|
const Liquid = require('..')
|
||||||
const assert = require('../src/util/assert.js');
|
const assert = require('../src/util/assert.js')
|
||||||
const lexical = Liquid.lexical;
|
const lexical = Liquid.lexical
|
||||||
|
|
||||||
module.exports = function(liquid) {
|
|
||||||
|
|
||||||
|
module.exports = function (liquid) {
|
||||||
liquid.registerTag('increment', {
|
liquid.registerTag('increment', {
|
||||||
parse: function(token) {
|
parse: function (token) {
|
||||||
var match = token.args.match(lexical.identifier);
|
var match = token.args.match(lexical.identifier)
|
||||||
assert(match, `illegal identifier ${token.args}`);
|
assert(match, `illegal identifier ${token.args}`)
|
||||||
this.variable = match[0];
|
this.variable = match[0]
|
||||||
},
|
},
|
||||||
render: function(scope, hash) {
|
render: function (scope, hash) {
|
||||||
var v = scope.get(this.variable);
|
var v = scope.get(this.variable)
|
||||||
if (typeof v !== 'number') v = 0;
|
if (typeof v !== 'number') v = 0
|
||||||
scope.set(this.variable, v + 1);
|
scope.set(this.variable, v + 1)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
}
|
||||||
};
|
|
||||||
|
|||||||
+20
-19
@@ -1,30 +1,31 @@
|
|||||||
const Liquid = require('..');
|
const Liquid = require('..')
|
||||||
|
|
||||||
module.exports = function(liquid) {
|
module.exports = function (liquid) {
|
||||||
liquid.registerTag('unless', {
|
liquid.registerTag('unless', {
|
||||||
parse: function(tagToken, remainTokens) {
|
parse: function (tagToken, remainTokens) {
|
||||||
this.templates = [];
|
this.templates = []
|
||||||
this.elseTemplates = [];
|
this.elseTemplates = []
|
||||||
var p, stream = liquid.parser.parseStream(remainTokens)
|
let p
|
||||||
|
let stream = liquid.parser.parseStream(remainTokens)
|
||||||
.on('start', x => {
|
.on('start', x => {
|
||||||
p = this.templates;
|
p = this.templates
|
||||||
this.cond = tagToken.args;
|
this.cond = tagToken.args
|
||||||
})
|
})
|
||||||
.on('tag:else', token => p = this.elseTemplates)
|
.on('tag:else', () => (p = this.elseTemplates))
|
||||||
.on('tag:endunless', token => stream.stop())
|
.on('tag:endunless', token => stream.stop())
|
||||||
.on('template', tpl => p.push(tpl))
|
.on('template', tpl => p.push(tpl))
|
||||||
.on('end', x => {
|
.on('end', x => {
|
||||||
throw new Error(`tag ${tagToken.raw} not closed`);
|
throw new Error(`tag ${tagToken.raw} not closed`)
|
||||||
});
|
})
|
||||||
|
|
||||||
stream.start();
|
stream.start()
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function(scope, hash) {
|
render: function (scope, hash) {
|
||||||
var cond = Liquid.evalExp(this.cond, scope);
|
let cond = Liquid.evalExp(this.cond, scope)
|
||||||
return Liquid.isFalsy(cond) ?
|
return Liquid.isFalsy(cond)
|
||||||
liquid.renderer.renderTemplates(this.templates, scope) :
|
? liquid.renderer.renderTemplates(this.templates, scope)
|
||||||
liquid.renderer.renderTemplates(this.elseTemplates, scope);
|
: liquid.renderer.renderTemplates(this.elseTemplates, scope)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user