Skip to content

Commit

Permalink
feat: move filters/tags to instances, fixes #188
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Mar 2, 2020
1 parent f676207 commit df8a919
Show file tree
Hide file tree
Showing 47 changed files with 240 additions and 221 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"no-unused-vars": "off",
"indent": "off",
"no-dupe-class-members": "off",
"no-useless-constructor": "off",
"@typescript-eslint/indent": ["error", 2],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-empty-function": "off",
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@types/benchmark": "^1.0.31",
"@types/chai": "^4.1.7",
"@types/chai-as-promised": "^7.1.0",
"@types/express": "^4.16.1",
"@types/express": "^4.17.2",
"@types/jsdom": "^12.2.2",
"@types/mocha": "^5.2.6",
"@types/sinon": "^7.0.6",
Expand Down Expand Up @@ -118,6 +118,7 @@
{
"assets": [
"package.json",
"package-lock.json",
"docs",
"CHANGELOG.md"
],
Expand Down
4 changes: 2 additions & 2 deletions src/builtin/tags/assign.ts
Original file line number Diff line number Diff line change
@@ -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*=([^]*)`)

Expand All @@ -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
8 changes: 4 additions & 4 deletions src/builtin/tags/block.ts
Original file line number Diff line number Diff line change
@@ -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`)
})
Expand All @@ -28,4 +28,4 @@ export default {
}
emitter.write(html)
}
} as ITagImplOptions
} as TagImplOptions
6 changes: 3 additions & 3 deletions src/builtin/tags/capture.ts
Original file line number Diff line number Diff line change
@@ -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})`)

Expand All @@ -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`)
})
Expand All @@ -25,4 +25,4 @@ export default {
const html = yield r.renderTemplates(this.templates, ctx)
ctx.front()[this.variable] = html
}
} as ITagImplOptions
} as TagImplOptions
8 changes: 4 additions & 4 deletions src/builtin/tags/case.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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[]) {
this.cond = tagToken.args
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({
Expand All @@ -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`)
})
Expand All @@ -37,4 +37,4 @@ export default {
}
yield r.renderTemplates(this.elseTemplates, ctx, emitter)
}
} as ITagImplOptions
} as TagImplOptions
4 changes: 2 additions & 2 deletions src/builtin/tags/comment.ts
Original file line number Diff line number Diff line change
@@ -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[]) {
Expand All @@ -14,4 +14,4 @@ export default {
})
stream.start()
}
} as ITagImplOptions
} as TagImplOptions
4 changes: 2 additions & 2 deletions src/builtin/tags/cycle.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -37,4 +37,4 @@ export default {
const html = yield new Expression(candidate).value(ctx)
emitter.write(html)
}
} as ITagImplOptions
} as TagImplOptions
4 changes: 2 additions & 2 deletions src/builtin/tags/decrement.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -16,4 +16,4 @@ export default {
}
emitter.write(stringify(--scope[this.variable]))
}
} as ITagImplOptions
} as TagImplOptions
6 changes: 3 additions & 3 deletions src/builtin/tags/for.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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`)
})
Expand Down Expand Up @@ -72,4 +72,4 @@ export default {
}
ctx.pop()
}
} as ITagImplOptions
} as TagImplOptions
6 changes: 3 additions & 3 deletions src/builtin/tags/if.ts
Original file line number Diff line number Diff line change
@@ -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[]) {
Expand All @@ -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`)
})
Expand All @@ -39,4 +39,4 @@ export default {
}
yield r.renderTemplates(this.elseTemplates, ctx, emitter)
}
} as ITagImplOptions
} as TagImplOptions
4 changes: 2 additions & 2 deletions src/builtin/tags/include.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -46,4 +46,4 @@ export default {
ctx.setRegister('blocks', originBlocks)
ctx.setRegister('blockMode', originBlockMode)
}
} as ITagImplOptions
} as TagImplOptions
4 changes: 2 additions & 2 deletions src/builtin/tags/increment.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -18,4 +18,4 @@ export default {
scope[this.variable]++
emitter.write(stringify(val))
}
} as ITagImplOptions
} as TagImplOptions
4 changes: 2 additions & 2 deletions src/builtin/tags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions src/builtin/tags/layout.ts
Original file line number Diff line number Diff line change
@@ -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+/
Expand Down Expand Up @@ -40,4 +40,4 @@ export default {
ctx.pop()
emitter.write(partial)
}
} as ITagImplOptions
} as TagImplOptions
4 changes: 2 additions & 2 deletions src/builtin/tags/raw.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TagToken, Token, ITagImplOptions } from '../../types'
import { TagToken, Token, TagImplOptions } from '../../types'

export default {
parse: function (tagToken: TagToken, remainTokens: Token[]) {
Expand All @@ -18,4 +18,4 @@ export default {
render: function () {
return this.tokens.map((token: Token) => token.raw).join('')
}
} as ITagImplOptions
} as TagImplOptions
4 changes: 2 additions & 2 deletions src/builtin/tags/render.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -47,4 +47,4 @@ export default {
childCtx.setRegister('blocks', originBlocks)
childCtx.setRegister('blockMode', originBlockMode)
}
} as ITagImplOptions
} as TagImplOptions
6 changes: 3 additions & 3 deletions src/builtin/tags/tablerow.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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`)
})
Expand Down Expand Up @@ -54,4 +54,4 @@ export default {
if (collection.length) emitter.write('</tr>')
ctx.pop()
}
} as ITagImplOptions
} as TagImplOptions
4 changes: 2 additions & 2 deletions src/builtin/tags/unless.ts
Original file line number Diff line number Diff line change
@@ -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[]) {
Expand Down Expand Up @@ -27,4 +27,4 @@ export default {
? r.renderTemplates(this.templates, ctx, emitter)
: r.renderTemplates(this.elseTemplates, ctx, emitter))
}
} as ITagImplOptions
} as TagImplOptions
Loading

0 comments on commit df8a919

Please sign in to comment.