Enum template

This commit is contained in:
Ivan Smolin 2017-06-07 20:33:36 +03:00
parent 07d5943746
commit 8d96730e64
2 changed files with 26 additions and 0 deletions

23
Swift/Enum.swift.template Normal file
View File

@ -0,0 +1,23 @@
{%- import 'swift-utils.twig' as utils -%}
import Foundation
/// {{ description }}
///
{% for value in values -%}
/// - {{ utils.decapitalize(value.name) }}: {{ value.description }}
{% endfor -%}
enum {{ name }}: {% if valuesTypes == "STRING" -%}
String
{%- elseif valuesTypes == "INT" -%}
Int
{%- endif %} {
{% for value in values -%}
case {{ utils.decapitalize(value.name) }} = {% if valuesTypes == "STRING" -%}
"{{ value.value }}"
{% else %}
{{- value.value }}
{% endif -%}
{% endfor %}
}

3
Swift/swift-utils.twig Normal file
View File

@ -0,0 +1,3 @@
{% macro decapitalize (text) %}
{{- concat(slice(text, 0, 1) | lower, slice(text, 1, text | length)) -}}
{% endmacro %}