Skip to content

Commit

Permalink
Make column element an empty node (#166)
Browse files Browse the repository at this point in the history
* Make column element an empty node

* Deprecate the old initializer
  • Loading branch information
mattesmohr authored Dec 31, 2024
1 parent dc2b315 commit d3dcaa6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
30 changes: 19 additions & 11 deletions Sources/HTMLKit/Abstraction/Elements/TableElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -568,24 +568,32 @@ extension ColumnGroup: GlobalAttributes, GlobalEventAttributes, SpanAttribute {

/// The element represents a column in a table.
///
/// ```html
/// <col></col>
/// Use `Column` for applying styles to entire columns, instead of repeating the styles for each cell, for each row.
///
/// ```swift
/// Table {
/// ColumnGroup {
/// Column()
/// .span(2)
/// Column()
/// .style("...")
/// }
/// }
/// ```
public struct Column: ContentNode, TableElement {

public struct Column: EmptyNode, TableElement {
internal var name: String { "col" }

internal var attributes: OrderedDictionary<String, Any>?

internal var content: [Content]

public init(@ContentBuilder<Content> content: () -> [Content]) {
self.content = content()
}
/// Create a column
public init() {}

internal init(attributes: OrderedDictionary<String, Any>?, content: [Content]) {
@available(*, deprecated, message: "The column element is actually an empty element. Use Column() instead.")
public init(@ContentBuilder<Content> content: () -> [Content]) {}

internal init(attributes: OrderedDictionary<String, Any>?) {
self.attributes = attributes
self.content = content
}

public func modify(if condition: Bool, element: (Column) -> Column) -> Column {
Expand Down
8 changes: 4 additions & 4 deletions Tests/HTMLKitTests/ElementTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1196,14 +1196,14 @@ final class ElementTests: XCTestCase {
func testColumnElement() throws {

let view = TestView {
Column {}
Col {}
Column()
Col()
}

XCTAssertEqual(try renderer.render(view: view),
"""
<col></col>\
<col></col>
<col>\
<col>
"""
)
}
Expand Down

0 comments on commit d3dcaa6

Please sign in to comment.