chore(TypeScript): demo for typescript

This commit is contained in:
harttle
2019-02-17 14:22:13 +08:00
parent 677e8511e6
commit 7ee87008c7
22 changed files with 9062 additions and 53 deletions
+15 -1
View File
@@ -4,9 +4,23 @@ const engine = new Liquid({
root: __dirname,
extname: '.liquid'
})
engine.registerTag('header', {
parse: function (token) {
const [key, val] = token.args.split(':')
this[key] = val
},
render: function (scope, hash) {
const title = this.liquid.evalValue(this.content, scope)
return `<h1>${title}</h1>`
}
})
const ctx = {
todos: ['fork and clone', 'make it better', 'make a pull request'],
title: 'Welcome to liquidjs!'
}
engine.renderFile('todolist', ctx).then(console.log)
engine.renderFile('todolist', ctx)
.then(console.log)
.catch(err => console.error(err.stack))
+12
View File
@@ -0,0 +1,12 @@
{
"name": "Node.js demo for liquidjs",
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"liquidjs": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/liquidjs/-/liquidjs-7.0.0.tgz",
"integrity": "sha512-/JL+VQUI++6iCS7JQ4fPPeji6vyvHCU/iuz2bLSiE0tn0eO3kf8GEyfaXnQUHSroy8SmJu7HQIvjvOErtYEvUg=="
}
}
}
+11
View File
@@ -0,0 +1,11 @@
{
"name": "liquidjs-demo-nodejs",
"description": "Node.js demo for liquidjs",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"liquidjs": "^7.0.0"
}
}
+2
View File
@@ -1,3 +1,5 @@
{%header content: "welcome to liquid" | capitalize%}
<ul>
{% for todo in todos %}
<li>{{forloop.index}} - {{todo}}</li>