Closed Qqwy closed 8 years ago
Seems like a good idea forcing a bit more that the correct datatypes are used for assigns. Though not seeing precisely how to implement it. But that is more that i'm not that experienced yet with working with protocols.
Converting this project to latest elixir version and bringing it in line with the shopify liquid was one of the first things I did in liquid. And now about 1+ days a week on elixir project starting to get more understanding. And using that knowledge to refactor and improve this project some more.
Sounds like a great idea, Protocols are the way to go for this functionality.
The most important ones are implemented using protocols now.
Liquid-elixir takes maps as input that use binaries as keys. When someone defines a struct somewhere, it will have atoms as keys.
This distinction is fine. I'd argue that the explicit need for transposing a struct into something that liquid-elixir can understand makes it easier for people to remember to only allow access to the fields that are deemed 'safe' for the purpose they'll be used in.
The 'gospel' Ruby implementation of Liquid did this by introducing the 'Drop', which are some kind of presenter-abstraction. This is a very OOP-like solution, and is not something what we want nor need.
However, what might be interesting to make this even more clear, is to create a protocol that people can implement for their custom data types, which outputs a format that liquid-elixir understands. (Such as a map with binary-keys, or just a plain string). Liquid-elixir could then call this protocol on everything that is passed in (implementations for the default data types being provided to have strings and maps pass through without changes), and this would make it even more explicit how the library should be used.
Is this a good idea or not?