Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extend not rendered when wrapped by with #129

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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