Skip to content

Commit

Permalink
chore(TypeScript): demo for typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Feb 17, 2019
1 parent 677e851 commit 7ee8700
Show file tree
Hide file tree
Showing 22 changed files with 9,062 additions and 53 deletions.
4 changes: 2 additions & 2 deletions demo/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

<head>
<title>liquidjs for the browser</title>
<script src="../../dist/liquid.js"></script>
<script src="node_modules/liquidjs/dist/liquid.min.js"></script>
</head>

<body>
<script>
var engine = window.Liquid({
var engine = new window.Liquid({
extname: '.html',
cache: true
});
Expand Down
220 changes: 220 additions & 0 deletions demo/browser/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions demo/browser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "liquidjs-demo-browser",
"version": "1.0.0",
"description": "Liquidjs Demo for Browser Usage",
"main": "index.html",
"scripts": {
"start": "http-server -c-1 "
},
"author": "harttle <[email protected]>",
"license": "ISC",
"devDependencies": {
"http-server": "^0.11.1"
},
"dependencies": {
"liquidjs": "^7.0.0"
}
}
16 changes: 15 additions & 1 deletion demo/nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 12 additions & 0 deletions demo/nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions demo/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions demo/nodejs/todolist.liquid
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{%header content: "welcome to liquid" | capitalize%}

<ul>
{% for todo in todos %}
<li>{{forloop.index}} - {{todo}}</li>
Expand Down
16 changes: 14 additions & 2 deletions demo/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import Liquid, {isTruthy} from 'liquidjs'
import Liquid from 'liquidjs'

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!'
}

// console.log('isTruthy:', isTruthy('a string here'));
engine.renderFile('todolist', ctx).then(console.log)
engine.renderFile('todolist', ctx).then(console.log)
Loading

0 comments on commit 7ee8700

Please sign in to comment.