Extend family stencil

This commit is contained in:
Christian Treffs 2020-08-07 10:50:31 +02:00
parent 5b73722a04
commit dd2c125664
No known key found for this signature in database
GPG Key ID: 49A4B4B460BE3ED4
1 changed files with 17 additions and 1 deletions

View File

@ -23,12 +23,20 @@
{% map components into compsTypeParams using comp %}{% if not maploop.first %}_ {% endif %}{{ comp|lowercase }}: {{ comp }}.Type{% endmap %}
{% set CompsTypeParams %}{{compsTypeParams|join: ", "}}{% endset %}
{% map components into compsNamedParams using comp %}{% if not maploop.first %}_ {% endif %}{{ comp|lowercase }}: {{ comp }}{% endmap %}
{% set CompsNamedParams %}{{compsNamedParams|join: ", "}}{% endset %}
{% set CompsNamedParams %}{{compsNamedParams|join: ", "}}{% endset %}
{% map components into compsNamedRParams using comp %}_ {{ comp|lowercase }}: R.{{ comp }}{% endmap %}
{% set CompsNamedRParams %}{{compsNamedRParams|join: ", "}}{% endset %}
// MARK: - Family {{ idx }}
public typealias Family{{ idx }}<{{ CompParams }}> = Family<Requires{{ idx }}<{{ CompParams }}>> where {{ CompsWhere }}
public protocol RequiringComponents{{ idx }}: FamilyRequirementsManaging where Components == ({{ CompParams }}) {
{% for comp in components %}
associatedtype {{ comp }}: Component
{% endfor %}
}
public struct Requires{{ idx }}<{{ CompParams }}>: FamilyRequirementsManaging where {{ CompsWhere }} {
public let componentTypes: [Component.Type]
@ -56,6 +64,14 @@ public struct Requires{{ idx }}<{{ CompParams }}>: FamilyRequirementsManaging wh
}
}
extension Requires{{ idx }}: RequiringComponents{{ idx }} { }
extension FamilyMemberBuilder where R: RequiringComponents{{ idx }} {
public static func buildBlock({{ CompsNamedRParams }}) -> (R.Components) {
return ({{ CompsLowercased }})
}
}
extension Requires{{ idx }}: FamilyEncoding where {{ CompsWhereEncodable }} {
public static func encode(components: ({{ CompParams }}), into container: inout KeyedEncodingContainer<DynamicCodingKey>, using strategy: CodingStrategy) throws {
{% if compEncodable.count == 1 %}