Created
September 11, 2018 15:21
-
-
Save homerooliveira/0f452ecec60e0e33d3c896322616f4e7 to your computer and use it in GitHub Desktop.
AutoInit template for Sourcery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% for type in types.structs %} | |
{% if type|annotated:"AutoInit" %} | |
{% set spacing %}{% if type.parentName %} {% endif %}{% endset %} | |
{% map type.storedVariables into parameters using var %}{{ var.name }}: {{ var.typeName }}{% if var.defaultValue %} = {{ var.defaultValue }}{% endif %}{% endmap %} | |
{% map type.storedVariables into parametersInit using var %}{{ var.name }}: {{ var.name }}{% endmap %} | |
// sourcery:inline:auto:{{ type.name }}.AutoInit | |
{{spacing}} {{ type.accessLevel }} init({{ parameters|join:", "}}) { // swiftlint:disable:this line_length | |
{{spacing}} {% for variable in type.storedVariables %} | |
{{spacing}} self.{{ variable.name }} = {{ variable.name }} | |
{{spacing}} {% endfor %} | |
{{spacing}} {{ type.name }}({{ parametersInit|join:", "}}) | |
{{spacing}} } | |
// sourcery:end | |
{% endif %} | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment