liquidjs
Version:
A simple, expressive and safe Shopify / Github Pages compatible template engine in pure JavaScript.
25 lines (20 loc) • 576 B
JavaScript
const Liquid = require('..').Liquid
const contextArg = process.argv.slice(2)[0]
let context = {}
if (contextArg) {
if (contextArg.endsWith('.json')) {
const fs = require('fs')
context = JSON.parse(fs.readFileSync(contextArg, 'utf8'))
} else {
context = JSON.parse(contextArg)
}
}
let tpl = ''
process.stdin.on('data', chunk => (tpl += chunk))
process.stdin.on('end', () => render(tpl))
async function render (tpl) {
const liquid = new Liquid()
const html = await liquid.parseAndRender(tpl, context)
process.stdout.write(html)
}