Skip to content

Add or override transforms for a type the library already provides an implementation for? #45

Description

@CallumTodd7

I'm struggling to add a custom transform for a string value. Is this supported by the library?

import Mustache

public extension StringProtocol {
  func transform(_ name: String) -> Any? {
    switch name {
    case "appendWithCake":
      self + "cake"
    default:
      nil
    }
  }
}

extension String: MustacheTransformable {}
extension Substring: MustacheTransformable {}
let template = try MustacheTemplate(string: """
{{ appendWithCake(value) }}
""")
let object: [String: Any] = ["value": "Cup"]
XCTAssertEqual(template.render(object), "Cupcake") // Actual: ""

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions