Skip to content

Commit

Permalink
Add #dumpContext tag (#113)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Aug 18, 2022
1 parent 00c2f2c commit c67a1b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Sources/LeafKit/LeafSyntax/LeafTag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public var defaultTags: [String: LeafTag] = [
"contains": Contains(),
"date": DateTag(),
"count": Count(),
"comment": Comment()
"comment": Comment(),
"dumpContext": DumpContext()
]

struct UnsafeHTML: UnsafeUnescapedLeafTag {
Expand Down Expand Up @@ -108,3 +109,10 @@ struct Comment: LeafTag {
LeafData.trueNil
}
}

struct DumpContext: LeafTag {
func render(_ ctx: LeafContext) throws -> LeafData {
try ctx.requireParameterCount(0)
return LeafData(.dictionary(ctx.data))
}
}
12 changes: 12 additions & 0 deletions Tests/LeafKitTests/TagTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ class TagTests: XCTestCase {
try XCTAssertEqual(render(template, ["now": .int(now)]), expected)
}

func testDumpContext() throws {
let data: [String: LeafData] = ["value": 12345]
let template = """
dumpContext should output debug description #dumpContext
"""

let expected = """
dumpContext should output debug description [value: "12345"]
"""

try XCTAssertEqual(render(template, data), expected)
}

func testPerformance() throws {
let template = """
Expand Down

0 comments on commit c67a1b0

Please sign in to comment.