Skip to content

Commit

Permalink
Td colspan (BinaryBirds#27)
Browse files Browse the repository at this point in the history
* <td> colspan Attribute
* test for table with attributes including td colspan

Co-authored-by: Atacan Durmusoglu <[email protected]_w_724v_typ_a_05011603_06_003>
  • Loading branch information
atacan and Atacan Durmusoglu authored May 29, 2022
1 parent 896e1bd commit f87a1cf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/SwiftHtml/Tags/Td.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@
open class Td: Tag {

}

public extension Td {

/// Specifies the number of columns a data cell should span
func colspan(_ value: Int) -> Self {
attribute("colspan", String(value))
}
}
47 changes: 47 additions & 0 deletions Tests/SwiftHtmlTests/Tags/TableTagTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,51 @@ final class TableTagTests: XCTestCase {

}

func testTablewithAttributes() {
let doc = Document(.html) {
Table {
Thead {
Tr {
Th("#")
.scope(.col)
Th("First")
.scope(.col)
Th("Last")
.scope(.col)
Th("Handle")
.scope(.col)
}
}
Tbody {
Tr {
Th("1")
.scope(.row)
Td("Mark")
Td("Otto")
Td("@mdo")
}
Tr {
Th("2")
.scope(.row)
Td("Jacob")
Td("Thornton")
Td("@fat")
}
Tr {
Th("3")
.scope(.row)
Td("Larry the Bird")
.colspan(2)
Td("@twitter")
}
}
}
.class("table")
}

XCTAssertEqual(DocumentRenderer(minify: true).render(doc), #"<!DOCTYPE html><table class="table"><thead><tr><th scope="col">#</th><th scope="col">First</th><th scope="col">Last</th><th scope="col">Handle</th></tr></thead><tbody><tr><th scope="row">1</th><td>Mark</td><td>Otto</td><td>@mdo</td></tr><tr><th scope="row">2</th><td>Jacob</td><td>Thornton</td><td>@fat</td></tr><tr><th scope="row">3</th><td colspan="2">Larry the Bird</td><td>@twitter</td></tr></tbody></table>"#)


}

}

0 comments on commit f87a1cf

Please sign in to comment.