From 7a235e9cb846dcf1dbda3220a5734aae8c52ee4d Mon Sep 17 00:00:00 2001 From: Jeff Verkoeyen Date: Sun, 22 Sep 2024 18:29:06 -0700 Subject: [PATCH 1/2] Add support for colspan and rowspan on TableCell. --- .../W3C/Elements/TabularData/TableCell.swift | 30 ++++++++++++++----- .../W3C/TabularData/TableCellTests.swift | 6 ++++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Sources/Slipstream/W3C/Elements/TabularData/TableCell.swift b/Sources/Slipstream/W3C/Elements/TabularData/TableCell.swift index 7880c06..5469e5e 100644 --- a/Sources/Slipstream/W3C/Elements/TabularData/TableCell.swift +++ b/Sources/Slipstream/W3C/Elements/TabularData/TableCell.swift @@ -1,16 +1,30 @@ +import SwiftSoup + /// A view that represents a data cell in a table. /// /// - SeeAlso: W3C [td](https://html.spec.whatwg.org/multipage/tables.html#the-td-element) specification. @available(iOS 17.0, macOS 14.0, *) -public struct TableCell: W3CElement where Content: View { - @_documentation(visibility: private) - public let tagName: String = "td" - - @_documentation(visibility: private) - @ViewBuilder public let content: () -> Content - +public struct TableCell: View where Content: View { /// Creates a table cell. - public init(@ViewBuilder content: @escaping () -> Content) { + public init(rowSpan: Int? = nil, colSpan: Int? = nil, @ViewBuilder content: @escaping () -> Content) { self.content = content + self.rowSpan = rowSpan + self.colSpan = colSpan } + + @_documentation(visibility: private) + public func render(_ container: Element, environment: EnvironmentValues) throws { + let element = try container.appendElement("td") + if let rowSpan { + try element.attr("rowspan", "\(rowSpan)") + } + if let colSpan { + try element.attr("colspan", "\(colSpan)") + } + try self.content().render(element, environment: environment) + } + + @ViewBuilder private let content: () -> Content + private let rowSpan: Int? + private let colSpan: Int? } diff --git a/Tests/SlipstreamTests/W3C/TabularData/TableCellTests.swift b/Tests/SlipstreamTests/W3C/TabularData/TableCellTests.swift index 2f31069..bf931a5 100644 --- a/Tests/SlipstreamTests/W3C/TabularData/TableCellTests.swift +++ b/Tests/SlipstreamTests/W3C/TabularData/TableCellTests.swift @@ -7,6 +7,12 @@ struct TableCellTests { try #expect(renderHTML(TableCell {}) == "") } + @Test func spans() throws { + try #expect(renderHTML(TableCell(rowSpan: 2) {}) == #""#) + try #expect(renderHTML(TableCell(colSpan: 3) {}) == #""#) + try #expect(renderHTML(TableCell(rowSpan: 2, colSpan: 4) {}) == #""#) + } + @Test func withText() throws { try #expect(renderHTML(TableCell { DOMString("Hello, world!") From 3a2b9f662f0e65a912d967d5e930c4205b02cd07 Mon Sep 17 00:00:00 2001 From: Jeff Verkoeyen Date: Sun, 22 Sep 2024 18:31:34 -0700 Subject: [PATCH 2/2] Update Xcode. --- .github/workflows/package-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package-test.yml b/.github/workflows/package-test.yml index 058a896..50b320a 100644 --- a/.github/workflows/package-test.yml +++ b/.github/workflows/package-test.yml @@ -11,7 +11,7 @@ jobs: runs-on: macos-latest steps: - name: Select Xcode - run: sudo xcode-select -s "/Applications/Xcode_16.1_beta.app" + run: sudo xcode-select -s "/Applications/Xcode_16.app" - name: Get swift version run: swift --version - uses: actions/checkout@v4