Skip to content

Commit c67a1b0

Browse files
marius-se0xTim
andauthored
Add #dumpContext tag (#113)
* add dumpContext tag * remove additional context data in test Co-authored-by: Marius Seufzer <marius.seufzer@protonmail.com> Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>
1 parent 00c2f2c commit c67a1b0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Sources/LeafKit/LeafSyntax/LeafTag.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public var defaultTags: [String: LeafTag] = [
1616
"contains": Contains(),
1717
"date": DateTag(),
1818
"count": Count(),
19-
"comment": Comment()
19+
"comment": Comment(),
20+
"dumpContext": DumpContext()
2021
]
2122

2223
struct UnsafeHTML: UnsafeUnescapedLeafTag {
@@ -108,3 +109,10 @@ struct Comment: LeafTag {
108109
LeafData.trueNil
109110
}
110111
}
112+
113+
struct DumpContext: LeafTag {
114+
func render(_ ctx: LeafContext) throws -> LeafData {
115+
try ctx.requireParameterCount(0)
116+
return LeafData(.dictionary(ctx.data))
117+
}
118+
}

Tests/LeafKitTests/TagTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ class TagTests: XCTestCase {
176176
try XCTAssertEqual(render(template, ["now": .int(now)]), expected)
177177
}
178178

179+
func testDumpContext() throws {
180+
let data: [String: LeafData] = ["value": 12345]
181+
let template = """
182+
dumpContext should output debug description #dumpContext
183+
"""
184+
185+
let expected = """
186+
dumpContext should output debug description [value: "12345"]
187+
"""
188+
189+
try XCTAssertEqual(render(template, data), expected)
190+
}
179191

180192
func testPerformance() throws {
181193
let template = """

0 commit comments

Comments
 (0)