fix linting

This commit is contained in:
harttle
2017-12-29 12:14:01 +08:00
parent 9f6e9f2f3f
commit 757a06ee83
7 changed files with 108 additions and 112 deletions
+3
View File
@@ -0,0 +1,3 @@
node_modules
dist
coverage
+1 -1
View File
@@ -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",
+27 -29
View File
@@ -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)
})
}
})
}
+15 -17
View File
@@ -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()
}
})
}
+17 -19
View File
@@ -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)
}
})
}
+17 -19
View File
@@ -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)
}
})
}
+28 -27
View File
@@ -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)
}
})
}