Help text for HBMustacheCustomRenderable

This commit is contained in:
Adam Fowler
2021-05-03 17:05:17 +01:00
parent c65a7956c8
commit 187c7f977c

View File

@@ -14,16 +14,24 @@
import Foundation import Foundation
/// Allow object to override standard hummingbird type rendering which uses
/// `String(describing)`.
public protocol HBMustacheCustomRenderable { public protocol HBMustacheCustomRenderable {
/// Custom rendered version of object
var renderText: String { get } var renderText: String { get }
/// Whether the object is a null object. Used when scoping sections
var isNull: Bool { get } var isNull: Bool { get }
} }
extension HBMustacheCustomRenderable { extension HBMustacheCustomRenderable {
/// default version returning the standard rendering
var renderText: String { String(describing: self) } var renderText: String { String(describing: self) }
/// default version returning false
var isNull: Bool { false } var isNull: Bool { false }
} }
/// Extend NSNull to conform to `HBMustacheCustomRenderable` to avoid outputting `<null>` and returning
/// a valid response for `isNull`
extension NSNull: HBMustacheCustomRenderable { extension NSNull: HBMustacheCustomRenderable {
public var renderText: String { "" } public var renderText: String { "" }
public var isNull: Bool { true } public var isNull: Bool { true }