mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
chore(TypeScript): demo for typescript
This commit is contained in:
@@ -8,6 +8,7 @@ import { evalValue } from 'src/render/syntax'
|
||||
* hash['foo'] === 'bar'
|
||||
*/
|
||||
export default class Hash {
|
||||
[key: string]: any
|
||||
constructor(markup, scope) {
|
||||
let match
|
||||
hashCapture.lastIndex = 0
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import Scope from 'src/scope/scope'
|
||||
import TagToken from 'src/parser/tag-token'
|
||||
import Token from 'src/parser/token'
|
||||
import Hash from 'src/template/tag/hash'
|
||||
import ITagImpl from './itag-impl'
|
||||
|
||||
export default interface ITagImplOptions {
|
||||
parse?: (this: ITagImpl, token: TagToken, remainingTokens: Array<Token>) => void
|
||||
render?: (this: ITagImpl, scope: Scope, hash: Hash) => string | Promise<string>
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import Liquid from 'src/liquid'
|
||||
import ITagImplOptions from './itag-impl-options'
|
||||
|
||||
export default interface ITagImpl extends ITagImplOptions {
|
||||
liquid: Liquid
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import { create } from 'src/util/underscore'
|
||||
import { stringify } from 'src/util/underscore'
|
||||
import assert from 'src/util/assert'
|
||||
import TagImpl from './tagimpl'
|
||||
import ITagImpl from './itag-impl'
|
||||
import ITagImplOptions from './itag-impl-options'
|
||||
import Liquid from 'src/liquid'
|
||||
import Hash from './hash'
|
||||
import Template from 'src/template/template'
|
||||
import ITemplate from 'src/template/itemplate'
|
||||
@@ -10,10 +12,10 @@ import TagToken from 'src/parser/tag-token'
|
||||
export default class Tag extends Template implements ITemplate {
|
||||
name: string
|
||||
token: TagToken
|
||||
private impl: TagImpl
|
||||
private impl: ITagImpl
|
||||
static impls: object = {}
|
||||
|
||||
constructor (token, tokens, liquid) {
|
||||
constructor (token, tokens, liquid: Liquid) {
|
||||
super(token)
|
||||
this.name = token.name
|
||||
|
||||
@@ -34,7 +36,7 @@ export default class Tag extends Template implements ITemplate {
|
||||
const html = await impl.render(scope, hash)
|
||||
return stringify(html)
|
||||
}
|
||||
static register (name, tag) {
|
||||
static register (name: string, tag: ITagImplOptions) {
|
||||
Tag.impls[name] = tag
|
||||
}
|
||||
static clear () {
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import Liquid from 'src/liquid'
|
||||
import Scope from 'src/scope/scope'
|
||||
|
||||
export default interface TagImpl {
|
||||
liquid: Liquid
|
||||
parse: (token: any, remainingTokens: Array<any>) => void
|
||||
render: (scope: Scope, hash: any) => Promise<string>
|
||||
}
|
||||
Reference in New Issue
Block a user