feat: with & for in render tag, closes #195

This commit is contained in:
harttle
2020-03-04 07:08:54 +08:00
parent aa27a6cd7b
commit 6ea6881f08
67 changed files with 1108 additions and 724 deletions
+43
View File
@@ -0,0 +1,43 @@
#!/usr/bin/env node
function isQuote (c) {
return c === '"' || c === "'"
}
function isOperator (c) {
return '!=<>'.includes(c)
}
function isNumber (c) {
return c >= '0' && c <= '9'
}
function isCharacter (c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
}
function isVariable (c) {
return '_-?'.includes(c) || isCharacter(c) || isNumber(c)
}
function isBlank (c) {
return c === '\n' || c === '\t' || c === ' ' || c === '\r'
}
const types = []
for (let i = 0; i < 128; i++) {
const c = String.fromCharCode(i)
let n = 0
if (isVariable(c)) n |= 1
if (isOperator(c)) n |= 2
if (isBlank(c)) n |= 4
if (isQuote(c)) n |= 8
types.push(n)
}
console.log(`
const TYPES = '${types.join('')}'
const VARIABLE = 1
const OPERATOR = 2
const BLANK = 4
const QUOTE = 8
`.trim())
+3 -3
View File
@@ -1,8 +1,8 @@
#!/usr/bin/env node
const Liquid = require('..').Liquid
var contextArg = process.argv.slice(2)[0]
var context = {}
const contextArg = process.argv.slice(2)[0]
let context = {}
if (contextArg) {
if (contextArg.endsWith('.json')) {
@@ -20,5 +20,5 @@ process.stdin.on('end', () => render(tpl))
async function render (tpl) {
const liquid = new Liquid()
const html = await liquid.parseAndRender(tpl, context)
console.log(html)
process.stdout.write(html)
}