mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
fix: address refactor comments
This commit is contained in:
committed by
Jun Yang
parent
b8e4b3337b
commit
6a0ad102a8
@@ -20,7 +20,7 @@ export default {
|
||||
const r = this.liquid.renderer
|
||||
const html = childDefined !== undefined
|
||||
? childDefined
|
||||
: yield r.renderTemplates(this.tpls, ctx, new Emitter(ctx.opts.keepOutputType))
|
||||
: yield r.renderTemplates(this.tpls, ctx)
|
||||
|
||||
if (ctx.getRegister('blockMode', BlockMode.OUTPUT) === BlockMode.STORE) {
|
||||
blocks[this.block] = html
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Tokenizer, assert, Template, Context, TagImplOptions, TagToken, TopLevelToken } from '../../types'
|
||||
import { evalQuotedToken } from '../../render/expression'
|
||||
import { Emitter } from '../../render/emitter'
|
||||
|
||||
export default {
|
||||
parse: function (tagToken: TagToken, remainTokens: TopLevelToken[]) {
|
||||
@@ -20,7 +19,7 @@ export default {
|
||||
},
|
||||
render: function * (ctx: Context) {
|
||||
const r = this.liquid.renderer
|
||||
const html = yield r.renderTemplates(this.templates, ctx, new Emitter(ctx.opts.keepOutputType))
|
||||
const html = yield r.renderTemplates(this.templates, ctx)
|
||||
ctx.bottom()[this.variable] = html
|
||||
}
|
||||
} as TagImplOptions
|
||||
|
||||
@@ -26,7 +26,7 @@ export default {
|
||||
const { renderer } = liquid
|
||||
const filepath = ctx.opts.dynamicPartials
|
||||
? (TypeGuards.isQuotedToken(file)
|
||||
? yield renderer.renderTemplates(liquid.parse(evalQuotedToken(file)), ctx, new Emitter(ctx.opts.keepOutputType))
|
||||
? yield renderer.renderTemplates(liquid.parse(evalQuotedToken(file)), ctx)
|
||||
: yield evalToken(file, ctx))
|
||||
: file.getText()
|
||||
assert(filepath, () => `illegal filename "${file.getText()}":"${filepath}"`)
|
||||
|
||||
@@ -16,7 +16,7 @@ export default {
|
||||
const { renderer } = liquid
|
||||
const filepath = ctx.opts.dynamicPartials
|
||||
? (TypeGuards.isQuotedToken(file)
|
||||
? yield renderer.renderTemplates(liquid.parse(evalQuotedToken(file)), ctx, new Emitter(ctx.opts.keepOutputType))
|
||||
? yield renderer.renderTemplates(liquid.parse(evalQuotedToken(file)), ctx)
|
||||
: evalToken(this.file, ctx))
|
||||
: file.getText()
|
||||
assert(filepath, () => `illegal filename "${file.getText()}":"${filepath}"`)
|
||||
@@ -24,12 +24,12 @@ export default {
|
||||
// render the remaining tokens immediately
|
||||
ctx.setRegister('blockMode', BlockMode.STORE)
|
||||
const blocks = ctx.getRegister('blocks')
|
||||
const html = yield renderer.renderTemplates(this.tpls, ctx, new Emitter(ctx.opts.keepOutputType))
|
||||
const html = yield renderer.renderTemplates(this.tpls, ctx)
|
||||
if (blocks[''] === undefined) blocks[''] = html
|
||||
const templates = yield liquid._parseFile(filepath, ctx.opts, ctx.sync)
|
||||
ctx.push(yield hash.render(ctx))
|
||||
ctx.setRegister('blockMode', BlockMode.OUTPUT)
|
||||
const partial = yield renderer.renderTemplates(templates, ctx, new Emitter(ctx.opts.keepOutputType))
|
||||
const partial = yield renderer.renderTemplates(templates, ctx)
|
||||
ctx.pop()
|
||||
emitter.write(partial)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export default {
|
||||
const { renderer } = liquid
|
||||
const filepath = ctx.opts.dynamicPartials
|
||||
? (TypeGuards.isQuotedToken(file)
|
||||
? yield renderer.renderTemplates(liquid.parse(evalQuotedToken(file)), ctx, new Emitter(ctx.opts.keepOutputType))
|
||||
? yield renderer.renderTemplates(liquid.parse(evalQuotedToken(file)), ctx)
|
||||
: evalToken(file, ctx))
|
||||
: file.getText()
|
||||
assert(filepath, () => `illegal filename "${file.getText()}":"${filepath}"`)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { stringify, toValue } from '../util/underscore'
|
||||
|
||||
export class Emitter {
|
||||
public html: any = '';
|
||||
public break = false;
|
||||
@@ -9,6 +11,11 @@ export class Emitter {
|
||||
}
|
||||
|
||||
public write (html: any) {
|
||||
if (this.keepOutputType === true) {
|
||||
html = toValue(html)
|
||||
} else {
|
||||
html = stringify(toValue(html))
|
||||
}
|
||||
// This will only preserve the type if the value is isolated.
|
||||
// I.E:
|
||||
// {{ my-port }} -> 42
|
||||
|
||||
@@ -4,7 +4,10 @@ import { Template } from '../template/template'
|
||||
import { Emitter } from './emitter'
|
||||
|
||||
export class Render {
|
||||
public * renderTemplates (templates: Template[], ctx: Context, emitter: Emitter): IterableIterator<any> {
|
||||
public * renderTemplates (templates: Template[], ctx: Context, emitter?: Emitter): IterableIterator<any> {
|
||||
if (!emitter) {
|
||||
emitter = new Emitter(ctx.opts.keepOutputType)
|
||||
}
|
||||
for (const tpl of templates) {
|
||||
try {
|
||||
const html = yield tpl.render(ctx, emitter)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Value } from './value'
|
||||
import { FilterMap } from './filter/filter-map'
|
||||
import { stringify, toValue } from '../util/underscore'
|
||||
import { TemplateImpl } from '../template/template-impl'
|
||||
import { Template } from '../template/template'
|
||||
import { Context } from '../context/context'
|
||||
@@ -16,10 +15,6 @@ export class Output extends TemplateImpl<OutputToken> implements Template {
|
||||
}
|
||||
public * render (ctx: Context, emitter: Emitter) {
|
||||
const val = yield this.value.value(ctx)
|
||||
if (ctx.opts.keepOutputType) {
|
||||
emitter.write(toValue(val))
|
||||
} else {
|
||||
emitter.write(stringify(toValue(val)))
|
||||
}
|
||||
emitter.write(val)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user