mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 05:10:40 -07:00
Support create variables on the filter line.
This commit is contained in:
+3
-1
@@ -36,7 +36,9 @@ module.exports = function(options) {
|
||||
|
||||
var args = [];
|
||||
while(match = valueRE.exec(argList.trim())){
|
||||
args.push(match[0]);
|
||||
var v = match[0];
|
||||
var re = new RegExp(`${v}\\s*:`, 'g');
|
||||
re.test(match.input) ? args.push(`'${v}'`) : args.push(v);
|
||||
}
|
||||
|
||||
this.name = name;
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ var rangeLine = new RegExp(`^${rangeCapture.source}$`);
|
||||
var integerLine = new RegExp(`^${integer.source}$`);
|
||||
|
||||
// filter related
|
||||
var valueList = new RegExp(`${value.source}(\\s*,\\s*${value.source})*`);
|
||||
var valueList = new RegExp(`${value.source}(\\s*,?:?\\s*${value.source})*`);
|
||||
var filter = new RegExp(`${identifier.source}(?:\\s*:\\s*${valueList.source})?`, 'g');
|
||||
var filterCapture = new RegExp(`(${identifier.source})(?:\\s*:\\s*(${valueList.source}))?`);
|
||||
var filterLine = new RegExp(`^${filterCapture.source}$`);
|
||||
|
||||
@@ -327,4 +327,9 @@ describe('filters', function() {
|
||||
it('should encode <space>',
|
||||
() => test('{{ "Tetsuro Takara" | url_encode }}', 'Tetsuro%20Takara'));
|
||||
});
|
||||
|
||||
describe('obj_test', function() {
|
||||
liquid.registerFilter('obj_test', (...v) => v.join(','));
|
||||
it('should support object', () => test('{{ "a" | obj_test: k1: "v1", k2: "v2" }}', 'a,k1,v1,k2,v2'));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,7 +11,9 @@ describe('lexical', function() {
|
||||
lexical.filterLine.test('foo: a, "b"').should.equal(true);
|
||||
lexical.filterLine.test('abs | another').should.equal(false);
|
||||
lexical.filterLine.test('join: "," | another').should.equal(false);
|
||||
lexical.filterLine.test('obj_test: k1: "v1", k2: "v2"').should.equal(true);
|
||||
});
|
||||
|
||||
it('should test boolean literal', function() {
|
||||
lexical.isLiteral('true').should.equal(true);
|
||||
lexical.isLiteral('TrUE').should.equal(true);
|
||||
|
||||
Reference in New Issue
Block a user