martenframework / marten

The pragmatic web framework.
https://martenframework.com
MIT License
415 stars 22 forks source link

Enums can not be used in templates #173

Closed notramo closed 7 months ago

notramo commented 7 months ago

It's not possible to use enums in templates, as enums can not include modules, and template values require Marten::Template::Object to be included. Maybe some automatic conversion could help with this.

ellmetha commented 7 months ago

Enums can't be used in union types, so the best we could do now would probably be to convert those to the corresponding integer values.

notramo commented 7 months ago

What about converting it to a tuple with value and name?

ellmetha commented 7 months ago

Tuples are not ideal to deal with in templates, but a special "wrapper" object giving access to the integer value and enum name would be an option.

notramo commented 7 months ago

Even better, then the #to_s method could be used for name, and #value for the numeric value.

notramo commented 7 months ago

I can try to implement it, where should I start?

ellmetha commented 7 months ago

Sorry @notramo I forgot to assign myself and I actually started looking into this after posting my previous message. The feature was added in 4c9139b.