Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. import WeatherCore
  2. {# define placeholder #}
  3. {% macro placeholder param_argument %}
  4. {% if param_argument.type.name|replace:"?","" == "String" %}""
  5. {% elif param_argument.typeName|replace:"Int","Integer" == "Integer" %}0
  6. {% elif param_argument.isArray %}
  7. {% for arrayModel in types.all|struct where arrayModel.name == param_argument.typeName|replace:"[",""|replace:"]","" %}
  8. {% for childArrayRealmModel in arrayModel.allVariables where childArrayRealmModel.name == "object" %}
  9. {% for childClass in types.all|class where childClass.name == childArrayRealmModel.typeName|replace:".Type","" %}
  10. {% for childObjectVariable in objectClass.allVariables where childObjectVariable.typeName|contains:"List"|contains:"" %}
  11. {{childObjectVariable.name}}: {{childObjectVariable.typeName}}
  12. {% endfor %}
  13. {% endfor %}
  14. {% endfor %}
  15. {% endfor %}
  16. {% elif param_argument.isDictionary %}[:]
  17. {% elif param_argument.typeName|replace:"Double","Double2" == "Double2" %}0
  18. {% elif param_argument.typeName|replace:"?","" == "Data" %}Data()
  19. {% elif argument.typeName|replace:"?","" == "Date" %}Date(){% endif %}
  20. {% endmacro %}
  21.  
  22. {% for domainModel in types.implementing.AutoObjectInit|struct where domainModel.accessLevel == "public" %}
  23. {% for realmModel in domainModel.allVariables where realmModel.name == "object" %}
  24. {% for objectClass in types.all|class where objectClass.name == realmModel.typeName|replace:".Type","" %}
  25. public extension {{ domainModel.name }} {
  26. public static func new(object: {{ objectClass.name }}) -> {{ domainModel.name }} {
  27. return {{domainModel.name}}.new(
  28. {% for argument in domainModel.variables where not argument.isComputed %}
  29. {{argument.name}}: {% for objectVariable in objectClass.variables where objectVariable.name == argument.name %}{% if argument.typeName|replace:"Int","Integer" == "Integer" and objectVariable.typeName|replace:"RealmOptional<Int>","RealmOptional<Integer>" == "RealmOptional<Integer>" %}object.{{argument.name}}.value{% elif argument.typeName|replace:"Double","Double2" == "Double2" and objectVariable.typeName|replace:"RealmOptional<Double>","RealmOptional<Double2>" == "RealmOptional<Double2>" %}object.{{argument.name}}.value ?? 0{% elif argument.type.kind == "struct" %}{% for childRealmModel in argument.type.allVariables where childRealmModel.name == "object" %}{% for childRealmModel in argument.type.allVariables where childRealmModel.name == "object" %}{% for childClass in types.all|class where childClass.name == childRealmModel.typeName|replace:".Type","" %}{% for childObjectVariable in objectClass.allVariables where childObjectVariable.type.name == childClass.name %}{{argument.typeName}}.new(object: object.{{ childObjectVariable.name}}{% ifnot argument.isOptional %}!{% endif %}){% endfor %}{% endfor %}{% endfor %}{% endfor %}{% elif argument.typeName|replace:"Double?","Double2?" == "Double2?" and objectVariable.typeName|replace:"RealmOptional<Double>","RealmOptional<Double2>" == "RealmOptional<Double2>" %}object.{{argument.name}}.value{% elif objectVariable.type.name != argument.type.name %}{% call placeholder argument %}{% else %}object.{{argument.name}}{% if objectVariable.isOptional %}{% ifnot argument.isOptional %} ?? {% call placeholder argument %}{% endif %}{% endif %}{% endif %}{% empty %}{% call placeholder argument %}{% endfor %}{% if not forloop.last %}, {% endif %}{% endfor %}
  30. )
  31. {% endfor %}
  32. {% endfor %}
  33. }
  34. }
  35. {% endfor %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement