mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
feat: support layout none, closes #299
This commit is contained in:
@@ -14,12 +14,18 @@ export default {
|
|||||||
render: function * (ctx: Context, emitter: Emitter) {
|
render: function * (ctx: Context, emitter: Emitter) {
|
||||||
const { liquid, hash, file } = this
|
const { liquid, hash, file } = this
|
||||||
const { renderer } = liquid
|
const { renderer } = liquid
|
||||||
|
if (file.getText() === 'none') {
|
||||||
|
ctx.setRegister('blockMode', BlockMode.OUTPUT)
|
||||||
|
const html = yield renderer.renderTemplates(this.tpls, ctx)
|
||||||
|
emitter.write(html)
|
||||||
|
return
|
||||||
|
}
|
||||||
const filepath = ctx.opts.dynamicPartials
|
const filepath = ctx.opts.dynamicPartials
|
||||||
? (TypeGuards.isQuotedToken(file)
|
? (TypeGuards.isQuotedToken(file)
|
||||||
? yield renderer.renderTemplates(liquid.parse(evalQuotedToken(file)), ctx)
|
? yield renderer.renderTemplates(liquid.parse(evalQuotedToken(file)), ctx)
|
||||||
: evalToken(this.file, ctx))
|
: evalToken(this.file, ctx))
|
||||||
: file.getText()
|
: file.getText()
|
||||||
assert(filepath, () => `illegal filename "${file.getText()}":"${filepath}"`)
|
assert(filepath, () => `file "${file.getText()}"("${filepath}") not available`)
|
||||||
const templates = yield liquid._parseFile(filepath, ctx.opts, ctx.sync)
|
const templates = yield liquid._parseFile(filepath, ctx.opts, ctx.sync)
|
||||||
|
|
||||||
// render remaining contents and store rendered results
|
// render remaining contents and store rendered results
|
||||||
|
|||||||
@@ -38,9 +38,16 @@ describe('tags/layout', function () {
|
|||||||
})
|
})
|
||||||
return liquid.renderFile('/parent.html').catch(function (e) {
|
return liquid.renderFile('/parent.html').catch(function (e) {
|
||||||
expect(e.name).to.equal('RenderError')
|
expect(e.name).to.equal('RenderError')
|
||||||
expect(e.message).to.match(/illegal filename "foo":"undefined"/)
|
expect(e.message).to.contain('file "foo"("undefined") not available')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
it('should handle layout none', async function () {
|
||||||
|
const src = '{% layout none %}' +
|
||||||
|
'{%block a%}A{%endblock%}' +
|
||||||
|
'B'
|
||||||
|
const html = await liquid.parseAndRender(src)
|
||||||
|
return expect(html).to.equal('AB')
|
||||||
|
})
|
||||||
describe('anonymous block', function () {
|
describe('anonymous block', function () {
|
||||||
it('should handle anonymous block', async function () {
|
it('should handle anonymous block', async function () {
|
||||||
mock({
|
mock({
|
||||||
|
|||||||
Reference in New Issue
Block a user