|
11 | 11 | import Foundation |
12 | 12 | import Markdown |
13 | 13 |
|
14 | | -/// A directive that sets the platform availability information for a documentation page. |
15 | | -/// |
16 | | -/// `@Available` is analagous to the `@available` attribute in Swift: It allows you to specify a |
17 | | -/// platform version that the page relates to. To specify a platform and version, list the platform |
18 | | -/// name and use the `introduced` argument: |
19 | | -/// |
20 | | -/// ```markdown |
21 | | -/// @Available(macOS, introduced: "12.0") |
22 | | -/// ``` |
23 | | -/// |
24 | | -/// The available platforms are `macOS`, `iOS`, `watchOS`, and `tvOS`. |
25 | | -/// |
26 | | -/// This directive is available on both articles and documentation extension files. In extension |
27 | | -/// files, the information overrides any information from the symbol itself. |
28 | | -/// |
29 | | -/// This directive is only valid within a ``Metadata`` directive: |
30 | | -/// |
31 | | -/// ```markdown |
32 | | -/// @Metadata { |
33 | | -/// @Available(macOS, introduced: "12.0") |
34 | | -/// @Available(iOS, introduced: "15.0") |
35 | | -/// } |
36 | | -/// ``` |
37 | | -public final class MetadataAvailability: Semantic, AutomaticDirectiveConvertible { |
38 | | - static public let directiveName: String = "Available" |
| 14 | +extension Metadata { |
| 15 | + /// A directive that sets the platform availability information for a documentation page. |
| 16 | + /// |
| 17 | + /// `@Available` is analagous to the `@available` attribute in Swift: It allows you to specify a |
| 18 | + /// platform version that the page relates to. To specify a platform and version, list the platform |
| 19 | + /// name and use the `introduced` argument: |
| 20 | + /// |
| 21 | + /// ```markdown |
| 22 | + /// @Available(macOS, introduced: "12.0") |
| 23 | + /// ``` |
| 24 | + /// |
| 25 | + /// The available platforms are `macOS`, `iOS`, `watchOS`, and `tvOS`. |
| 26 | + /// |
| 27 | + /// This directive is available on both articles and documentation extension files. In extension |
| 28 | + /// files, the information overrides any information from the symbol itself. |
| 29 | + /// |
| 30 | + /// This directive is only valid within a ``Metadata`` directive: |
| 31 | + /// |
| 32 | + /// ```markdown |
| 33 | + /// @Metadata { |
| 34 | + /// @Available(macOS, introduced: "12.0") |
| 35 | + /// @Available(iOS, introduced: "15.0") |
| 36 | + /// } |
| 37 | + /// ``` |
| 38 | + public final class Availability: Semantic, AutomaticDirectiveConvertible { |
| 39 | + static public let directiveName: String = "Available" |
39 | 40 |
|
40 | | - public enum Platform: String, RawRepresentable, CaseIterable, DirectiveArgumentValueConvertible { |
41 | | - // FIXME: re-add `case any = "*"` when `isBeta` and `isDeprecated` are implemented |
42 | | - // cf. https://github.com/apple/swift-docc/issues/441 |
43 | | - case macOS, iOS, watchOS, tvOS |
| 41 | + public enum Platform: String, RawRepresentable, CaseIterable, DirectiveArgumentValueConvertible { |
| 42 | + // FIXME: re-add `case any = "*"` when `isBeta` and `isDeprecated` are implemented |
| 43 | + // cf. https://github.com/apple/swift-docc/issues/441 |
| 44 | + case macOS, iOS, watchOS, tvOS |
44 | 45 |
|
45 | | - public init?(rawValue: String) { |
46 | | - for platform in Self.allCases { |
47 | | - if platform.rawValue.lowercased() == rawValue.lowercased() { |
48 | | - self = platform |
49 | | - return |
| 46 | + public init?(rawValue: String) { |
| 47 | + for platform in Self.allCases { |
| 48 | + if platform.rawValue.lowercased() == rawValue.lowercased() { |
| 49 | + self = platform |
| 50 | + return |
| 51 | + } |
50 | 52 | } |
| 53 | + return nil |
51 | 54 | } |
52 | | - return nil |
53 | 55 | } |
54 | | - } |
55 | 56 |
|
56 | | - /// The platform that this argument's information applies to. |
57 | | - @DirectiveArgumentWrapped(name: .unnamed) |
58 | | - public var platform: Platform |
| 57 | + /// The platform that this argument's information applies to. |
| 58 | + @DirectiveArgumentWrapped(name: .unnamed) |
| 59 | + public var platform: Platform |
59 | 60 |
|
60 | | - /// The platform version that this page applies to. |
61 | | - @DirectiveArgumentWrapped |
62 | | - public var introduced: String |
| 61 | + /// The platform version that this page applies to. |
| 62 | + @DirectiveArgumentWrapped |
| 63 | + public var introduced: String |
63 | 64 |
|
64 | | - // FIXME: `isBeta` and `isDeprecated` properties/arguments |
65 | | - // cf. https://github.com/apple/swift-docc/issues/441 |
| 65 | + // FIXME: `isBeta` and `isDeprecated` properties/arguments |
| 66 | + // cf. https://github.com/apple/swift-docc/issues/441 |
66 | 67 |
|
67 | | - static var keyPaths: [String : AnyKeyPath] = [ |
68 | | - "platform" : \MetadataAvailability._platform, |
69 | | - "introduced" : \MetadataAvailability._introduced, |
70 | | - ] |
| 68 | + static var keyPaths: [String : AnyKeyPath] = [ |
| 69 | + "platform" : \Availability._platform, |
| 70 | + "introduced" : \Availability._introduced, |
| 71 | + ] |
71 | 72 |
|
72 | | - public let originalMarkup: Markdown.BlockDirective |
| 73 | + public let originalMarkup: Markdown.BlockDirective |
73 | 74 |
|
74 | | - @available(*, deprecated, message: "Do not call directly. Required for 'AutomaticDirectiveConvertible'.") |
75 | | - init(originalMarkup: Markdown.BlockDirective) { |
76 | | - self.originalMarkup = originalMarkup |
| 75 | + @available(*, deprecated, message: "Do not call directly. Required for 'AutomaticDirectiveConvertible'.") |
| 76 | + init(originalMarkup: Markdown.BlockDirective) { |
| 77 | + self.originalMarkup = originalMarkup |
| 78 | + } |
77 | 79 | } |
78 | 80 | } |
0 commit comments