Skip to content

Commit 0cb74c9

Browse files
committed
Update documentation
1 parent f2c1ee9 commit 0cb74c9

File tree

7 files changed

+130
-119
lines changed

7 files changed

+130
-119
lines changed

README.md

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414

1515
# TagKit
1616

17-
TagKit is a Swift SDK that makes it easy to work with tags and string/ID slugification in `Swift` and `SwiftUI`.
17+
TagKit is a Swift SDK that makes it easy to work with tags and slugify strings in `Swift` and `SwiftUI`.
1818

1919
<p align="center">
2020
<img src="Resources/Demo-v2.gif" width=450 />
2121
</p>
2222

23-
Tags and tag views can be customized to fit your needs. You can slug and tag any model and customize the slug format. When presenting tags, you can apply custom styling and use any views you like.
24-
25-
TagKit also has a views that make it easier to work with tags. For instance, ``TagList`` and ``TagEditList`` let you list and edit tags, ``TagCapsule`` renders styled tags and ``TagTextField`` automatically slugifies text as you type.
23+
You can slug and tag any type, customize the slug format, and use the built-in views to list and edit tags with ease.
2624

2725

2826

@@ -39,7 +37,47 @@ https://github.com/danielsaidi/TagKit.git
3937

4038
## Getting started
4139

42-
The online documentation has a [getting-started guide][Getting-Started] that helps you get started with TagKit.
40+
TagKit lets you slugify strings and manage tags for any taggable type.
41+
42+
43+
### Slugs
44+
45+
Slugifying a string means to remove unwanted characters and replacing whitespaces with a separator. This is often used in urls, where a page slug creates a unique, valid url that also describes the content.
46+
47+
TagKit has a ``Swift/String/slugified(with:)`` string extension that lets you slugify strings with a standard or custom ``SlugConfiguration``:
48+
49+
```
50+
let custom = SlugConfiguration(
51+
separator: "+",
52+
allowedCharacters: .init(charactersIn: "hewo")
53+
)
54+
55+
"Hello, world!".slugified() // "hello-world"
56+
"Hello, world!".slugified(with: custom) // "he+wo"
57+
```
58+
59+
Slugified strings are automatically lowercased, since a slug should be case-insensitively unique.
60+
61+
62+
### Tags
63+
64+
Tagging is the process of adding tags to an item, with the intent to categorize, group, filter and search among tags.
65+
66+
TagKit has a ``Taggable`` protocol that can be implemented by any type that has mutable ``Taggable/tags``:
67+
68+
```swift
69+
public protocol Taggable {
70+
71+
var tags: [String] { get set }
72+
}
73+
```
74+
75+
Once a type implements ``Taggable``, it can make use of a lot of automatically implemented functionality that the protocol provides, like ``Taggable/hasTags``, ``Taggable/slugifiedTags``, ``Taggable/addTag(_:)``, ``Taggable/removeTag(_:)``, ``Taggable/toggleTag(_:)``. All ``Taggable`` collections are extended as well.
76+
77+
78+
### Views
79+
80+
TagKit has a bunch of tag related types, like ``TagCapsule``, ``TagList``, ``TagEditList`` and ``TagTextField``.
4381

4482

4583

@@ -85,5 +123,4 @@ TagKit is available under the MIT license. See the [LICENSE][License] file for m
85123
[Twitter]: https://twitter.com/danielsaidi
86124

87125
[Documentation]: https://danielsaidi.github.io/TagKit
88-
[Getting-Started]: https://danielsaidi.github.io/TagKit/documentation/tagkit/getting-started
89126
[License]: https://github.com/danielsaidi/TagKit/blob/master/LICENSE

RELEASE_NOTES.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ TagKit will use semver after 1.0.
88

99
This version makes TagKit use Swift 6.
1010

11+
### 🗑️ Deprecated
12+
13+
* `Slugifiable` has been deprecated. Just use the `slugified` string extension instead.
14+
1115
### 💥 Breaking Changes
1216

13-
* `FlowLayout` did not support Swift 6 strict concurrency and has been removed.
17+
* `FlowLayout` could not be refactored to support strict concurrency, and has been removed.
1418

1519

1620

Sources/TagKit/SlugConfiguration.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ import Foundation
1111
/// This configuration defines how ``Slugifiable`` types are
1212
/// slugified.
1313
///
14-
/// The standard configuration allows `a-z`, `A-Z` and `0-9`,
15-
/// and will e.g. slugify `Hello, world!` into `hello-world`.
14+
/// The standard configuration allows `a-z0-9`, and will for
15+
/// instance slugify `Hello, world!` into `hello-world`.
1616
public struct SlugConfiguration {
1717

1818
/// Create a new slug configurator.
1919
///
2020
/// - Parameters:
2121
/// - separator: The separator to use in the slugified string, by default `-`.
22-
/// - allowedCharacters: The characters to allow in the slugified string, by default `a-zA-Z0-9`.
22+
/// - allowedCharacters: The characters to allow in the slugified string, by default `a-z0-9`.
2323
public init(
2424
separator: String = "-",
25-
allowedCharacters: String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
25+
allowedCharacters: String = "abcdefghijklmnopqrstuvwxyz0123456789"
2626
) {
2727
let chars = allowedCharacters + separator
2828
self.separator = separator

Sources/TagKit/String+Slugified.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// String+Slug.swift
3+
// TagKit
4+
//
5+
// Created by Daniel Saidi on 2022-08-18.
6+
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public extension String {
12+
13+
/// Create a slugified version of the string.
14+
///
15+
/// - Parameters:
16+
/// - configuration: The configuration to use, by default ``SlugConfiguration/standard``.
17+
func slugified(
18+
with configuration: SlugConfiguration = .standard
19+
) -> String {
20+
lowercased()
21+
.components(separatedBy: configuration.notAllowedCharacterSet)
22+
.filter { !$0.isEmpty }
23+
.joined(separator: configuration.separator)
24+
}
25+
}

Sources/TagKit/TagKit.docc/Getting-Started.md

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

Sources/TagKit/TagKit.docc/TagKit.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ TagKit is a Swift SDK that makes it easy to work with tags and slugification in
88

99
![TagKit logo](Logo.png)
1010

11-
TagKit is a Swift SDK that makes it easy to work with tags and slugification in `Swift` and `SwiftUI`.
12-
13-
Tags and views can be customized to fit your needs. You can slug and tag any model and customize the slug format. When presenting tags, you can apply custom styling and use any views you like.
11+
TagKit is a Swift SDK that makes it easy to work with tags and slugified strings in `Swift` and `SwiftUI`.
1412

15-
TagKit also has a views that make it easier to work with tags. For instance, ``TagList`` and ``TagEditList`` let you list and edit tags, ``TagCapsule`` renders styled tags and ``TagTextField`` automatically slugifies text as you type.
13+
You can slug and tag any type and customize the slug format, and use the built-in views to list and edit tags with minimum effort.
1614

1715

1816

@@ -28,7 +26,48 @@ https://github.com/danielsaidi/TagKit.git
2826

2927
## Getting started
3028

31-
The <doc:Getting-Started> article helps you get started with TagKit.
29+
TagKit lets you slugify strings and manage tags for any taggable type.
30+
31+
32+
### Slugs
33+
34+
Slugifying a string means to remove unwanted characters and replacing whitespaces with a separator. This is often used in urls, where a page slug creates a unique, valid url that also describes the content.
35+
36+
TagKit has a ``Swift/String/slugified(with:)`` string extension that lets you slugify strings with a standard or custom ``SlugConfiguration``:
37+
38+
```
39+
let custom = SlugConfiguration(
40+
separator: "+",
41+
allowedCharacters: .init(charactersIn: "hewo")
42+
)
43+
44+
"Hello, world!".slugified() // "hello-world"
45+
"Hello, world!".slugified(with: custom) // "he+wo"
46+
```
47+
48+
Slugified strings are automatically lowercased, since a slug should be case-insensitively unique.
49+
50+
51+
### Tags
52+
53+
Tagging is the process of adding tags to an item, with the intent to categorize, group, filter and search among tags.
54+
55+
TagKit has a ``Taggable`` protocol that can be implemented by any type that has mutable ``Taggable/tags``:
56+
57+
```swift
58+
public protocol Taggable {
59+
60+
var tags: [String] { get set }
61+
}
62+
```
63+
64+
Once a type implements ``Taggable``, it can make use of a lot of automatically implemented functionality that the protocol provides, like ``Taggable/hasTags``, ``Taggable/slugifiedTags``, ``Taggable/addTag(_:)``, ``Taggable/removeTag(_:)``, ``Taggable/toggleTag(_:)``. All ``Taggable`` collections are extended as well.
65+
66+
67+
### Views
68+
69+
TagKit has a bunch of tag related types, like ``TagCapsule``, ``TagList``, ``TagEditList`` and ``TagTextField``.
70+
3271

3372

3473

Sources/TagKit/Slugifiable.swift renamed to Sources/TagKit/_Deprecated/Slugifiable.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88

99
import Foundation
1010

11-
/// This protocol can be implemented by any type that can be
12-
/// converted to a slugified string.
13-
///
14-
/// This protocol is automatically implemented by `String`.
11+
@available(*, deprecated, renamed: "Sluggable")
1512
public protocol Slugifiable {
1613

1714
/// The value used to create a slugified representation.
1815
var slugifiableValue: String { get }
1916
}
2017

18+
@available(*, deprecated, renamed: "Sluggable")
2119
public extension Slugifiable {
2220

2321
/// Convert the slugifiable value to a slugified string.
@@ -37,7 +35,12 @@ public extension Slugifiable {
3735
}
3836
}
3937

40-
extension String: Slugifiable {
38+
public extension String {
4139

42-
public var slugifiableValue: String { self }
40+
@available(*, deprecated, renamed: "slugified(with:)")
41+
func slugified(
42+
configuration: SlugConfiguration
43+
) -> String {
44+
slugified(with: configuration)
45+
}
4346
}

0 commit comments

Comments
 (0)