-
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
185 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
import { Liquid, TagToken, Context, Emitter } from 'liquidjs' | ||
import { Value, Liquid, TagToken, Context, Emitter, Tag, TopLevelToken } from 'liquidjs' | ||
|
||
const engine = new Liquid({ | ||
root: __dirname, | ||
extname: '.liquid' | ||
}) | ||
|
||
engine.registerTag('header', { | ||
parse: function (token: TagToken) { | ||
const [key, val] = token.args.split(':') | ||
this[key] = val | ||
}, | ||
render: async function (context: Context, emitter: Emitter) { | ||
const title = await this.liquid.evalValue(this['content'], context) | ||
engine.registerTag('header', class HeaderTag extends Tag { | ||
private value: Value | ||
constructor (token: TagToken, remainTokens: TopLevelToken[], liquid: Liquid) { | ||
super(token, remainTokens, liquid) | ||
this.value = new Value(token.args, liquid) | ||
} | ||
* render (ctx: Context, emitter: Emitter) { | ||
const title = yield this.value.value(ctx) | ||
emitter.write(`<h1>${title}</h1>`) | ||
} | ||
}) | ||
|
||
const ctx = { | ||
const scope = { | ||
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', scope).then(console.log) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{%header content: title | capitalize%} | ||
{%header title | capitalize%} | ||
|
||
<ul> | ||
{% for todo in todos %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"types": [ | ||
"node" | ||
] | ||
"target": "es6", | ||
"moduleResolution": "node", | ||
"types": [ | ||
"node" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.