From 187c7f977c30281fec050c3d74d995914b11e09d Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Mon, 3 May 2021 17:05:17 +0100 Subject: [PATCH] Help text for HBMustacheCustomRenderable --- Sources/HummingbirdMustache/CustomRenderable.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/HummingbirdMustache/CustomRenderable.swift b/Sources/HummingbirdMustache/CustomRenderable.swift index b409f9b..307360b 100644 --- a/Sources/HummingbirdMustache/CustomRenderable.swift +++ b/Sources/HummingbirdMustache/CustomRenderable.swift @@ -14,16 +14,24 @@ import Foundation +/// Allow object to override standard hummingbird type rendering which uses +/// `String(describing)`. public protocol HBMustacheCustomRenderable { + /// Custom rendered version of object var renderText: String { get } + /// Whether the object is a null object. Used when scoping sections var isNull: Bool { get } } extension HBMustacheCustomRenderable { + /// default version returning the standard rendering var renderText: String { String(describing: self) } + /// default version returning false var isNull: Bool { false } } +/// Extend NSNull to conform to `HBMustacheCustomRenderable` to avoid outputting `` and returning +/// a valid response for `isNull` extension NSNull: HBMustacheCustomRenderable { public var renderText: String { "" } public var isNull: Bool { true }