Skip to content

Commit

Permalink
Fix extend not rendered when wrapped by with
Browse files Browse the repository at this point in the history
When an `#extend` was wrapped by a `#with`, the `#extend` wasn't rendered.

Fixes #128
  • Loading branch information
benblakely committed Dec 8, 2023
1 parent 547a134 commit 63f8ad9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/LeafKit/LeafSyntax/LeafSyntax.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ extension Syntax: BodiedSyntax {
.custom(let bS as BodiedSyntax),
.export(let bS as BodiedSyntax),
.extend(let bS as BodiedSyntax),
.with(let bS as BodiedSyntax),
.loop(let bS as BodiedSyntax): return bS.externals()
default: return .init()
}
Expand Down Expand Up @@ -125,6 +126,7 @@ extension Syntax: BodiedSyntax {
.custom(let bS as BodiedSyntax),
.export(let bS as BodiedSyntax),
.extend(let bS as BodiedSyntax),
.with(let bS as BodiedSyntax),
.loop(let bS as BodiedSyntax): result += bS.inlineRefs(externals, imports)
case .expression(let pDA): result.append(.expression(pDA.inlineImports(imports)))
// .variable, .raw
Expand Down
28 changes: 28 additions & 0 deletions Tests/LeafKitTests/LeafTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,34 @@ final class LeafTests: XCTestCase {
try XCTAssertEqual(render(template, ["parent": ["child": "Elizabeth"]]), expected)
}

func testWithWrappingExtend() throws {
let header = """
<h1>#(child)</h1>
"""

let base = """
<body>#with(parent):<main>#extend("header")</main>#endwith</body>
"""

let expected = """
<body><main><h1>Elizabeth</h1></main></body>
"""

let headerAST = try LeafAST(name: "header", ast: parse(header))
let baseAST = try LeafAST(name: "base", ast: parse(base))

let baseResolved = LeafAST(from: baseAST, referencing: ["header": headerAST])

var serializer = LeafSerializer(
ast: baseResolved.ast,
ignoreUnfoundImports: false
)
let view = try serializer.serialize(context: ["parent": ["child": "Elizabeth"]])
let str = view.getString(at: view.readerIndex, length: view.readableBytes) ?? ""

XCTAssertEqual(str, expected)
}

func testExtendWithSugar() throws {
let header = """
<h1>#(child)</h1>
Expand Down

0 comments on commit 63f8ad9

Please sign in to comment.