Skip to content

Commit 598a7d1

Browse files
authored
Refactor codebase to align with Swift API Design Guidelines (#80)
* Refactor core HTML protocols and builders to Markup - Rename HTML protocol to Markup for Swift API Design Guidelines compliance - Rename HTMLBuilder to MarkupBuilder with updated documentation - Rename HTMLString to MarkupString for consistency - Update AnyHTML to AnyMarkup with proper type erasure - Rename HTMLClassContainer to MarkupClassContainer - Rename HTMLContentBuilder to MarkupContentBuilder - Update all documentation to use 'markup' terminology - Rename AttributeBuilder.renderTag to buildMarkupTag for clarity - Move files from HTML/ directory to Markup/ directory * Complete HTML to Markup refactoring across entire codebase - Update all 85+ Swift files to use Markup instead of HTML types - Replace HTMLBuilder with MarkupBuilder throughout codebase - Update all protocol conformances and type annotations - Replace renderTag with buildMarkupTag method name - Update documentation to use 'markup' and 'stylesheet' terminology - Maintain backward compatibility for actual HTML tag output - All tests passing after comprehensive refactor * Expand abbreviations and improve method names per Swift API Design Guidelines - CSS → StyleSheet: sanitizedForCSS() → sanitizedForStyleSheet() - URL → WebAddress: baseURL → baseWebAddress throughout APIs - XML → ExtensibleMarkupLanguageDocument: generateXML() → generateExtensibleMarkupLanguageDocument() - Improve method clarity: getData() → retrieveStructuredDataDictionary() - Improve method clarity: toJSON() → convertToJsonString() - Boolean properties to assertions: generateSitemap → shouldGenerateSitemap - Boolean properties to assertions: generateRobotsTxt → shouldGenerateRobotsTxt - Add backward compatibility aliases with deprecation warnings - Update all references across codebase and tests - All 367 tests passing with new method names * Improve parameter labels for better call-site clarity - AttributeBuilder.buildAttributes: Add clear parameter labels (identifier, styleSheetClasses, ariaRole, etc.) - StyleOperation: Add alternative methods with clearer labels (using, with configuration) - Input component: Improve event handler parameter label clarity - Add backward compatibility overloads to maintain existing API - All 254 tests passing with improved parameter clarity - Complete Swift API Design Guidelines compliance
1 parent a41ae6d commit 598a7d1

File tree

91 files changed

+804
-666
lines changed

Some content is hidden

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

91 files changed

+804
-666
lines changed

Sources/WebUI/Core/HTML/Attribute.swift renamed to Sources/WebUI/Core/Markup/Attribute.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
public enum Attribute {
2-
/// Builds an HTML attribute string if the value exists.
2+
/// Builds a markup attribute string if the value exists.
33
///
44
/// - Parameters:
55
/// - name: Attribute name (e.g., "id", "class", "src").
@@ -10,7 +10,7 @@ public enum Attribute {
1010
return "\(name)=\"\(value)\""
1111
}
1212

13-
/// Builds a boolean HTML attribute if enabled.
13+
/// Builds a boolean markup attribute if enabled.
1414
///
1515
/// - Parameters:
1616
/// - name: Attribute name (e.g., "disabled", "checked", "required").
@@ -20,7 +20,7 @@ public enum Attribute {
2020
enabled == true ? name : nil
2121
}
2222

23-
/// Builds an HTML attribute string from a typed enum value.
23+
/// Builds a markup attribute string from a typed enum value.
2424
///
2525
/// - Parameters:
2626
/// - name: Attribute name (e.g., "type", "role").

Sources/WebUI/Core/HTML/AttributeBuilder.swift renamed to Sources/WebUI/Core/Markup/AttributeBuilder.swift

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import Foundation
22

3-
/// Utility for building HTML attributes
3+
/// Utility for building markup attributes
44
///
5-
/// The `AttributeBuilder` provides helper methods for generating HTML
5+
/// The `AttributeBuilder` provides helper methods for generating markup
66
/// attribute strings in a consistent way across all elements.
77
public enum AttributeBuilder {
8-
/// Builds a collection of HTML attributes from common parameters
8+
/// Builds a collection of markup attributes from common parameters
99
///
1010
/// - Parameters:
11-
/// - id: Optional unique identifier for the HTML element
12-
/// - classes: Optional array of CSS class names
11+
/// - id: Optional unique identifier for the markup element
12+
/// - classes: Optional array of stylesheet class names
1313
/// - role: Optional ARIA role for accessibility
1414
/// - label: Optional ARIA label for accessibility
1515
/// - data: Optional dictionary of data attributes
1616
/// - additional: Optional array of additional attribute strings
17-
/// - Returns: Array of attribute strings for use in HTML tags
17+
/// - Returns: Array of attribute strings for use in markup tags
1818
public static func buildAttributes(
19-
id: String? = nil,
20-
classes: [String]? = nil,
21-
role: AriaRole? = nil,
22-
label: String? = nil,
23-
data: [String: String]? = nil,
24-
additional: [String] = []
19+
identifier id: String? = nil,
20+
styleSheetClasses classes: [String]? = nil,
21+
ariaRole role: AriaRole? = nil,
22+
ariaLabel label: String? = nil,
23+
dataAttributes data: [String: String]? = nil,
24+
additionalAttributes additional: [String] = []
2525
) -> [String] {
2626
var attributes: [String] = []
2727

@@ -54,17 +54,48 @@ public enum AttributeBuilder {
5454
attributes.append(contentsOf: additional)
5555
return attributes
5656
}
57+
58+
/// Builds a collection of markup attributes from common parameters (backward compatibility)
59+
///
60+
/// This overload maintains backward compatibility with existing code.
61+
/// Consider using the version with clearer parameter labels for new code.
62+
///
63+
/// - Parameters:
64+
/// - id: Optional unique identifier for the markup element
65+
/// - classes: Optional array of stylesheet class names
66+
/// - role: Optional ARIA role for accessibility
67+
/// - label: Optional ARIA label for accessibility
68+
/// - data: Optional dictionary of data attributes
69+
/// - additional: Optional array of additional attribute strings
70+
/// - Returns: Array of attribute strings for use in markup tags
71+
public static func buildAttributes(
72+
id: String? = nil,
73+
classes: [String]? = nil,
74+
role: AriaRole? = nil,
75+
label: String? = nil,
76+
data: [String: String]? = nil,
77+
additional: [String] = []
78+
) -> [String] {
79+
return buildAttributes(
80+
identifier: id,
81+
styleSheetClasses: classes,
82+
ariaRole: role,
83+
ariaLabel: label,
84+
dataAttributes: data,
85+
additionalAttributes: additional
86+
)
87+
}
5788

58-
/// Renders a complete HTML tag with attributes and content
89+
/// Renders a complete markup tag with attributes and content
5990
///
6091
/// - Parameters:
61-
/// - tag: The HTML tag name
92+
/// - tag: The markup tag name
6293
/// - attributes: Array of attribute strings
6394
/// - content: Optional content to include between opening and closing tags
6495
/// - isSelfClosing: Whether this is a self-closing tag
6596
/// - noClosingTag: Whether this should be rendered without a self-close and without a seperate close
66-
/// - Returns: Complete HTML tag as a string
67-
public static func renderTag(
97+
/// - Returns: Complete markup tag as a string
98+
public static func buildMarkupTag(
6899
_ tag: String,
69100
attributes: [String],
70101
content: String = "",

Sources/WebUI/Core/HTML/HTML.swift renamed to Sources/WebUI/Core/Markup/Markup.swift

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import Foundation
22

3-
/// Represents an HTML component or element.
3+
/// Represents a markup component or element.
44
///
5-
/// The `HTML` protocol is the foundation for all HTML elements in WebUI. It
5+
/// The `Markup` protocol is the foundation for all markup elements in WebUI. It
66
/// defines how components describe their structure and content.
77
///
8-
/// Elements conforming to HTML can be composed together to create complex
8+
/// Elements conforming to Markup can be composed together to create complex
99
/// layouts while maintaining a declarative syntax. The protocol handles both
10-
/// primitive HTML string content and composite element structures.
10+
/// primitive markup string content and composite element structures.
1111
///
1212
/// ## Example
1313
/// ```swift
1414
/// struct CustomCard: Element {
1515
/// var title: String
1616
/// var content: String
1717
///
18-
/// var body: some HTML {
18+
/// var body: some Markup {
1919
/// Stack {
2020
/// Heading(.title) { title }
2121
/// Text { content }
@@ -26,42 +26,42 @@ import Foundation
2626
/// }
2727
/// }
2828
/// ```
29-
public protocol HTML {
30-
/// The type of HTML content this component produces.
31-
associatedtype Body: HTML
29+
public protocol Markup {
30+
/// The type of markup content this component produces.
31+
associatedtype Body: Markup
3232

33-
/// The content and structure of this HTML component.
33+
/// The content and structure of this markup component.
3434
///
3535
/// The `body` property defines the component's layout and content
3636
/// hierarchy. This pattern mirrors SwiftUI's declarative syntax, making
3737
/// the code more intuitive and maintainable.
3838
///
39-
/// - Returns: A composition of HTML elements that make up this component.
39+
/// - Returns: A composition of markup elements that make up this component.
4040
var body: Body { get }
4141

42-
/// Renders the HTML component to its string representation.
42+
/// Renders the markup component to its string representation.
4343
///
44-
/// This method converts the HTML component into its final HTML string representation
45-
/// for output to files or HTTP responses.
44+
/// This method converts the markup component into its final markup string representation
45+
/// for output to files or responses.
4646
///
47-
/// - Returns: The rendered HTML string.
47+
/// - Returns: The rendered markup string.
4848
func render() -> String
4949
}
5050

51-
/// A type-erased HTML component.
51+
/// A type-erased markup component.
5252
///
53-
/// `AnyHTML` wraps any HTML-conforming type, allowing for type erasure in
53+
/// `AnyMarkup` wraps any Markup-conforming type, allowing for type erasure in
5454
/// heterogeneous collections or when specific type information isn't needed.
55-
public struct AnyHTML: HTML {
56-
private let wrapped: any HTML
55+
public struct AnyMarkup: Markup {
56+
private let wrapped: any Markup
5757
private let renderClosure: () -> String
5858

59-
public init<T: HTML>(_ html: T) {
60-
self.wrapped = html
61-
self.renderClosure = { html.render() }
59+
public init<T: Markup>(_ markup: T) {
60+
self.wrapped = markup
61+
self.renderClosure = { markup.render() }
6262
}
6363

64-
public var body: AnyHTML {
64+
public var body: AnyMarkup {
6565
self
6666
}
6767

@@ -70,13 +70,13 @@ public struct AnyHTML: HTML {
7070
}
7171
}
7272

73-
/// Primitive HTML string content.
73+
/// Primitive markup string content.
7474
///
75-
/// Used internally to represent raw HTML string content within the HTML hierarchy.
76-
public struct HTMLString: HTML {
75+
/// Used internally to represent raw markup string content within the markup hierarchy.
76+
public struct MarkupString: Markup {
7777
let content: String
7878

79-
public var body: HTMLString {
79+
public var body: MarkupString {
8080
self
8181
}
8282

@@ -89,27 +89,27 @@ public struct HTMLString: HTML {
8989
}
9090
}
9191

92-
// String extension that conforms to HTML is in Utilities/String.swift
92+
// String extension that conforms to Markup is in Utilities/String.swift
9393

9494
// MARK: - Default Implementations
9595

96-
extension HTML {
96+
extension Markup {
9797
/// Default render implementation that delegates to the body.
9898
public func render() -> String {
9999
body.render()
100100
}
101101

102-
/// Adds CSS classes to an HTML element
102+
/// Adds stylesheet classes to a markup element
103103
///
104-
/// - Parameter classes: The CSS classes to add
105-
/// - Returns: A container with the HTML content and additional classes
106-
public func addingClasses(_ classes: [String]) -> some HTML {
107-
HTMLClassContainer(content: self, classes: classes)
104+
/// - Parameter classes: The stylesheet classes to add
105+
/// - Returns: A container with the markup content and additional classes
106+
public func addingClasses(_ classes: [String]) -> some Markup {
107+
MarkupClassContainer(content: self, classes: classes)
108108
}
109109
}
110110

111-
/// A container that adds CSS classes to HTML content
112-
public struct HTMLClassContainer<Content: HTML>: HTML {
111+
/// A container that adds stylesheet classes to markup content
112+
public struct MarkupClassContainer<Content: Markup>: Markup {
113113
private let content: Content
114114
private let classes: [String]
115115

@@ -118,8 +118,8 @@ public struct HTMLClassContainer<Content: HTML>: HTML {
118118
self.classes = classes
119119
}
120120

121-
public var body: HTMLString {
122-
HTMLString(content: renderWithClasses())
121+
public var body: MarkupString {
122+
MarkupString(content: renderWithClasses())
123123
}
124124

125125
private func renderWithClasses() -> String {
@@ -131,7 +131,7 @@ public struct HTMLClassContainer<Content: HTML>: HTML {
131131
return renderedContent
132132
}
133133

134-
// Check if content starts with an HTML tag
134+
// Check if content starts with a markup tag
135135
guard
136136
let tagRange = renderedContent.range(
137137
of: "<[^>]+>", options: .regularExpression)

0 commit comments

Comments
 (0)