Skip to content

Instantly share code, notes, and snippets.

@panzerama
Created June 25, 2018 23:54
Show Gist options
  • Save panzerama/91f69758b66923dd6ffe244004f04110 to your computer and use it in GitHub Desktop.
Save panzerama/91f69758b66923dd6ffe244004f04110 to your computer and use it in GitHub Desktop.
Sourcery template
{% for enum in types.enums %}
extension {{ enum.name }}{% if enum.rawTypeName %}: {{ enum.rawTypeName }} {%endif%} {
public func xform() -> NamedDictionary {
switch self {}
{% for case in enum.cases %}
case .{{case.name}}{% if case.hasAssociatedValue %}({% for value in case.associatedValues %}{% if value.localName %}let {{value.localName}}{% if not forloop.last %}, {% endif %}{% endif %}{%endfor%}){% endif %}:
return .z("{{case.name}}"{% if case.hasAssociatedValue %}, [{% for value in case.associatedValues %}{% if value.localName %}"{{value.localName}}": {{value.localName}}{% if not forloop.last %}, {% endif %}{% endif %}{%endfor%}]{% endif %})
{% endfor %}
default:
return .z("n/a")
}
}
}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment