Initial Commit
This commit is contained in:
137
Sources/HRW/GenHTML/Elements/Th.swift
Normal file
137
Sources/HRW/GenHTML/Elements/Th.swift
Normal file
@@ -0,0 +1,137 @@
|
||||
//
|
||||
// Th.swift
|
||||
// HTMLStandard
|
||||
//
|
||||
// Generated on 09/23/2025.
|
||||
// THIS FILE IS GENERATED. DO NOT EDIT.
|
||||
//
|
||||
import Foundation
|
||||
|
||||
/// <th> Table header cell
|
||||
public class Th : HTMLNode, IInteractive {
|
||||
|
||||
public enum Scope : String, CaseIterable {
|
||||
|
||||
case col
|
||||
case colgroup
|
||||
case row
|
||||
case rowgroup
|
||||
|
||||
public init?(rawValue: Substring) {
|
||||
guard
|
||||
let value = Self.allCases.first(where: { $0.rawValue == rawValue })
|
||||
else
|
||||
{ return nil }
|
||||
|
||||
self = value
|
||||
}
|
||||
|
||||
public init(expect: Substring) throws {
|
||||
guard
|
||||
let value = Self.allCases.first(where: { $0.rawValue == expect })
|
||||
else
|
||||
{ throw AppError("Unexpected value for Scope: \(expect)") }
|
||||
|
||||
self = value
|
||||
}
|
||||
|
||||
public init(expect: String) throws {
|
||||
guard let result = Scope(rawValue: expect) else {
|
||||
throw AppError("Unexpected value for Scope: \(expect)")
|
||||
}
|
||||
self = result
|
||||
}
|
||||
|
||||
static func parseList(_ value:String?, _ separator:String = " ") throws -> [Scope] {
|
||||
guard let value = value else { return [] }
|
||||
var iterator = value.componentsIterator(separatedBy: separator)
|
||||
let result = try iterator.map { input in
|
||||
return try expect(Scope(rawValue: input), "unexpected value for Scope: \(input)")
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
/// Alternative label to use for the header cell when referencing the cell in other contexts. Text. The actual rules are more complicated than indicated.
|
||||
public var abbr:String? = nil
|
||||
|
||||
/// Number of columns that the cell is to span. Valid non-negative integer greater than zero.
|
||||
public var colspan:UInt? = nil
|
||||
|
||||
/// The header cells for this cell. Unordered set of unique space-separated tokens, case-sensitive, consisting of IDs. The actual rules are more complicated than indicated.
|
||||
public var headers:[String] = []
|
||||
|
||||
/// Number of rows that the cell is to span. Valid non-negative integer.
|
||||
public var rowspan:UInt? = nil
|
||||
|
||||
/// Specifies which cells the header cell applies to.
|
||||
public var scope:Scope? = nil
|
||||
|
||||
|
||||
public init(_ attributes:[String:String], _ parser:XMLParser? = nil) throws {
|
||||
var globalAttr = GlobalAttributesBuilder()
|
||||
for (key, attValue) in attributes {
|
||||
switch (key) {
|
||||
case "abbr":
|
||||
abbr = attValue
|
||||
continue
|
||||
case "colspan":
|
||||
colspan = UInt(attValue)
|
||||
continue
|
||||
case "headers":
|
||||
headers = try String.parseList(attValue, " ")
|
||||
continue
|
||||
case "rowspan":
|
||||
rowspan = UInt(attValue)
|
||||
continue
|
||||
case "scope":
|
||||
scope = try Scope(expect: attValue)
|
||||
continue
|
||||
|
||||
default: break
|
||||
}
|
||||
if globalAttr.trySetGlobalAttribute(key, attValue) {
|
||||
continue
|
||||
}
|
||||
throw AppError("Unexpected attribute: \(key)")
|
||||
}
|
||||
var allItems:[HTMLNode] = []
|
||||
while let obj = try parser?.readObject(endTag: "th", xmlToHtmlMapper) {
|
||||
allItems.append(obj)
|
||||
}
|
||||
super.init(globalAttr, allItems)
|
||||
}
|
||||
|
||||
|
||||
public func addChild(_ someElement:IFlow) {
|
||||
children.append(someElement)
|
||||
}
|
||||
|
||||
public override func renderAttributes() -> String {
|
||||
var result = super.renderAttributes()
|
||||
if let abbr = abbr {
|
||||
result += " abbr='\(abbr)'"
|
||||
}
|
||||
if let colspan = colspan {
|
||||
result += " colspan='\(colspan)'"
|
||||
}
|
||||
result += " headers='\(headers.toStringList(" "))'"
|
||||
if let rowspan = rowspan {
|
||||
result += " rowspan='\(rowspan)'"
|
||||
}
|
||||
if let scope = scope {
|
||||
result += " scope='\(scope.rawValue)'"
|
||||
}
|
||||
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
override var nodeName: String {
|
||||
return "th"
|
||||
}
|
||||
|
||||
override var isVoidElement: Bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user