mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-19 06:20:38 -07:00
feat: move filters/tags to instances, fixes #188
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { assert } from '../../util/assert'
|
||||
import { identifier } from '../../parser/lexical'
|
||||
import { ITagImplOptions, TagToken, Context } from '../../types'
|
||||
import { TagImplOptions, TagToken, Context } from '../../types'
|
||||
|
||||
const re = new RegExp(`(${identifier.source})\\s*=([^]*)`)
|
||||
|
||||
@@ -14,4 +14,4 @@ export default {
|
||||
render: function * (ctx: Context) {
|
||||
ctx.front()[this.key] = yield this.liquid._evalValue(this.value, ctx)
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import BlockMode from '../../context/block-mode'
|
||||
import { ParseStream, TagToken, Token, ITemplate, Context, ITagImplOptions, Emitter, Hash } from '../../types'
|
||||
import { ParseStream, TagToken, Token, Template, Context, TagImplOptions, Emitter, Hash } from '../../types'
|
||||
|
||||
export default {
|
||||
parse: function (token: TagToken, remainTokens: Token[]) {
|
||||
const match = /\w+/.exec(token.args)
|
||||
this.block = match ? match[0] : ''
|
||||
this.tpls = [] as ITemplate[]
|
||||
this.tpls = [] as Template[]
|
||||
const stream: ParseStream = this.liquid.parser.parseStream(remainTokens)
|
||||
.on('tag:endblock', () => stream.stop())
|
||||
.on('template', (tpl: ITemplate) => this.tpls.push(tpl))
|
||||
.on('template', (tpl: Template) => this.tpls.push(tpl))
|
||||
.on('end', () => {
|
||||
throw new Error(`tag ${token.raw} not closed`)
|
||||
})
|
||||
@@ -28,4 +28,4 @@ export default {
|
||||
}
|
||||
emitter.write(html)
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { assert } from '../../util/assert'
|
||||
import { identifier } from '../../parser/lexical'
|
||||
import { ITemplate, Context, ITagImplOptions, TagToken, Token } from '../../types'
|
||||
import { Template, Context, TagImplOptions, TagToken, Token } from '../../types'
|
||||
|
||||
const re = new RegExp(`(${identifier.source})`)
|
||||
|
||||
@@ -14,7 +14,7 @@ export default {
|
||||
|
||||
const stream = this.liquid.parser.parseStream(remainTokens)
|
||||
stream.on('tag:endcapture', () => stream.stop())
|
||||
.on('template', (tpl: ITemplate) => this.templates.push(tpl))
|
||||
.on('template', (tpl: Template) => this.templates.push(tpl))
|
||||
.on('end', () => {
|
||||
throw new Error(`tag ${tagToken.raw} not closed`)
|
||||
})
|
||||
@@ -25,4 +25,4 @@ export default {
|
||||
const html = yield r.renderTemplates(this.templates, ctx)
|
||||
ctx.front()[this.variable] = html
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Expression, Hash, Emitter, TagToken, Token, Context, ITemplate, ITagImplOptions, ParseStream } from '../../types'
|
||||
import { Expression, Hash, Emitter, TagToken, Token, Context, Template, TagImplOptions, ParseStream } from '../../types'
|
||||
|
||||
export default {
|
||||
parse: function (tagToken: TagToken, remainTokens: Token[]) {
|
||||
@@ -6,7 +6,7 @@ export default {
|
||||
this.cases = []
|
||||
this.elseTemplates = []
|
||||
|
||||
let p: ITemplate[] = []
|
||||
let p: Template[] = []
|
||||
const stream: ParseStream = this.liquid.parser.parseStream(remainTokens)
|
||||
.on('tag:when', (token: TagToken) => {
|
||||
this.cases.push({
|
||||
@@ -16,7 +16,7 @@ export default {
|
||||
})
|
||||
.on('tag:else', () => (p = this.elseTemplates))
|
||||
.on('tag:endcase', () => stream.stop())
|
||||
.on('template', (tpl: ITemplate) => p.push(tpl))
|
||||
.on('template', (tpl: Template) => p.push(tpl))
|
||||
.on('end', () => {
|
||||
throw new Error(`tag ${tagToken.raw} not closed`)
|
||||
})
|
||||
@@ -37,4 +37,4 @@ export default {
|
||||
}
|
||||
yield r.renderTemplates(this.elseTemplates, ctx, emitter)
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { TagToken } from '../../parser/tag-token'
|
||||
import { Token } from '../../parser/token'
|
||||
import { ITagImplOptions } from '../../template/tag/itag-impl-options'
|
||||
import { TagImplOptions } from '../../template/tag/tag-impl-options'
|
||||
|
||||
export default {
|
||||
parse: function (tagToken: TagToken, remainTokens: Token[]) {
|
||||
@@ -14,4 +14,4 @@ export default {
|
||||
})
|
||||
stream.start()
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { assert } from '../../util/assert'
|
||||
import { value as rValue } from '../../parser/lexical'
|
||||
import { Emitter, Expression, TagToken, Context, ITagImplOptions, Hash } from '../../types'
|
||||
import { Emitter, Expression, TagToken, Context, TagImplOptions, Hash } from '../../types'
|
||||
|
||||
const groupRE = new RegExp(`^(?:(${rValue.source})\\s*:\\s*)?(.*)$`)
|
||||
const candidatesRE = new RegExp(rValue.source, 'g')
|
||||
@@ -37,4 +37,4 @@ export default {
|
||||
const html = yield new Expression(candidate).value(ctx)
|
||||
emitter.write(html)
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { assert } from '../../util/assert'
|
||||
import { identifier } from '../../parser/lexical'
|
||||
import { Emitter, TagToken, Context, ITagImplOptions, Hash } from '../../types'
|
||||
import { Emitter, TagToken, Context, TagImplOptions, Hash } from '../../types'
|
||||
import { isNumber, stringify } from '../../util/underscore'
|
||||
|
||||
export default {
|
||||
@@ -16,4 +16,4 @@ export default {
|
||||
}
|
||||
emitter.write(stringify(--scope[this.variable]))
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Emitter, TagToken, Token, Context, ITemplate, ITagImplOptions, ParseStream } from '../../types'
|
||||
import { Emitter, TagToken, Token, Context, Template, TagImplOptions, ParseStream } from '../../types'
|
||||
import { isString, isObject, isArray } from '../../util/underscore'
|
||||
import { Expression } from '../../render/expression'
|
||||
import { assert } from '../../util/assert'
|
||||
@@ -29,7 +29,7 @@ export default {
|
||||
.on('start', () => (p = this.templates))
|
||||
.on('tag:else', () => (p = this.elseTemplates))
|
||||
.on('tag:endfor', () => stream.stop())
|
||||
.on('template', (tpl: ITemplate) => p.push(tpl))
|
||||
.on('template', (tpl: Template) => p.push(tpl))
|
||||
.on('end', () => {
|
||||
throw new Error(`tag ${tagToken.raw} not closed`)
|
||||
})
|
||||
@@ -72,4 +72,4 @@ export default {
|
||||
}
|
||||
ctx.pop()
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Hash, Emitter, isTruthy, Expression, TagToken, Token, Context, ITemplate, ITagImplOptions, ParseStream } from '../../types'
|
||||
import { Hash, Emitter, isTruthy, Expression, TagToken, Token, Context, Template, TagImplOptions, ParseStream } from '../../types'
|
||||
|
||||
export default {
|
||||
parse: function (tagToken: TagToken, remainTokens: Token[]) {
|
||||
@@ -19,7 +19,7 @@ export default {
|
||||
})
|
||||
.on('tag:else', () => (p = this.elseTemplates))
|
||||
.on('tag:endif', () => stream.stop())
|
||||
.on('template', (tpl: ITemplate) => p.push(tpl))
|
||||
.on('template', (tpl: Template) => p.push(tpl))
|
||||
.on('end', () => {
|
||||
throw new Error(`tag ${tagToken.raw} not closed`)
|
||||
})
|
||||
@@ -39,4 +39,4 @@ export default {
|
||||
}
|
||||
yield r.renderTemplates(this.elseTemplates, ctx, emitter)
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { assert } from '../../util/assert'
|
||||
import { Expression, Hash, Emitter, TagToken, Context, ITagImplOptions } from '../../types'
|
||||
import { Expression, Hash, Emitter, TagToken, Context, TagImplOptions } from '../../types'
|
||||
import { value, quotedLine } from '../../parser/lexical'
|
||||
import BlockMode from '../../context/block-mode'
|
||||
|
||||
@@ -46,4 +46,4 @@ export default {
|
||||
ctx.setRegister('blocks', originBlocks)
|
||||
ctx.setRegister('blockMode', originBlockMode)
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { assert } from '../../util/assert'
|
||||
import { identifier } from '../../parser/lexical'
|
||||
import { isNumber, stringify } from '../../util/underscore'
|
||||
import { Emitter, TagToken, Context, ITagImplOptions, Hash } from '../../types'
|
||||
import { Emitter, TagToken, Context, TagImplOptions, Hash } from '../../types'
|
||||
|
||||
export default {
|
||||
parse: function (token: TagToken) {
|
||||
@@ -18,4 +18,4 @@ export default {
|
||||
scope[this.variable]++
|
||||
emitter.write(stringify(val))
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -16,9 +16,9 @@ import tablerow from './tablerow'
|
||||
import unless from './unless'
|
||||
import Break from './break'
|
||||
import Continue from './continue'
|
||||
import { ITagImplOptions } from '../../template/tag/itag-impl-options'
|
||||
import { TagImplOptions } from '../../template/tag/tag-impl-options'
|
||||
|
||||
const tags: { [key: string]: ITagImplOptions } = {
|
||||
const tags: { [key: string]: TagImplOptions } = {
|
||||
assign, 'for': For, capture, 'case': Case, comment, include, render, decrement, increment, cycle, 'if': If, layout, block, raw, tablerow, unless, 'break': Break, 'continue': Continue
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { assert } from '../../util/assert'
|
||||
import { value as rValue } from '../../parser/lexical'
|
||||
import { Emitter, Hash, Expression, TagToken, Token, Context, ITagImplOptions } from '../../types'
|
||||
import { Emitter, Hash, Expression, TagToken, Token, Context, TagImplOptions } from '../../types'
|
||||
import BlockMode from '../../context/block-mode'
|
||||
|
||||
const staticFileRE = /\S+/
|
||||
@@ -40,4 +40,4 @@ export default {
|
||||
ctx.pop()
|
||||
emitter.write(partial)
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TagToken, Token, ITagImplOptions } from '../../types'
|
||||
import { TagToken, Token, TagImplOptions } from '../../types'
|
||||
|
||||
export default {
|
||||
parse: function (tagToken: TagToken, remainTokens: Token[]) {
|
||||
@@ -18,4 +18,4 @@ export default {
|
||||
render: function () {
|
||||
return this.tokens.map((token: Token) => token.raw).join('')
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { assert } from '../../util/assert'
|
||||
import { Expression, Hash, Emitter, TagToken, Context, ITagImplOptions } from '../../types'
|
||||
import { Expression, Hash, Emitter, TagToken, Context, TagImplOptions } from '../../types'
|
||||
import { value, quotedLine } from '../../parser/lexical'
|
||||
import BlockMode from '../../context/block-mode'
|
||||
|
||||
@@ -47,4 +47,4 @@ export default {
|
||||
childCtx.setRegister('blocks', originBlocks)
|
||||
childCtx.setRegister('blockMode', originBlockMode)
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { assert } from '../../util/assert'
|
||||
import { Expression, Emitter, Hash, TagToken, Token, Context, ITemplate, ITagImplOptions, ParseStream } from '../../types'
|
||||
import { Expression, Emitter, Hash, TagToken, Token, Context, Template, TagImplOptions, ParseStream } from '../../types'
|
||||
import { identifier, value, hash } from '../../parser/lexical'
|
||||
import { TablerowloopDrop } from '../../drop/tablerowloop-drop'
|
||||
|
||||
@@ -20,7 +20,7 @@ export default {
|
||||
const stream: ParseStream = this.liquid.parser.parseStream(remainTokens)
|
||||
.on('start', () => (p = this.templates))
|
||||
.on('tag:endtablerow', () => stream.stop())
|
||||
.on('template', (tpl: ITemplate) => p.push(tpl))
|
||||
.on('template', (tpl: Template) => p.push(tpl))
|
||||
.on('end', () => {
|
||||
throw new Error(`tag ${tagToken.raw} not closed`)
|
||||
})
|
||||
@@ -54,4 +54,4 @@ export default {
|
||||
if (collection.length) emitter.write('</tr>')
|
||||
ctx.pop()
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Emitter, Expression, isFalsy, ParseStream, Context, ITagImplOptions, Token, Hash, TagToken } from '../../types'
|
||||
import { Emitter, Expression, isFalsy, ParseStream, Context, TagImplOptions, Token, Hash, TagToken } from '../../types'
|
||||
|
||||
export default {
|
||||
parse: function (tagToken: TagToken, remainTokens: Token[]) {
|
||||
@@ -27,4 +27,4 @@ export default {
|
||||
? r.renderTemplates(this.templates, ctx, emitter)
|
||||
: r.renderTemplates(this.elseTemplates, ctx, emitter))
|
||||
}
|
||||
} as ITagImplOptions
|
||||
} as TagImplOptions
|
||||
|
||||
Reference in New Issue
Block a user