Skip to content

Commit dccd891

Browse files
committed
Optional class value, dd & span tag builder init
1 parent 1b0f64c commit dccd891

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

Sources/SwiftHtml/Html/Attributes/Global.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public extension Tag {
4040
}
4141

4242
/// Specifies one classname for an element (refers to a class in a style sheet)
43-
func `class`(_ value: String, _ condition: Bool = true) -> Self {
44-
if condition {
43+
func `class`(_ value: String?, _ condition: Bool = true) -> Self {
44+
if let value = value, condition {
4545
node.upsert(Attribute(key: "class", value: value))
4646
}
4747
return self

Sources/SwiftHtml/Html/Tags/Dd.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
/// Inside a `<dd>` tag you can put paragraphs, line breaks, images, links, lists, etc.
1313
public final class Dd: Tag {
1414

15-
public init(_ contents: String) {
16-
super.init(Node(type: .standard, name: "dd", contents: contents))
15+
public init(_ contents: String? = nil, @TagBuilder _ builder: () -> [Tag]) {
16+
super.init(Node(type: .standard, name: "dd", contents: contents), children: builder())
1717
}
18+
19+
public convenience init(_ contents: String) {
20+
self.init(contents) {}
21+
}
22+
1823
}

Sources/SwiftHtml/Html/Tags/Span.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111
///
1212
/// The `<span>` tag is much like the `<div>` element, but `<div>` is a block-level element and `<span>` is an inline element.
1313
public final class Span: Tag {
14+
15+
public init(_ contents: String? = nil, @TagBuilder _ builder: () -> [Tag]) {
16+
super.init(Node(type: .standard, name: "span", contents: contents), children: builder())
17+
}
1418

15-
public init(_ contents: String) {
16-
super.init(Node(type: .standard, name: "span", contents: contents))
19+
public convenience init(_ contents: String) {
20+
self.init(contents) {}
1721
}
22+
1823
}

0 commit comments

Comments
 (0)