Skip to content

Commit 573dfee

Browse files
committed
fix svg lib
1 parent fcad307 commit 573dfee

31 files changed

+1009
-773
lines changed

Package.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ let package = Package(
1919
.library(name: "SwiftSitemap", targets: ["SwiftSitemap"]),
2020
.library(name: "SwiftSVG", targets: ["SwiftSVG"]),
2121
],
22+
dependencies: [
23+
// .package(url: "https://github.com/apple/swift-collections", .upToNextMinor(from: "1.3.0")),
24+
],
2225
targets: [
2326
.target(
2427
name: "DOM",
@@ -27,73 +30,74 @@ let package = Package(
2730
.target(
2831
name: "SGML",
2932
dependencies: [
30-
.target(name: "DOM")
33+
// .product(name: "Collections", package: "swift-collections"),
34+
.target(name: "DOM"),
3135
],
3236
swiftSettings: defaultSwiftSettings
3337
),
3438
.target(
3539
name: "SwiftHTML",
3640
dependencies: [
37-
.target(name: "SGML")
41+
.target(name: "SGML"),
3842
],
3943
swiftSettings: defaultSwiftSettings
4044
),
4145
.target(
4246
name: "SwiftRSS",
4347
dependencies: [
44-
.target(name: "SGML")
48+
.target(name: "SGML"),
4549
],
4650
swiftSettings: defaultSwiftSettings
4751
),
4852
.target(
4953
name: "SwiftSitemap",
5054
dependencies: [
51-
.target(name: "SGML")
55+
.target(name: "SGML"),
5256
],
5357
swiftSettings: defaultSwiftSettings
5458
),
5559
.target(
5660
name: "SwiftSVG",
5761
dependencies: [
58-
.target(name: "SGML")
62+
.target(name: "SGML"),
5963
],
6064
swiftSettings: defaultSwiftSettings
6165
),
6266
// MARK: - test
6367
.testTarget(
6468
name: "DOMTests",
6569
dependencies: [
66-
.target(name: "DOM")
70+
.target(name: "DOM"),
6771
]
6872
),
6973
.testTarget(
7074
name: "SGMLTests",
7175
dependencies: [
72-
.target(name: "SGML")
76+
.target(name: "SGML"),
7377
]
7478
),
7579
.testTarget(
7680
name: "SwiftHTMLTests",
7781
dependencies: [
78-
.target(name: "SwiftHTML")
82+
.target(name: "SwiftHTML"),
7983
]
8084
),
8185
.testTarget(
8286
name: "SwiftRSSTests",
8387
dependencies: [
84-
.target(name: "SwiftRSS")
88+
.target(name: "SwiftRSS"),
8589
]
8690
),
8791
.testTarget(
8892
name: "SwiftSitemapTests",
8993
dependencies: [
90-
.target(name: "SwiftSitemap")
94+
.target(name: "SwiftSitemap"),
9195
]
9296
),
9397
.testTarget(
9498
name: "SwiftSVGTests",
9599
dependencies: [
96-
.target(name: "SwiftSVG")
100+
.target(name: "SwiftSVG"),
97101
]
98102
),
99103
]

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ struct Alignment: Attribute {
178178
You can set, add, or remove attributes—or even modify individual attribute values—on any tag that supports attributes:
179179

180180
```swift
181-
P("lorem ipsum")
181+
P("Lorem ipsum")
182182
// set (override) the current attributes
183183
.setAttribute(Class("note"))
184184
.setAttributeValueBy(name: "style", value: "color: white;")
@@ -201,6 +201,20 @@ P("lorem ipsum")
201201

202202
There are built-in, type-safe attributes and helper modifiers available for the standard tags.
203203

204+
### Conditions
205+
206+
Use the `check` modifier to evaluate a condition and update an element when the condition is met:
207+
208+
```swift
209+
let condition = false
210+
211+
H1("Lorem ipsum")
212+
.check(condition) {
213+
$0.class("foo")
214+
} else: {
215+
$0.class("bar")
216+
}
217+
```
204218

205219
### Container elements
206220

Sources/SGML/Attributes/AttributeStore.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import DOM
22

3+
//import Collections
4+
35
public struct AttributeStore: Sendable {
46

57
private var storage: [String: [String?]]
@@ -24,6 +26,9 @@ public struct AttributeStore: Sendable {
2426
if storage[name] == nil {
2527
storage[name] = []
2628
}
29+
guard let value, !value.isEmpty else {
30+
return
31+
}
2732
guard !storage[name]!.contains(value) else {
2833
return
2934
}

Sources/SwiftHTML/Attributes/ClassAttribute.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ extension ClassAttributeModifier where Self: Attributes & Mutable {
4646
public func toggleClass(
4747
_ value: String?
4848
) -> Self {
49-
removeAttribute(ClassAttribute(value))
49+
if hasAttribute(ClassAttribute(value)) {
50+
removeAttribute(ClassAttribute(value))
51+
}
52+
else {
53+
addAttribute(ClassAttribute(value))
54+
}
5055
}
5156
}

Sources/SwiftSVG/Circle.swift

Lines changed: 0 additions & 25 deletions
This file was deleted.

Sources/SwiftSVG/Ellipse.swift

Lines changed: 0 additions & 27 deletions
This file was deleted.

Sources/SwiftSVG/Double+PreciseString.swift renamed to Sources/SwiftSVG/Extensions/Double+PreciseString.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
//
2-
// File.swift
3-
//
4-
//
5-
// Created by Tibor Bodecs on 2022. 02. 04..
6-
//
7-
81
extension Double {
92

10-
// @NOTE: this is a pure hack, but it works without using Foundation
3+
// NOTE: This is a hack, but it works without using Foundation
114
var preciseString: String {
125
if self - Double(Int(self)) == 0 {
136
return String(Int(self))

Sources/SwiftSVG/G.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

Sources/SwiftSVG/Line.swift

Lines changed: 0 additions & 27 deletions
This file was deleted.

Sources/SwiftSVG/Path.swift

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)