mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
* Fix Path Traversal fallback * Update loader.ts Fixed nested * Update loader.ts padding fix * refactor: reuse root enforcing * docs: update test case and docs --------- Co-authored-by: MorielHarush <[email protected]>
31 lines
864 B
JavaScript
31 lines
864 B
JavaScript
import { Liquid } from 'liquidjs'
|
|
|
|
const engine = new Liquid({
|
|
extname: '.liquid',
|
|
globals: { title: 'LiquidJS Demo' },
|
|
// root files for `.render()` and `.parse()`
|
|
root: process.cwd(),
|
|
// layout files for `{% layout %}`
|
|
layouts: process.cwd() + '/layouts',
|
|
// partial files for `{% include %}` and `{% render %}`
|
|
partials: [process.cwd() + '/partials', 'node_modules']
|
|
})
|
|
|
|
const ctx = {
|
|
todos: ['fork and clone', 'make it better', 'make a pull request']
|
|
}
|
|
|
|
async function main () {
|
|
console.log('==========renderFile===========')
|
|
const html = await engine.renderFile('todolist', ctx)
|
|
console.log(html)
|
|
|
|
console.log('===========Streamed===========')
|
|
const tpls = await engine.parseFile('todolist')
|
|
engine.renderToNodeStream(tpls, ctx)
|
|
.on('data', data => process.stdout.write(data))
|
|
.on('end', () => console.log(''))
|
|
}
|
|
|
|
main()
|