8000 feat: support layout none, closes #299 · harttle/liquidjs@81e11bb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 81e11bb

Browse files
committed
feat: support layout none, closes #299
1 parent 71d5d24 commit 81e11bb

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/builtin/tags/layout.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@ export default {
1414
render: function * (ctx: Context, emitter: Emitter) {
1515
const { liquid, hash, file } = this
1616
const { renderer } = liquid
17+
if (file.getText() === 'none') {
18+
ctx.setRegister('blockMode', BlockMode.OUTPUT)
19+
const html = yield renderer.renderTemplates(this.tpls, ctx)
20+
emitter.write(html)
21+
return
22+
}
1723
const filepath = ctx.opts.dynamicPartials
1824
? (TypeGuards.isQuotedToken(file)
1925
? yield renderer.renderTemplates(liquid.parse(evalQuotedToken(file)), ctx)
2026
: evalToken(this.file, ctx))
2127
: file.getText()
22-
assert(filepath, () => `illegal filename "${file.getText()}":"${filepath}"`)
28+
assert(filepath, () => `file "${file.getText()}"("${filepath}") not available`)
2329
const templates = yield liquid._parseFile(filepath, ctx.opts, ctx.sync)
2430

2531
// render remaining contents and store rendered results

test/integration/builtin/tags/layout.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,16 @@ describe('tags/layout', function () {
3838
})
3939
return liquid.renderFile('/parent.html').catch(function (e) {
4040
expect(e.name).to.equal('RenderError')
41-
expect(e.message).to.match(/illegal filename "foo":"undefined"/)
41+
expect(e.message).to.contain('file "foo"("undefined") not available')
4242
})
4343
})
44+
it('should handle layout none', async function () {
45+
const src = '{% layout none %}' +
46+
'{%block a%}A{%endblock%}' +
47+
'B'
48+
const html = await liquid.parseAndRender(src)
49+
return expect(html).to.equal('AB')
50+
})
4451
describe('anonymous block', function () {
4552
it('should handle anonymous block', async function () {
4653
mock({

0 commit comments

Comments
 (0)
0