Closed gwynne closed 2 years ago
this pull request is great, but I found a bug.
1: add a route like this, and pass empty list to todoList parameter
func routes(_ app: Application) throws {
app.get { req async throws -> View in
let context = DemoModel(title: "Demo", todoList: [])
return try await req.view.render("demo", context)
}
}
struct DemoModel: Encodable {
let title: String
let todoList: [String]
}
2: in leaf template file, use #count() tag to check the todoList count
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>#(title)</title>
</head>
<body>
#if(count(todoList) > 0):
<h1>#(title)</h1>
#else:
<h1>#(title)</h1>
#endif
</body>
</html>
when visit this page on browser will encounter error:
{
"error": true,
"reason": "Unable to convert count parameter to LeafData collection"
}
and I tested leaf 4.2.0, it work right!
cc @gwynne looks like some behaviour has changed here
Yeah, to say the least... I'll add some more tests to cover whatever this turns out to be.
Nope, this is a bug. I'll be pushing a fix for it shortly.
That should do it 🤞
Types which use
superEncoder(forKey:)
in theirCodable
conformance (such as Fluent models) can now safely be provided to Leaf views as context objects. In general, handling of context encoding is significantly improved.LeafError
now conforms toAbortError
andDebuggableError
for improved error UI/UX.