Files
swiftpm-mustache/Sources/Mustache/CustomRenderable.swift
T. R. Bernstein 6061715025
Some checks failed
CI / macOS (push) Has been cancelled
CI / linux (swift:6.0) (push) Has been cancelled
CI / linux (swift:6.1) (push) Has been cancelled
CI / linux (swift:6.2) (push) Has been cancelled
CI / windows (6.1) (push) Has been cancelled
Adapt project for Astzweig
2025-09-29 15:03:48 +02:00

25 lines
830 B
Swift

import Foundation
/// Allow object to override standard hummingbird type rendering which uses
/// `String(describing)`.
public protocol MustacheCustomRenderable {
/// 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 MustacheCustomRenderable {
/// 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 `MustacheCustomRenderable` to avoid outputting `<null>` and returning
/// a valid response for `isNull`
extension NSNull: MustacheCustomRenderable {
public var renderText: String { "" }
public var isNull: Bool { true }
}