Skip to content

Commit 6c81c43

Browse files
authored
Tidy up some code (#199)
* Fix misspelled readonly attribute * Remove redundant lines by leveraging default parameter * Extend correct protocol * Fix some oversights in the code * Add the root property to editorconfig * Fix some code examples
1 parent 97df0a7 commit 6c81c43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+449
-1698
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
root = true
2+
13
[*.swift]
24
indent_style = space
35
indent_size = 4

Sources/HTMLKit/Abstraction/Attributes/BasicAttributes.swift

Lines changed: 20 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public protocol AccessKeyAttribute: Attribute {
1515
/// Anchor {
1616
/// "Lorem ipsum..."
1717
/// }
18-
/// .accessKey="A"
18+
/// .accessKey("A")
1919
/// ```
2020
///
2121
/// - Parameter value: The key to press.
@@ -117,7 +117,7 @@ extension ActionAttribute where Self: EmptyNode {
117117
@_documentation(visibility: internal)
118118
public protocol AlternateAttribute: Attribute {
119119

120-
/// Provide an alternative information
120+
/// Provide an alternative information.
121121
///
122122
/// ```swift
123123
/// Image()
@@ -129,7 +129,7 @@ public protocol AlternateAttribute: Attribute {
129129
/// - Returns: The element
130130
func alternate(_ value: String) -> Self
131131

132-
/// Provide an alternative information
132+
/// Provide an alternative information.
133133
///
134134
/// ```swift
135135
/// Image()
@@ -349,16 +349,6 @@ extension AutofocusAttribute where Self: EmptyNode {
349349
@_documentation(visibility: internal)
350350
public protocol AutoplayAttribute: Attribute {
351351

352-
/// Mark the video as autoplay.
353-
///
354-
/// ```swift
355-
/// Video {
356-
/// Source()
357-
/// }
358-
/// .autoplay()
359-
/// ```
360-
func autoplay() -> Self
361-
362352
/// Mark the video as autoplay.
363353
///
364354
/// ```swift
@@ -423,16 +413,7 @@ extension CharsetAttribute where Self: EmptyNode {
423413
@_documentation(visibility: internal)
424414
public protocol CheckedAttribute: Attribute {
425415

426-
/// Mark an input as pre-selected
427-
///
428-
/// ```swift
429-
/// Input()
430-
/// .type(.radio)
431-
/// .checked()
432-
/// ```
433-
func checked() -> Self
434-
435-
/// Mark an input as pre-selected
416+
/// Mark an input as pre-selected.
436417
///
437418
/// ```swift
438419
/// Input()
@@ -697,7 +678,7 @@ extension EditAttribute where Self: EmptyNode {
697678
@_documentation(visibility: internal)
698679
public protocol ControlsAttribute: Attribute {
699680

700-
/// Display the controls
681+
/// Display the controls.
701682
///
702683
/// ```swift
703684
/// Audio {
@@ -950,14 +931,6 @@ extension DirectionAttribute where Self: EmptyNode {
950931
@_documentation(visibility: internal)
951932
public protocol DisabledAttribute: Attribute {
952933

953-
/// Disable the element.
954-
///
955-
/// ```swift
956-
/// Input()
957-
/// .disabled()
958-
/// ```
959-
func disabled() -> Self
960-
961934
/// Disable the element.
962935
///
963936
/// ```swift
@@ -1315,18 +1288,6 @@ extension HeightAttribute where Self: EmptyNode {
13151288
@_documentation(visibility: internal)
13161289
public protocol HiddenAttribute: Attribute {
13171290

1318-
/// Hide an element.
1319-
///
1320-
/// ```swift
1321-
/// Paragraph {
1322-
/// "Lorem ipsum..."
1323-
/// }
1324-
/// .hidden()
1325-
/// ```
1326-
///
1327-
/// - Returns: The element
1328-
func hidden() -> Self
1329-
13301291
/// Hide an element.
13311292
///
13321293
/// ```swift
@@ -1892,7 +1853,7 @@ public protocol KindAttribute: Attribute {
18921853
///
18931854
/// ```swift
18941855
/// Track()
1895-
/// .src(...vtt)
1856+
/// .source("...vtt")
18961857
/// .kind(.chapters)
18971858
/// ```
18981859
///
@@ -1924,7 +1885,7 @@ public protocol LabelAttribute: Attribute {
19241885
///
19251886
/// ```swift
19261887
/// Track()
1927-
/// .src(...vtt)
1888+
/// .source("...vtt")
19281889
/// .kind(.chapters)
19291890
/// .label("lorem")
19301891
/// ```
@@ -2017,7 +1978,7 @@ extension ListAttribute where Self: EmptyNode {
20171978
@_documentation(visibility: internal)
20181979
public protocol LoopAttribute: Attribute {
20191980

2020-
/// Activate auto play
1981+
/// Activate autoplay.
20211982
///
20221983
/// It specifies that the element will start over again, every time it is finished.
20231984
///
@@ -2701,9 +2662,10 @@ extension PosterAttribute where Self: EmptyNode {
27012662
}
27022663

27032664
/// A type that provides the `playInline` modifier.
2665+
@_documentation(visibility: internal)
27042666
public protocol PlaysInlineAttribute: Attribute {
27052667

2706-
/// Enables inline playback
2668+
/// Enables inline playback.
27072669
///
27082670
/// It specifies that the element should not use the native fullscreen mode when playing.
27092671
///
@@ -2742,7 +2704,7 @@ public protocol PreloadAttribute: Attribute {
27422704
/// ```swift
27432705
/// Video {
27442706
/// Source()
2745-
/// .source("")
2707+
/// .source("https://...")
27462708
/// .type(.mp4)
27472709
/// }
27482710
/// .preload(.auto)
@@ -2770,17 +2732,7 @@ extension PreloadAttribute where Self: EmptyNode {
27702732

27712733
/// A type that provides the `readonly` modifier.
27722734
@_documentation(visibility: internal)
2773-
public protocol ReadyOnlyAttribute: Attribute {
2774-
2775-
/// Mark the input as read only.
2776-
///
2777-
/// ```swift
2778-
/// Input()
2779-
/// .readonly()
2780-
/// ```
2781-
///
2782-
/// - Returns: The element
2783-
func readonly() -> Self
2735+
public protocol ReadOnlyAttribute: Attribute {
27842736

27852737
/// Mark the input as read only based on a condition.
27862738
///
@@ -2795,14 +2747,14 @@ public protocol ReadyOnlyAttribute: Attribute {
27952747
func readonly(_ condition: Bool) -> Self
27962748
}
27972749

2798-
extension ReadyOnlyAttribute where Self: ContentNode {
2750+
extension ReadOnlyAttribute where Self: ContentNode {
27992751

28002752
internal func mutate(readonly value: String) -> Self {
28012753
return self.mutate(key: "readonly", value: value)
28022754
}
28032755
}
28042756

2805-
extension ReadyOnlyAttribute where Self: EmptyNode {
2757+
extension ReadOnlyAttribute where Self: EmptyNode {
28062758

28072759
internal func mutate(readonly value: String) -> Self {
28082760
return self.mutate(key: "readonly", value: value)
@@ -2874,16 +2826,6 @@ extension RelationshipAttribute where Self: EmptyNode {
28742826
@_documentation(visibility: internal)
28752827
public protocol RequiredAttribute: Attribute {
28762828

2877-
/// Mark an input as required.
2878-
///
2879-
/// ```swift
2880-
/// Input()
2881-
/// .required()
2882-
/// ```
2883-
///
2884-
/// - Returns: The element
2885-
func required() -> Self
2886-
28872829
/// Mark an input as required based on a condition.
28882830
///
28892831
/// ```swift
@@ -3336,7 +3278,7 @@ public protocol SourceAttribute: Attribute {
33363278
/// Audio {
33373279
/// Source()
33383280
/// .type(.mpeg)
3339-
/// .source(....mpeg)
3281+
/// .source("...mpeg")
33403282
/// }
33413283
/// ```
33423284
/// - Parameter url: The url to load from.
@@ -3350,7 +3292,7 @@ public protocol SourceAttribute: Attribute {
33503292
/// Audio {
33513293
/// Source()
33523294
/// .type(.mpeg)
3353-
/// .source()
3295+
/// .source("...mpeg")
33543296
/// }
33553297
/// ```
33563298
/// - Parameter url: The url to load from.
@@ -4017,17 +3959,6 @@ extension ShadowRootModeAttribute where Self: ContentNode {
40173959
@_documentation(visibility: internal)
40183960
public protocol InertAttribute: Attribute {
40193961

4020-
/// Disable the element and the content of the element.
4021-
///
4022-
/// ```swift
4023-
/// Division {
4024-
/// }
4025-
/// .inert()
4026-
/// ```
4027-
///
4028-
/// - Returns: The element
4029-
func inert() -> Self
4030-
40313962
/// Disable the element and the content of the element based on a condition.
40323963
///
40333964
/// ```swift
@@ -4275,14 +4206,14 @@ public protocol PopoverTargetAttribute: Attribute {
42754206
func popoverTarget(_ id: String) -> Self
42764207
}
42774208

4278-
extension PopoverAttribute where Self: ContentNode {
4209+
extension PopoverTargetAttribute where Self: ContentNode {
42794210

42804211
internal func mutate(popovertarget value: String) -> Self {
42814212
return self.mutate(key: "popovertarget", value: value)
42824213
}
42834214
}
42844215

4285-
extension PopoverAttribute where Self: EmptyNode {
4216+
extension PopoverTargetAttribute where Self: EmptyNode {
42864217

42874218
internal func mutate(popovertarget value: String) -> Self {
42884219
return self.mutate(key: "popovertarget", value: value)
@@ -4309,14 +4240,14 @@ public protocol PopoverActionAttribute: Attribute {
43094240
func popoverAction(_ action: Values.Popover.Action) -> Self
43104241
}
43114242

4312-
extension PopoverAttribute where Self: ContentNode {
4243+
extension PopoverActionAttribute where Self: ContentNode {
43134244

43144245
internal func mutate(popoveraction value: String) -> Self {
43154246
return self.mutate(key: "popovertargetaction", value: value)
43164247
}
43174248
}
43184249

4319-
extension PopoverAttribute where Self: EmptyNode {
4250+
extension PopoverActionAttribute where Self: EmptyNode {
43204251

43214252
internal func mutate(popoveraction value: String) -> Self {
43224253
return self.mutate(key: "popovertargetaction", value: value)

Sources/HTMLKit/Abstraction/Attributes/VectorAttributes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public protocol NamespaceAttribute: Attribute {
400400
/// .namespace("http://...")
401401
/// ```
402402
///
403-
/// - Parameter url: The url to refer to
403+
/// - Parameter url: The url to refer to.
404404
///
405405
/// - Returns: The element
406406
func namespace(_ url: String) -> Self

Sources/HTMLKit/Abstraction/Elements/BasicElements.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import OrderedCollections
1010
/// ```
1111
public struct Comment: CommentNode, GlobalElement {
1212

13-
public var content: String
13+
internal var content: String
1414

1515
/// Create a comment.
1616
///
@@ -35,7 +35,7 @@ public struct Comment: CommentNode, GlobalElement {
3535
/// ```
3636
public struct Document: DocumentNode, BasicElement {
3737

38-
public var content: String
38+
internal var content: String
3939

4040
/// Create a document.
4141
///
@@ -139,12 +139,8 @@ extension Html: GlobalAttributes, GlobalEventAttributes {
139139
public func enterKeyHint(_ value: Values.Hint) -> Html {
140140
return mutate(enterkeyhint: value.rawValue)
141141
}
142-
143-
public func hidden() -> Html {
144-
return mutate(hidden: "hidden")
145-
}
146142

147-
public func hidden(_ condition: Bool) -> Html {
143+
public func hidden(_ condition: Bool = true) -> Html {
148144

149145
if condition {
150146
return mutate(hidden: "hidden")
@@ -243,11 +239,7 @@ extension Html: GlobalAttributes, GlobalEventAttributes {
243239
return mutate(translate: value.rawValue)
244240
}
245241

246-
public func inert() -> Html {
247-
return mutate(inert: "inert")
248-
}
249-
250-
public func inert(_ condition: Bool) -> Html {
242+
public func inert(_ condition: Bool = true) -> Html {
251243

252244
if condition {
253245
return mutate(inert: "inert")

0 commit comments

Comments
 (0)