From f7fa29d26084a8c17b6fe2441e5e09b293e2c419 Mon Sep 17 00:00:00 2001 From: dannflor <59743986+dannflor@users.noreply.github.com> Date: Mon, 27 Jun 2022 13:42:02 -0600 Subject: [PATCH] Fix custom-tags to make it clear where the implementation is (#671) --- docs/leaf/custom-tags.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/docs/leaf/custom-tags.md b/docs/leaf/custom-tags.md index 2f17ff2d..bfd86394 100644 --- a/docs/leaf/custom-tags.md +++ b/docs/leaf/custom-tags.md @@ -22,20 +22,22 @@ Now let's implement the `render(_:)` method. The `LeafContext` context passed to ```swift struct NowTagError: Error {} -let formatter = DateFormatter() -switch ctx.parameters.count { -case 0: formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" -case 1: - guard let string = ctx.parameters[0].string else { - throw NowTagError() - } - formatter.dateFormat = string -default: - throw NowTagError() +func render(_ ctx: LeafContext) throws -> LeafData { + let formatter = DateFormatter() + switch ctx.parameters.count { + case 0: formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" + case 1: + guard let string = ctx.parameters[0].string else { + throw NowTagError() + } + formatter.dateFormat = string + default: + throw NowTagError() + } + + let dateAsString = formatter.string(from: Date()) + return LeafData.string(dateAsString) } - -let dateAsString = formatter.string(from: Date()) -return LeafData.string(dateAsString) ``` !!! tip