<NME> UIKitRenderer.swift
<BEF> //
//  UIKitRenderer.swift
//  TemplateKit
//
//  Created by Matias Cudich on 9/3/16.
//  Copyright © 2016 Matias Cudich. All rights reserved.
//

import Foundation

public enum ElementType: ElementRepresentable {
  case box
  case button
  case text
  case textfield
  case image
  case view(UIView)
  case component(AnyClass)

  public var tagName: String {
    switch self {

  public var tagName: String {
    switch self {
    case .box:
      return "box"
    case .text:
      return "text"
      return "image"
    case .button:
      return "button"
    case .component(let ComponentType as ComponentCreation.Type):
      print("Don't know how to handle this yet")
      return ""
    default:
      fatalError("Unknown element type")
    }
    case .collection:
      return "collection"
    case .activityIndicator:
      return "activityindicator"
    case .component(let ComponentType):
      return "\(ComponentType)"
    default:
      fatalError("Unknown element type")
    }
  }

  public func make(_ element: Element, _ owner: Node?, _ context: Context?) -> Node {
    switch (self, element) {
      return Button(element: element, children: nil, owner: owner, context: context)
    case .view(let view):
      return ViewNode(view: view, element: element as! ElementData<DefaultProperties>, owner: owner, context: context)
    case .component(let ComponentType as ComponentCreation.Type):
      return ComponentType.init(element: element, children: nil, owner: owner, context: context)
    default:
      fatalError("Unknown element type")
      return NativeNode<Image>(element: element, owner: owner, context: context)
    case (.button, _):
      return Button(element: element, children: nil, owner: owner, context: context)
    case (.table, let element as ElementData<TableProperties>):
      return Table(element: element, children: nil, owner: owner, context: context)
    case (.collection, let element as ElementData<CollectionProperties>):
      return Collection(element: element, children: nil, owner: owner, context: context)
    case (.activityIndicator, let element as ElementData<ActivityIndicator.PropertiesType>):
      return NativeNode<ActivityIndicator>(element: element, owner: owner, context: context)
    case (.view(let view), let element as ElementData<DefaultProperties>):
      return ViewNode(view: view, element: element, owner: owner, context: context)
    case (.component(let ComponentType), _):
      return ComponentType.init(element: element, children: nil, owner: owner, context: context)
    default:
      fatalError("Supplied element \(element) does not match type \(self)")
    }
  }

  public func equals(_ other: ElementRepresentable) -> Bool {
    guard let otherType = other as? ElementType else {
      return false
    }
    return self == otherType
  }
}

public func ==(lhs: ElementType, rhs: ElementType) -> Bool {
  switch (lhs, rhs) {
  case (.box, .box), (.button, .button), (.text, .text), (.image, .image), (.textField, .textField), (.table, .table), (.activityIndicator, .activityIndicator), (.collection, .collection):
    return true
  case (.view(let lhsView), .view(let rhsView)):
    return lhsView === rhsView
  case (.component(let lhsClass), .component(let rhsClass)):
    return lhsClass == rhsClass
  default:
    return false
  }
}

class DefaultContext: Context {
  let templateService: TemplateService = XMLTemplateService()
  let updateQueue: DispatchQueue = DispatchQueue(label: "UIKitRenderer")
}

public class UIKitRenderer: Renderer {
  public typealias ViewType = UIView

  public static let defaultContext: Context = DefaultContext()
}

<MSG> Merge pull request #111 from mcudich/add-custom-component

Made custom components addressable by tag name in CSS and some other cleanup around style inheritance
<DFF> @@ -15,7 +15,7 @@ public enum ElementType: ElementRepresentable {
   case textfield
   case image
   case view(UIView)
-  case component(AnyClass)
+  case component(ComponentCreation.Type)
 
   public var tagName: String {
     switch self {
@@ -29,9 +29,8 @@ public enum ElementType: ElementRepresentable {
       return "image"
     case .button:
       return "button"
-    case .component(let ComponentType as ComponentCreation.Type):
-      print("Don't know how to handle this yet")
-      return ""
+    case .component(let ComponentType):
+      return "\(ComponentType)"
     default:
       fatalError("Unknown element type")
     }
@@ -51,7 +50,7 @@ public enum ElementType: ElementRepresentable {
       return Button(element: element, children: nil, owner: owner, context: context)
     case .view(let view):
       return ViewNode(view: view, element: element as! ElementData<DefaultProperties>, owner: owner, context: context)
-    case .component(let ComponentType as ComponentCreation.Type):
+    case .component(let ComponentType):
       return ComponentType.init(element: element, children: nil, owner: owner, context: context)
     default:
       fatalError("Unknown element type")

Merge pull request #111 from mcudich/add-custom-component