Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Dec 29, 2017
1 parent 9f6e9f2 commit 757a06e
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 112 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
@@ -0,0 +1,3 @@
node_modules
dist
coverage
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
56 changes: 27 additions & 29 deletions 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)
})
}
})
}
32 changes: 15 additions & 17 deletions 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()
}
})
}
36 changes: 17 additions & 19 deletions 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)
}
})
}
36 changes: 17 additions & 19 deletions 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)
}
})
}
55 changes: 28 additions & 27 deletions 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)
}
})
}

0 comments on commit 757a06e

Please sign in to comment.