Initial Commit
This commit is contained in:
265
Sources/HRW/GenHTML/Elements/Button.swift
Normal file
265
Sources/HRW/GenHTML/Elements/Button.swift
Normal file
@@ -0,0 +1,265 @@
|
||||
//
|
||||
// Button.swift
|
||||
// HTMLStandard
|
||||
//
|
||||
// Generated on 09/23/2025.
|
||||
// THIS FILE IS GENERATED. DO NOT EDIT.
|
||||
//
|
||||
import Foundation
|
||||
|
||||
/// <button> Button control
|
||||
public class Button : HTMLNode, IFlow, IFormAssociated, IInteractive, ILabelable, IListed, IPalpable, IPhrasing, ISubmittable {
|
||||
|
||||
public enum Formenctype : String, CaseIterable {
|
||||
|
||||
case application_xWwwFormUrlencoded = "application/x-www-form-urlencoded"
|
||||
case multipart_formData = "multipart/form-data"
|
||||
case text_plain = "text/plain"
|
||||
|
||||
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 Formenctype: \(expect)") }
|
||||
|
||||
self = value
|
||||
}
|
||||
|
||||
public init(expect: String) throws {
|
||||
guard let result = Formenctype(rawValue: expect) else {
|
||||
throw AppError("Unexpected value for Formenctype: \(expect)")
|
||||
}
|
||||
self = result
|
||||
}
|
||||
|
||||
static func parseList(_ value:String?, _ separator:String = " ") throws -> [Formenctype] {
|
||||
guard let value = value else { return [] }
|
||||
var iterator = value.componentsIterator(separatedBy: separator)
|
||||
let result = try iterator.map { input in
|
||||
return try expect(Formenctype(rawValue: input), "unexpected value for Formenctype: \(input)")
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
public enum Formmethod : String, CaseIterable {
|
||||
|
||||
case GET
|
||||
case POST
|
||||
case dialog
|
||||
|
||||
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 Formmethod: \(expect)") }
|
||||
|
||||
self = value
|
||||
}
|
||||
|
||||
public init(expect: String) throws {
|
||||
guard let result = Formmethod(rawValue: expect) else {
|
||||
throw AppError("Unexpected value for Formmethod: \(expect)")
|
||||
}
|
||||
self = result
|
||||
}
|
||||
|
||||
static func parseList(_ value:String?, _ separator:String = " ") throws -> [Formmethod] {
|
||||
guard let value = value else { return [] }
|
||||
var iterator = value.componentsIterator(separatedBy: separator)
|
||||
let result = try iterator.map { input in
|
||||
return try expect(Formmethod(rawValue: input), "unexpected value for Formmethod: \(input)")
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
public enum AttrType : String, CaseIterable {
|
||||
|
||||
case button
|
||||
case reset
|
||||
case submit
|
||||
|
||||
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 AttrType: \(expect)") }
|
||||
|
||||
self = value
|
||||
}
|
||||
|
||||
public init(expect: String) throws {
|
||||
guard let result = AttrType(rawValue: expect) else {
|
||||
throw AppError("Unexpected value for AttrType: \(expect)")
|
||||
}
|
||||
self = result
|
||||
}
|
||||
|
||||
static func parseList(_ value:String?, _ separator:String = " ") throws -> [AttrType] {
|
||||
guard let value = value else { return [] }
|
||||
var iterator = value.componentsIterator(separatedBy: separator)
|
||||
let result = try iterator.map { input in
|
||||
return try expect(AttrType(rawValue: input), "unexpected value for AttrType: \(input)")
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the form control is disabled.
|
||||
public var disabled:Bool = false
|
||||
|
||||
/// Associates the element with a form element. ID. The actual rules are more complicated than indicated.
|
||||
public var form:String? = nil
|
||||
|
||||
/// URL to use for form submission. Valid non-empty URL potentially surrounded by spaces.
|
||||
public var formaction:URL? = nil
|
||||
|
||||
/// Entry list encoding type to use for form submission.
|
||||
public var formenctype:Formenctype? = nil
|
||||
|
||||
/// Variant to use for form submission.
|
||||
public var formmethod:Formmethod? = nil
|
||||
|
||||
/// Bypass form control validation for form submission.
|
||||
public var formnovalidate:Bool = false
|
||||
|
||||
/// Browsing context for form submission. Valid browsing context name or keyword.
|
||||
public var formtarget:String? = nil
|
||||
|
||||
/// Name of the element to use for form submission and in the form.elements API. Text. The actual rules are more complicated than indicated.
|
||||
public var name:String? = nil
|
||||
|
||||
/// Type of button.
|
||||
public var type:AttrType? = nil
|
||||
|
||||
/// Value to be used for form submission.
|
||||
public var value:String? = nil
|
||||
|
||||
|
||||
public init(_ attributes:[String:String], _ parser:XMLParser? = nil) throws {
|
||||
var globalAttr = GlobalAttributesBuilder()
|
||||
for (key, attValue) in attributes {
|
||||
switch (key) {
|
||||
case "disabled":
|
||||
disabled = true
|
||||
continue
|
||||
case "form":
|
||||
form = attValue
|
||||
continue
|
||||
case "formaction":
|
||||
formaction = try URL(expect: attValue)
|
||||
continue
|
||||
case "formenctype":
|
||||
formenctype = try Formenctype(expect: attValue)
|
||||
continue
|
||||
case "formmethod":
|
||||
formmethod = try Formmethod(expect: attValue)
|
||||
continue
|
||||
case "formnovalidate":
|
||||
formnovalidate = true
|
||||
continue
|
||||
case "formtarget":
|
||||
formtarget = attValue
|
||||
continue
|
||||
case "name":
|
||||
name = attValue
|
||||
continue
|
||||
case "type":
|
||||
type = try AttrType(expect: attValue)
|
||||
continue
|
||||
case "value":
|
||||
value = 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: "button", xmlToHtmlMapper) {
|
||||
allItems.append(obj)
|
||||
}
|
||||
super.init(globalAttr, allItems)
|
||||
}
|
||||
|
||||
|
||||
public func addChild(_ someElement:IPhrasing) {
|
||||
children.append(someElement)
|
||||
}
|
||||
|
||||
public override func renderAttributes() -> String {
|
||||
var result = super.renderAttributes()
|
||||
if disabled {
|
||||
result += " disabled"
|
||||
}
|
||||
if let form = form {
|
||||
result += " form='\(form)'"
|
||||
}
|
||||
if let formaction = formaction {
|
||||
result += " formaction='\(formaction.absoluteString)'"
|
||||
}
|
||||
if let formenctype = formenctype {
|
||||
result += " formenctype='\(formenctype.rawValue)'"
|
||||
}
|
||||
if let formmethod = formmethod {
|
||||
result += " formmethod='\(formmethod.rawValue)'"
|
||||
}
|
||||
if formnovalidate {
|
||||
result += " formnovalidate"
|
||||
}
|
||||
if let formtarget = formtarget {
|
||||
result += " formtarget='\(formtarget)'"
|
||||
}
|
||||
if let name = name {
|
||||
result += " name='\(name)'"
|
||||
}
|
||||
if let type = type {
|
||||
result += " type='\(type.rawValue)'"
|
||||
}
|
||||
if let value = value {
|
||||
result += " value='\(value)'"
|
||||
}
|
||||
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
override var nodeName: String {
|
||||
return "button"
|
||||
}
|
||||
|
||||
override var isVoidElement: Bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user