Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Sources/HTMLKit/Abstraction/Attributes/BasicAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2189,16 +2189,26 @@ extension SandboxAttribute where Self: EmptyNode {
}
}

/// The protocol provides the element with the scope handler.
/// A type that provides the `scope` modifier.
@_documentation(visibility: internal)
public protocol ScopeAttribute: Attribute {

/// The function represents the html-attribute 'scope'.
/// Define the scope for a header cell
///
/// ```html
/// <tag scope="" />
/// It specifies wether the cell is for a column, row or a group of columns
/// and rows.
///
/// ```swift
/// TableRow {
/// HeaderCell {
/// "..."
/// }
/// .scope(.column)
/// }
/// ```
func scope(_ value: String) -> Self
///
/// - Parameter value: The scope of the header cell
func scope(_ value: Values.Scope) -> Self
}

extension ScopeAttribute where Self: ContentNode {
Expand Down
7 changes: 6 additions & 1 deletion Sources/HTMLKit/Abstraction/Elements/TableElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2316,11 +2316,16 @@ extension HeaderCell: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu
public func headers(_ value: String) -> HeaderCell {
return mutate(headers: value)
}


@available(*, deprecated, message: "The scope attribute is actually an enumerated attribute. Use the scope(_: Scope) modifier instead.")
public func scope(_ value: String) -> HeaderCell {
return mutate(scope: value)
}

public func scope(_ value: Values.Scope) -> HeaderCell {
return mutate(scope: value.rawValue)
}

public func popover(_ value: Values.Popover.State) -> HeaderCell {
return mutate(popover: value.rawValue)
}
Expand Down
23 changes: 23 additions & 0 deletions Sources/HTMLKit/Abstraction/Tokens/ValueTokens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -958,4 +958,27 @@ public enum Values {
case hide
}
}

/// A enumeration of potential scopes for a header cell.
///
/// ```swift
/// HeaderCell {
/// "..."
/// }
/// .scope(.column)
/// ```
public enum Scope: String {

/// The cell applies to subsequent cells in the same row.
case row

/// The cell applies to subsequent cells in the same column.
case column = "col"

/// The cell applies to all remaining cells in the row group.
case rowGroup = "rowgroup"

/// The cell applies to all remaining cells in the column group.
case columnGroup = "colgroup"
}
}
14 changes: 10 additions & 4 deletions Tests/HTMLKitTests/AttributesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ final class AttributesTests: XCTestCase {
return self.mutate(sandbox: "sandbox")
}

func scope(_ value: String) -> Tag {
return self.mutate(scope: value)
func scope(_ value: Values.Scope) -> Tag {
return self.mutate(scope: value.rawValue)
}

func shape(_ value: Values.Shape) -> Tag {
Expand Down Expand Up @@ -1832,12 +1832,18 @@ final class AttributesTests: XCTestCase {
func testScopeAttribute() throws {

let view = TestView {
Tag {}.scope("scope")
Tag {}.scope(.column)
Tag {}.scope(.row)
Tag {}.scope(.columnGroup)
Tag {}.scope(.rowGroup)
}

XCTAssertEqual(try renderer.render(view: view),
"""
<tag scope="scope"></tag>
<tag scope="col"></tag>\
<tag scope="row"></tag>\
<tag scope="colgroup"></tag>\
<tag scope="rowgroup"></tag>
"""
)
}
Expand Down