From d24655887fe2186cba143816a0495f9c93b2bbe1 Mon Sep 17 00:00:00 2001 From: Harttle Date: Wed, 14 Dec 2022 02:08:06 +0800 Subject: [PATCH] docs: update docs and demo for `Value` usage, fixes #568 --- benchmark/demo.js | 11 -- demo/nodejs/index.js | 16 +-- demo/nodejs/todolist.liquid | 2 +- demo/typescript/index.ts | 21 ++-- demo/typescript/todolist.liquid | 2 +- demo/typescript/tsconfig.json | 8 +- .../source/tutorials/register-filters-tags.md | 10 +- docs/source/tutorials/sync-and-async.md | 104 ++++++++++------- .../zh-cn/tutorials/register-filters-tags.md | 29 ++++- docs/source/zh-cn/tutorials/sync-and-async.md | 107 +++++++++++------- src/liquid.ts | 2 +- src/template/value.ts | 2 +- 12 files changed, 187 insertions(+), 127 deletions(-) diff --git a/benchmark/demo.js b/benchmark/demo.js index e049aad70..cb9f2f3c7 100755 --- a/benchmark/demo.js +++ b/benchmark/demo.js @@ -8,17 +8,6 @@ const engine = new Liquid({ extname: '.liquid' }) -engine.registerTag('header', { - parse: function (token) { - const [key, val] = token.args.split(':') - this[key] = val - }, - render: function (ctx) { - const title = this.liquid.evalValue(this.content, ctx) - return `

${title}

` - } -}) - function demo () { console.log(' demo') console.log('------------------------') diff --git a/demo/nodejs/index.js b/demo/nodejs/index.js index 8849502bc..b1a45c9ad 100644 --- a/demo/nodejs/index.js +++ b/demo/nodejs/index.js @@ -1,4 +1,4 @@ -const { Liquid } = require('liquidjs') +const { Liquid, Tag, Value } = require('liquidjs') const engine = new Liquid({ extname: '.liquid', @@ -11,13 +11,13 @@ const engine = new Liquid({ partials: './partials' }) -engine.registerTag('header', { - parse: function (token) { - const [key, val] = token.args.split(':') - this[key] = val - }, - render: async function (scope, emitter) { - const title = await this.liquid.evalValue(this.content, scope) +engine.registerTag('header', class HeaderTag extends Tag { + constructor (token, remainTokens, liquid) { + super(token, remainTokens, liquid) + this.value = new Value(token.args, liquid) + } + * render (ctx, emitter) { + const title = yield this.value.value(ctx) emitter.write(`

${title}

`) } }) diff --git a/demo/nodejs/todolist.liquid b/demo/nodejs/todolist.liquid index e3156a889..51bbe4af9 100644 --- a/demo/nodejs/todolist.liquid +++ b/demo/nodejs/todolist.liquid @@ -1,5 +1,5 @@ {% layout 'html.liquid' %} -{%header content: title | capitalize%} +{%header title | capitalize%}