Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
108 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
dist | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
}) | ||
} |