Skip to content

Commit f85fe77

Browse files
authored
Update option directive naming (#448)
* Rename enabled/disabled argument for option directives * Use property wrapper initializer for custom true/false spellings * Improve readability of comparison with nil coalesced value * Switch back to an Enabledness enum but keep the Bool computed property * Generate a new symbol graph file for directives
1 parent f724095 commit f85fe77

File tree

10 files changed

+2231
-2238
lines changed

10 files changed

+2231
-2238
lines changed

Sources/SwiftDocC/Infrastructure/Topic Graph/AutomaticCuration.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,9 @@ public struct AutomaticCuration {
123123
renderContext: RenderContext?,
124124
renderer: DocumentationContentRenderer
125125
) throws -> TaskGroup? {
126-
if let automaticSeeAlsoOption = node.options?.automaticSeeAlsoBehavior
127-
?? context.options?.automaticSeeAlsoBehavior
126+
if (node.options?.automaticSeeAlsoEnabled ?? context.options?.automaticSeeAlsoEnabled) == false
128127
{
129-
guard automaticSeeAlsoOption == .siblingPages else {
130-
return nil
131-
}
128+
return nil
132129
}
133130

134131
// First try getting the canonical path from a render context, default to the documentation context

Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,27 +1112,15 @@ public struct RenderNodeTranslator: SemanticVisitor {
11121112
}
11131113

11141114
private func shouldCreateAutomaticRoleHeading(for node: DocumentationNode) -> Bool {
1115-
var shouldCreateAutomaticRoleHeading = true
1116-
if let automaticTitleHeadingOption = node.options?.automaticTitleHeadingBehavior
1117-
?? context.options?.automaticTitleHeadingBehavior
1118-
{
1119-
shouldCreateAutomaticRoleHeading = automaticTitleHeadingOption == .pageKind
1120-
}
1121-
1122-
return shouldCreateAutomaticRoleHeading
1115+
return node.options?.automaticTitleHeadingEnabled
1116+
?? context.options?.automaticTitleHeadingEnabled
1117+
?? true
11231118
}
11241119

11251120
private func shouldCreateAutomaticArticleSubheading(for node: DocumentationNode) -> Bool {
1126-
let shouldCreateAutomaticArticleSubheading: Bool
1127-
if let automaticSubheadingOption = node.options?.automaticArticleSubheadingBehavior
1128-
?? context.options?.automaticArticleSubheadingBehavior
1129-
{
1130-
shouldCreateAutomaticArticleSubheading = !(automaticSubheadingOption == .disabled)
1131-
} else {
1132-
shouldCreateAutomaticArticleSubheading = true
1133-
}
1134-
1135-
return shouldCreateAutomaticArticleSubheading
1121+
return node.options?.automaticArticleSubheadingEnabled
1122+
?? context.options?.automaticArticleSubheadingEnabled
1123+
?? true
11361124
}
11371125

11381126
private func topicsSectionStyle(for node: DocumentationNode) -> RenderNode.TopicsSectionStyle {

Sources/SwiftDocC/Semantics/Options/AutomaticArticleSubheading.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2022 Apple Inc. and the Swift project authors
4+
Copyright (c) 2022-2023 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -19,22 +19,29 @@ import Markdown
1919
public class AutomaticArticleSubheading: Semantic, AutomaticDirectiveConvertible {
2020
public let originalMarkup: BlockDirective
2121

22-
/// The specified behavior for automatic subheading generation.
22+
// This property exist so that the generated directive documentation makes it
23+
// clear that "enabled" and "disabled" are then two possible values.
24+
25+
/// Whether or not DocC generates automatic second-level "Overview" subheadings.
2326
@DirectiveArgumentWrapped(name: .unnamed)
24-
public private(set) var behavior: Behavior
27+
public private(set) var enabledness: Enabledness
2528

26-
/// A behavior for automatic subheading generation.
27-
public enum Behavior: String, CaseIterable, DirectiveArgumentValueConvertible {
28-
/// No subheading should be created for the article.
29-
case disabled
30-
31-
/// An overview subheading should be created containing the article's
32-
/// first paragraph of content.
29+
/// A value that represent whether automatic subheading generation is enabled or disabled.
30+
public enum Enabledness: String, CaseIterable, DirectiveArgumentValueConvertible {
31+
/// An overview subheading should be automatically created for the article (the default).
3332
case enabled
33+
34+
/// No automatic overview subheading should be created for the article.
35+
case disabled
36+
}
37+
38+
/// Whether or not DocC generates automatic second-level "Overview" subheadings.
39+
public var enabled: Bool {
40+
return enabledness == .enabled
3441
}
3542

3643
static var keyPaths: [String : AnyKeyPath] = [
37-
"behavior" : \AutomaticArticleSubheading._behavior,
44+
"enabledness" : \AutomaticArticleSubheading._enabledness,
3845
]
3946

4047
@available(*, deprecated, message: "Do not call directly. Required for 'AutomaticDirectiveConvertible'.")

Sources/SwiftDocC/Semantics/Options/AutomaticSeeAlso.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,29 @@ import Markdown
1616
public class AutomaticSeeAlso: Semantic, AutomaticDirectiveConvertible {
1717
public let originalMarkup: BlockDirective
1818

19-
/// The specified behavior for automatic See Also section generation.
19+
// This property exist so that the generated directive documentation makes it
20+
// clear that "enabled" and "disabled" are then two possible values.
21+
22+
/// Whether or not DocC generates automatic See Also sections.
2023
@DirectiveArgumentWrapped(name: .unnamed)
21-
public private(set) var behavior: Behavior
24+
public private(set) var enabledness: Enabledness
2225

23-
/// A behavior for automatic See Also section generation.
24-
public enum Behavior: String, CaseIterable, DirectiveArgumentValueConvertible {
25-
/// A See Also section will not be automatically created.
26-
case disabled
26+
/// A value that represent whether automatic See Also section generation is enabled or disabled.
27+
public enum Enabledness: String, CaseIterable, DirectiveArgumentValueConvertible {
28+
/// A See Also section should be automatically created (the default).
29+
case enabled
2730

28-
/// A See Also section will be automatically created based on the page's siblings.
29-
case siblingPages
31+
/// No automatic See Also section should be created.
32+
case disabled
33+
}
34+
35+
/// Whether or not DocC generates automatic See Also sections.
36+
public var enabled: Bool {
37+
return enabledness == .enabled
3038
}
3139

3240
static var keyPaths: [String : AnyKeyPath] = [
33-
"behavior" : \AutomaticSeeAlso._behavior,
41+
"enabledness" : \AutomaticSeeAlso._enabledness,
3442
]
3543

3644
@available(*, deprecated, message: "Do not call directly. Required for 'AutomaticDirectiveConvertible'.")

Sources/SwiftDocC/Semantics/Options/AutomaticTitleHeading.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,29 @@ import Markdown
1818
public class AutomaticTitleHeading: Semantic, AutomaticDirectiveConvertible {
1919
public let originalMarkup: BlockDirective
2020

21-
/// The specified behavior for automatic title heading generation.
21+
// This property exist so that the generated directive documentation makes it
22+
// clear that "enabled" and "disabled" are then two possible values.
23+
24+
/// Whether or not DocC generates automatic title headings.
2225
@DirectiveArgumentWrapped(name: .unnamed)
23-
public private(set) var behavior: Behavior
26+
public private(set) var enabledness: Enabledness
2427

25-
/// A behavior for automatic title heading generation.
26-
public enum Behavior: String, CaseIterable, DirectiveArgumentValueConvertible {
27-
/// No title heading should be created for the page.
28-
case disabled
28+
/// A value that represent whether automatic title heading generation is enabled or disabled.
29+
public enum Enabledness: String, CaseIterable, DirectiveArgumentValueConvertible {
30+
/// A title heading should be automatically created for the page (the default).
31+
case enabled
2932

30-
/// A title heading based on the page's kind should be automatically created.
31-
case pageKind
33+
/// No automatic title heading should be created for the page.
34+
case disabled
35+
}
36+
37+
/// Whether or not DocC generates automatic title headings.
38+
public var enabled: Bool {
39+
return enabledness == .enabled
3240
}
3341

3442
static var keyPaths: [String : AnyKeyPath] = [
35-
"behavior" : \AutomaticTitleHeading._behavior,
43+
"enabledness" : \AutomaticTitleHeading._enabledness,
3644
]
3745

3846
@available(*, deprecated, message: "Do not call directly. Required for 'AutomaticDirectiveConvertible'.")

Sources/SwiftDocC/Semantics/Options/Options.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ public class Options: Semantic, AutomaticDirectiveConvertible {
4444
@ChildDirective
4545
public private(set) var _topicsVisualStyle: TopicsVisualStyle? = nil
4646

47-
/// If given, the authored behavior for automatic See Also section generation.
48-
public var automaticSeeAlsoBehavior: AutomaticSeeAlso.Behavior? {
49-
return _automaticSeeAlso?.behavior
47+
/// If given, whether or not automatic See Also section generation is enabled.
48+
public var automaticSeeAlsoEnabled: Bool? {
49+
return _automaticSeeAlso?.enabled
5050
}
5151

52-
/// If given, the authored behavior for automatic Title Heading generation.
53-
public var automaticTitleHeadingBehavior: AutomaticTitleHeading.Behavior? {
54-
return _automaticTitleHeading?.behavior
52+
/// If given, whether or not automatic Title Heading generation is enabled.
53+
public var automaticTitleHeadingEnabled: Bool? {
54+
return _automaticTitleHeading?.enabled
5555
}
5656

57-
/// If given, the authored behavior for automatic article subheading generation.
58-
public var automaticArticleSubheadingBehavior: AutomaticArticleSubheading.Behavior? {
59-
return _automaticArticleSubheading?.behavior
57+
/// If given, whether or not automatic article subheading generation is enabled.
58+
public var automaticArticleSubheadingEnabled: Bool? {
59+
return _automaticArticleSubheading?.enabled
6060
}
6161

6262
/// If given, the authored style for a page's Topics section.

0 commit comments

Comments
 (0)