From c0b101d1ffc1af4eef91db4f3c3f5f0f457fb95d Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 23 Jun 2017 18:55:50 +0300 Subject: [PATCH] swift templates small refactoring --- Swift/blocks/class/fields-mapping-from-map.twig | 2 +- Swift/blocks/class/fields.twig | 2 +- Swift/blocks/class/init-parameters-fields.twig | 2 +- Swift/utils.twig | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Swift/blocks/class/fields-mapping-from-map.twig b/Swift/blocks/class/fields-mapping-from-map.twig index 1cd9018..6bc9093 100644 --- a/Swift/blocks/class/fields-mapping-from-map.twig +++ b/Swift/blocks/class/fields-mapping-from-map.twig @@ -1,4 +1,4 @@ {%- import '../../utils.twig' as utils -%} {%- for field in fields %} - {{ field.name }} = {{ utils.formatNullable('try', field.nullable, field.optional) }} {{ utils.mappingFromMapForField(field) }} + {{ field.name }} = {{ utils.formatNullableOrOptional('try', field.nullable, field.optional) }} {{ utils.mappingFromMapForField(field) }} {%- endfor -%} \ No newline at end of file diff --git a/Swift/blocks/class/fields.twig b/Swift/blocks/class/fields.twig index 1fb0a84..d52adeb 100644 --- a/Swift/blocks/class/fields.twig +++ b/Swift/blocks/class/fields.twig @@ -4,6 +4,6 @@ // MARK: - Fields {% for field in fields %} /// {{ field.description }} - let {{ field.name }}: {{ utils.formatNullable(utils.formatValueType(field.type.type), field.nullable, field.optional) }} + let {{ field.name }}: {{ utils.formatNullableOrOptional(utils.formatValueType(field.type.type), field.nullable, field.optional) }} {% endfor -%} {% endif %} \ No newline at end of file diff --git a/Swift/blocks/class/init-parameters-fields.twig b/Swift/blocks/class/init-parameters-fields.twig index 7951993..23f4f0b 100644 --- a/Swift/blocks/class/init-parameters-fields.twig +++ b/Swift/blocks/class/init-parameters-fields.twig @@ -2,6 +2,6 @@ {%- if fields is not empty -%} {%- for field in fields -%} - {{ field.name }}: {{ utils.formatNullable(utils.formatValueType(field.type.type), field.nullable, field.optional) }}{% if field.optional %} = nil{% endif %}{%- if not (loop.last) %}, {% endif %} + {{ field.name }}: {{ utils.formatNullableOrOptional(utils.formatValueType(field.type.type), field.nullable, field.optional) }}{% if field.optional %} = nil{% endif %}{%- if not (loop.last) %}, {% endif %} {%- endfor -%} {%- endif -%} \ No newline at end of file diff --git a/Swift/utils.twig b/Swift/utils.twig index 20f890a..3255629 100644 --- a/Swift/utils.twig +++ b/Swift/utils.twig @@ -18,7 +18,7 @@ ImmutableMappable {%- endif -%} {% endmacro %} -{% macro formatNullable(expr, nullable, optional) %} +{% macro formatNullableOrOptional(expr, nullable, optional) %} {{- expr -}}{%- if nullable or optional -%}?{%- endif -%} {% endmacro %}