1
0

TableRowContent.swift.gyb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // This file was generated using gyb. Do not edit it directly. Edit
  2. // TableRowContent.swift.gyb instead.
  3. // swiftformat:options --allow-partial-wrapping true
  4. %{
  5. maximum_column_count = 20
  6. }%
  7. public protocol TableRowContent<RowValue> {
  8. associatedtype RowValue
  9. associatedtype RowContent: View
  10. var labels: [String] { get }
  11. func content(for row: RowValue) -> RowContent
  12. }
  13. public struct EmptyTableRowContent<RowValue>: TableRowContent {
  14. public typealias RowContent = EmptyView
  15. public var labels: [String] {
  16. []
  17. }
  18. public init() {}
  19. public func content(for row: RowValue) -> EmptyView {
  20. EmptyView()
  21. }
  22. }
  23. %for i in range(1, maximum_column_count + 1):
  24. public struct TupleTableRowContent${i}<
  25. RowValue, ${", ".join("Content%d: View" % j for j in range(i))}
  26. >: TableRowContent {
  27. public typealias RowContent = TupleView${i}<
  28. ${", ".join("Content%d" % j for j in range(i))}
  29. >
  30. %for j in range(i):
  31. public var column${j}: TableColumn<RowValue, Content${j}>
  32. %end
  33. public var labels: [String] {
  34. [${", ".join("column%d.label" % j for j in range(i))}]
  35. }
  36. public init(
  37. ${", ".join("_ column%d: TableColumn<RowValue, Content%d>" % (j, j) for j in range(i))}
  38. ) {
  39. %for j in range(i):
  40. self.column${j} = column${j}
  41. %end
  42. }
  43. public func content(for row: RowValue) -> RowContent {
  44. TupleView${i}(
  45. ${", ".join("column%d.content(row)" % j for j in range(i))}
  46. )
  47. }
  48. }
  49. %end