Fix custom-tags to make it clear where the implementation is (#671)

This commit is contained in:
dannflor 2022-06-27 13:42:02 -06:00 committed by GitHub
parent 4e170d1b7e
commit f7fa29d260
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 13 deletions

View File

@ -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