Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CallumTodd7 opened this issue Aug 9, 2024 · 2 comments

Comments

@CallumTodd7
Copy link

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: ""
@adam-fowler
Copy link
Member

Currently it isn't possible to add additional transforms to a type that already has transforms. What is the transform you want to add? I assume it isn't the appendWithCake function.

@CallumTodd7
Copy link
Author

Ah, that's a shame. Thanks for the reply.

I was looking to add a UTF8 base64 encoding transform. Not a huge issue for me now as I've got it working without transforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants