mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e2dded8fb |
@@ -53,6 +53,7 @@ For more details, refer to the [Setup Guide][setup].
|
||||
## Who's Using LiquidJS?
|
||||
|
||||
- [Eleventy](https://www.11ty.dev/): Eleventy, a simpler static site generator.
|
||||
- [Github Docs](https://github.com/github/docs): The open-source repo for docs.github.com.
|
||||
- [Opensense](https://www.opensense.com/): The smarter way to send email.
|
||||
- [Directus](https://docs.directus.io/): an instant REST+GraphQL API and intuitive no-code data collaboration app for any SQL database.
|
||||
- [Semgrep](https://github.com/returntocorp/semgrep): Lightweight static analysis for many languages.
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Emitter, SimpleEmitter } from '../emitters'
|
||||
import { Drop } from './drop'
|
||||
|
||||
export class BlockDrop extends Drop {
|
||||
constructor (
|
||||
// the block render from layout template
|
||||
private superBlockRender: () => Iterable<any> = () => ''
|
||||
private superBlockRender: (emitter: Emitter) => IterableIterator<unknown> | string = () => ''
|
||||
) {
|
||||
super()
|
||||
}
|
||||
@@ -11,7 +12,9 @@ export class BlockDrop extends Drop {
|
||||
* Provide parent access in child block by
|
||||
* {{ block.super }}
|
||||
*/
|
||||
public super () {
|
||||
return this.superBlockRender()
|
||||
public * super (): IterableIterator<unknown> {
|
||||
const emitter = new SimpleEmitter()
|
||||
yield this.superBlockRender(emitter)
|
||||
return emitter.buffer
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -39,7 +39,11 @@ export default class extends Tag {
|
||||
ctx.pop()
|
||||
}
|
||||
return renderChild
|
||||
? (superBlock: BlockDrop, emitter: Emitter) => renderChild(new BlockDrop(() => renderCurrent(superBlock, emitter)), emitter)
|
||||
? (superBlock: BlockDrop, emitter: Emitter) => renderChild(
|
||||
new BlockDrop(
|
||||
(emitter: Emitter) => renderCurrent(superBlock, emitter)
|
||||
),
|
||||
emitter)
|
||||
: renderCurrent
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +101,26 @@ describe('tags/layout', function () {
|
||||
const output = '<link href="base.css" rel="stylesheet"><link href="extra.css" rel="stylesheet">'
|
||||
return expect(html).toBe(output)
|
||||
})
|
||||
it('should pass block.super as a string', async function () {
|
||||
mock({
|
||||
'/parent.html': '{% block css %}<link href="base.css" rel="stylesheet">{% endblock %}'
|
||||
})
|
||||
const src = '{% layout "parent.html" %}' +
|
||||
'{%block css%}{{block.super}}<meta basesize={{block.super | size}}>{%endblock%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
const output = '<link href="base.css" rel="stylesheet"><meta basesize=39>'
|
||||
return expect(html).toBe(output)
|
||||
})
|
||||
it('should support block.super while strictVariables', async function () {
|
||||
mock({
|
||||
'/parent.html': '{% block css %}<link href="base.css" rel="stylesheet">{% endblock %}'
|
||||
})
|
||||
const src = '{% layout "parent.html" %}' +
|
||||
'{%block css%}{{block.super}}<link href="extra.css" rel="stylesheet">{%endblock%}'
|
||||
const html = await liquid.parseAndRender(src, undefined, { strictVariables: true })
|
||||
const output = '<link href="base.css" rel="stylesheet"><link href="extra.css" rel="stylesheet">'
|
||||
return expect(html).toBe(output)
|
||||
})
|
||||
it('should render block.super to empty if no parent exists', async function () {
|
||||
mock({
|
||||
'/parent.html': '{% block css %}{{block.super}}<link href="base.css" rel="stylesheet">{% endblock %}'
|
||||
|
||||
Reference in New Issue
Block a user