Skip to content

Commit 5209591

Browse files
added 5 missing attributes for form macro
1 parent f8d9dbf commit 5209591

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

Sources/HTMLKit/HTMLKit.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,14 @@ public macro form<T: ExpressibleByStringLiteral>(
372372
attributes: [HTMLElementAttribute] = [],
373373

374374
acceptCharset: [T] = [],
375+
action: T? = nil,
375376
autocomplete: HTMLElementAttribute.Extra.autocomplete? = nil,
377+
enctype: HTMLElementAttribute.Extra.formenctype? = nil,
378+
method: T? = nil,
376379
name: T? = nil,
380+
novalidate: Bool = false,
377381
rel: T? = nil,
382+
target: HTMLElementAttribute.Extra.target? = nil,
378383
_ innerHTML: T...
379384
) -> T = #externalMacro(module: "HTMLKitMacros", type: "HTMLElement")
380385

Sources/HTMLKitMacros/HTMLElement.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,12 @@ private extension HTMLElement {
238238

239239
static func enumName(elementType: HTMLElementType, key: String) -> String {
240240
switch elementType.rawValue + key {
241-
case "buttontype": return "buttontype"
242-
case "inputtype": return "inputtype"
243-
case "oltype": return "numberingtype"
244-
case "scripttype": return "scripttype"
245-
default: return key
241+
case "buttontype": return "buttontype"
242+
case "formenctype": return "formenctype"
243+
case "inputtype": return "inputtype"
244+
case "oltype": return "numberingtype"
245+
case "scripttype": return "scripttype"
246+
default: return key
246247
}
247248
}
248249

Tests/HTMLKitTests/ElementTests.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,43 @@ extension ElementTests {
169169
}
170170

171171
// MARK: canvas
172+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas
172173
@Test func canvas() {
173174
let string:StaticString = #canvas(height: .percent(4), width: .em(2.69))
174175
#expect(string == "<canvas height=\"4%\" width=\"2.69em\"></canvas>")
175176
}
176177

178+
// MARK: col
179+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/col
180+
@Test func col() {
181+
let string:StaticString = #col(span: 4)
182+
#expect(string == "<col span=\"4\">")
183+
}
184+
185+
// MARK: colgroup
186+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/colgroup
187+
@Test func colgroup() {
188+
let string:StaticString = #colgroup(span: 3)
189+
#expect(string == "<colgroup span=\"3\"></colgroup>")
190+
}
191+
177192
// MARK: form
193+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form
178194
@Test func form() {
179-
let string:StaticString = #form(acceptCharset: ["utf-8"], autocomplete: .on)
195+
var string:StaticString = #form(acceptCharset: ["utf-8"], autocomplete: .on)
180196
#expect(string == "<form accept-charset=\"utf-8\" autocomplete=\"on\"></form>")
197+
198+
string = #form(acceptCharset: ["utf-8", "utf-16"])
199+
#expect(string == "<form accept-charset=\"utf-8 utf-16\"></form>")
200+
201+
string = #form(enctype: .textPlain)
202+
#expect(string == "<form enctype=\"text/plain\"></form>")
203+
204+
string = #form(method: "post")
205+
#expect(string == "<form method=\"post\"></form>")
206+
207+
string = #form(novalidate: true)
208+
#expect(string == "<form novalidate></form>")
181209
}
182210

183211
// MARK: iframe

0 commit comments

Comments
 (0)