Skip to content

Commit bf246ad

Browse files
committed
Update documentation and clean up code
1 parent a780c79 commit bf246ad

File tree

6 files changed

+62
-43
lines changed

6 files changed

+62
-43
lines changed

Package.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:6.0
22

33
import PackageDescription
44

55
let package = Package(
66
name: "TagKit",
77
platforms: [
8-
.iOS(.v15),
9-
.macOS(.v12),
10-
.tvOS(.v15),
11-
.watchOS(.v10),
8+
.iOS(.v16),
9+
.macOS(.v13),
10+
.tvOS(.v16),
11+
.watchOS(.v9),
1212
.visionOS(.v1)
1313
],
1414
products: [

RELEASE_NOTES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ TagKit will use semver after 1.0.
44

55

66

7+
## 0.5
8+
9+
This version makes TagKit use Swift 6.
10+
11+
12+
713
## 0.4.1
814

915
This version temporarily downgrades to Swift 5.9 since Xcode 16.1 made things stop working.

Sources/TagKit/SlugConfiguration.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,43 @@ import Foundation
1111
/// This configuration defines how ``Slugifiable`` types are
1212
/// slugified.
1313
///
14-
/// Use the ``SlugConfiguration/standard`` configuration for
15-
/// the default behavior, which limits the slugified strings
16-
/// to `a-z` and `1-9`, using `-` as separator.
14+
/// The standard configuration allows `a-z`, `A-Z` and `0-9`,
15+
/// and will e.g. slugify `Hello, world!` into `hello-world`.
1716
public struct SlugConfiguration {
1817

1918
/// Create a new slug configurator.
2019
///
2120
/// - Parameters:
2221
/// - separator: The separator to use in the slugified string, by default `-`.
23-
/// - allowedCharacters: The characters to allow in the slugified string, by default alphanumerical characters and `-`.
22+
/// - allowedCharacters: The characters to allow in the slugified string, by default `a-zA-Z0-9`.
2423
public init(
2524
separator: String = "-",
2625
allowedCharacters: String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
2726
) {
2827
let chars = allowedCharacters + separator
2928
self.separator = separator
3029
self.allowedCharacters = chars
31-
self.allowedCharacterSet = NSCharacterSet(charactersIn: chars)
30+
let allowedSet = NSCharacterSet(charactersIn: chars)
31+
self.allowedCharacterSet = allowedSet
32+
self.notAllowedCharacterSet = allowedSet.inverted
3233
}
3334

3435
/// The separator to use in the slugified string.
3536
public let separator: String
3637

3738
/// The characters to allow in the slugified string.
3839
public let allowedCharacters: String
39-
40-
/// The character set to allow in the slugified string.
40+
41+
/// The characters to allow in the slugified string.
4142
public let allowedCharacterSet: NSCharacterSet
43+
44+
/// The characters to not allow in the slugified string.
45+
public let notAllowedCharacterSet: CharacterSet
4246
}
4347

4448
public extension SlugConfiguration {
4549

46-
/// A standard slug configuration, that allows `a-z` and
47-
/// `1-9` and uses `-` as the component separator.
50+
/// A standard slug configuration, with `-` as component
51+
/// separator and `a-zA-Z0-9` as allowed characters.
4852
static var standard: SlugConfiguration { .init() }
4953
}

Sources/TagKit/Slugifiable.swift

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,8 @@
88

99
import Foundation
1010

11-
/// This protocol describes a slugifiable type, which can be
12-
/// represented as a slugified string.
13-
///
14-
/// Slugified strings are for instance used in urls and tags,
15-
/// where a text is represented by removing unsupported text
16-
/// components. The standard format can be customized with a
17-
/// custom ``SlugConfiguration``.
18-
///
19-
/// By default, `Hello, world!` is slugified to `hello-world`.
11+
/// This protocol can be implemented by any type that can be
12+
/// converted to a slugified string.
2013
///
2114
/// This protocol is automatically implemented by `String`.
2215
public protocol Slugifiable {
@@ -37,12 +30,10 @@ public extension Slugifiable {
3730
func slugified(
3831
configuration: SlugConfiguration = .standard
3932
) -> String {
40-
let chars = configuration.allowedCharacterSet.inverted
41-
let separator = configuration.separator
42-
return slugifiableValue.lowercased()
43-
.components(separatedBy: chars)
33+
slugifiableValue.lowercased()
34+
.components(separatedBy: configuration.notAllowedCharacterSet)
4435
.filter { !$0.isEmpty }
45-
.joined(separator: separator)
36+
.joined(separator: configuration.separator)
4637
}
4738
}
4839

Sources/TagKit/Views/FlowLayout.swift

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,52 @@ private extension FlowLayout {
7575

7676
var content: some View {
7777
GeometryReader { geometry in
78-
content(in: geometry)
78+
content(in: geometry.size)
7979
}
8080
}
8181

82-
func content(in g: GeometryProxy) -> some View {
82+
func content(in size: CGSize) -> some View {
8383
var width = CGFloat.zero
8484
var height = CGFloat.zero
8585
var lastHeight = CGFloat.zero
8686
let itemCount = items.count
87+
let itemVews = items.enumerated().map { element in
88+
let index = element.offset
89+
let item = element.element
90+
itemView(item)
91+
.padding([.horizontal], horizontalSpacing)
92+
.padding([.vertical], verticalSpacing)
93+
.alignmentGuide(.leading, computeValue: { d in
94+
if abs(width - d.width) > size.width {
95+
width = 0
96+
height -= lastHeight
97+
}
98+
lastHeight = d.height
99+
let result = width
100+
if index == itemCount - 1 {
101+
width = 0
102+
} else {
103+
width -= d.width
104+
}
105+
return result
106+
})
107+
.alignmentGuide(.top, computeValue: { _ in
108+
let result = height
109+
if index == itemCount - 1 {
110+
height = 0
111+
}
112+
return result
113+
})
114+
}
115+
116+
87117
return ZStack(alignment: .topLeading) {
88118
ForEach(Array(items.enumerated()), id: \.offset) { index, item in
89119
itemView(item)
90120
.padding([.horizontal], horizontalSpacing)
91121
.padding([.vertical], verticalSpacing)
92122
.alignmentGuide(.leading, computeValue: { d in
93-
if abs(width - d.width) > g.size.width {
123+
if abs(width - d.width) > size.width {
94124
width = 0
95125
height -= lastHeight
96126
}

Sources/TagKit/_Deprecated/TagCapsule+Deprecated.swift

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

0 commit comments

Comments
 (0)