mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
feat: with & for in render tag, closes #195
This commit is contained in:
@@ -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
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user