Make runMethod calls public, add some comments
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user