HBMustacheMethods -> HBMustacheTransformable
HBMustacheContext -> HBMustacheSequenceContext
This commit is contained in:
Adam Fowler
2021-03-19 14:48:44 +00:00
parent 09f5c5953e
commit f9f8c1320a
4 changed files with 44 additions and 44 deletions

View File

@@ -1,41 +0,0 @@
/// Context that current object is being rendered in. Only really relevant when rendering a sequence
struct HBMustacheContext: HBMustacheMethods {
var first: Bool
var last: Bool
var index: Int
init(first: Bool = false, last: Bool = false) {
self.first = first
self.last = last
index = 0
}
/// Apply method to `HBMustacheContext`. These are available when processing elements
/// of a sequence.
///
/// Format your mustache as follows to accept them. They look like a function without any arguments
/// ```
/// {{#sequence}}{{index()}}{{/sequence}}
/// ```
///
/// Methods available are `first`, `last`, and `index`
/// - Parameter name: Method name
/// - Returns: Result
func runMethod(_ name: String) -> Any? {
switch name {
case "first":
return first
case "last":
return last
case "index":
return index
case "even":
return (index & 1) == 0
case "odd":
return (index & 1) == 1
default:
return nil
}
}
}