Make runMethod calls public, add some comments

This commit is contained in:
Adam Fowler
2021-03-15 14:27:32 +00:00
parent e0a0b3fe8e
commit e2cfbb7acc
3 changed files with 61 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
/// Context that current object is being rendered in. Only really relevant when rendering a sequence
struct HBMustacheContext: HBMustacheMethods {
var first: Bool
var last: Bool
@@ -10,6 +11,17 @@ struct HBMustacheContext: HBMustacheMethods {
self.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":
@@ -18,10 +30,6 @@ struct HBMustacheContext: HBMustacheMethods {
return self.last
case "index":
return self.index
case "even":
return (self.index & 1) == 0
case "odd":
return (self.index & 1) == 1
default:
return nil
}