You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for variant overrides in Render JSON (#11)
Adds infrastructure support for adding language-specific overrides in Render
JSON. Also, adds support specifying language variants for
`RenderMetadata.title` and `TopicRenderReference.title`.
rdar://82919099
/// The variant overrides accumulated as part of the encoding process.
31
+
varuserInfoVariantOverrides:VariantOverrides?{
32
+
userInfo[.variantOverrides]as?VariantOverrides
33
+
}
22
34
}
23
35
24
36
/// A namespace for encoders for render node JSON.
25
-
enumRenderJSONEncoder{
37
+
publicenumRenderJSONEncoder{
26
38
/// Creates a new JSON encoder for render node values.
27
39
///
28
-
/// - Parameter prettyPrint: If `true`, the encoder formats its output to make it easy to read; if `false`, the output is compact.
40
+
/// Returns an encoder that's configured to encode ``RenderNode`` values.
41
+
///
42
+
/// > Important: Don't reuse encoders returned by this function to encode multiple render nodes, as the encoder accumulates state during the encoding
43
+
/// process which should not be shared in other encoding units. Instead, call this API to create a new encoder for each render node you want to encode.
44
+
///
45
+
/// - Parameters:
46
+
/// - prettyPrint: If `true`, the encoder formats its output to make it easy to read; if `false`, the output is compact.
47
+
/// - emitVariantOverrides: Whether the encoder should emit the top-level ``RenderNode/variantOverrides`` property that holds language-
/// An error that describes failures that may occur while encoding or decoding a render node.
53
85
enumCodingError:DescribedError{
54
86
/// JSON data could not be decoded as a render node value.
@@ -79,7 +111,7 @@ public extension RenderNode {
79
111
/// - decoder: The object that decodes the JSON data.
80
112
/// - Throws: A ``CodingError`` in case the decoder is unable to find a key or value in the data, the type of a decoded value is wrong, or the data is corrupted.
81
113
/// - Returns: The decoded render node value.
82
-
staticfunc decode(fromJSON data:Data, with decoder:JSONDecoder=RenderNode.defaultJSONDecoder)throws->RenderNode{
114
+
staticfunc decode(fromJSON data:Data, with decoder:JSONDecoder=RenderJSONDecoder.makeDecoder())throws->RenderNode{
Copy file name to clipboardExpand all lines: Sources/SwiftDocC/Model/Rendering/RenderNode.swift
+21Lines changed: 21 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,18 @@ import Foundation
28
28
/// The render node schema constantly evolves to support new documentation features. To help clients maintain compatibility,
29
29
/// we associate each schema with a version. See ``schemaVersion`` for more details.
30
30
///
31
+
/// ### Variants
32
+
///
33
+
/// Different variants of a documentation page can be represented by a single render node using the ``variantOverrides`` property.
34
+
/// This property holds overrides that clients should apply to the render JSON when processing documentation for specific programming languages. The overrides
35
+
/// are organized by traits (e.g., language) and it's up to the client to determine which trait is most appropriate for them. For example, a client that wants to
36
+
/// process the Objective-C version of documentation should apply the overrides associated with the `interfaceLanguage: objc` trait.
37
+
///
38
+
/// Use the ``RenderJSONEncoder/makeEncoder(prettyPrint:emitVariantOverrides:)`` API to instantiate a JSON encoder that's configured
39
+
/// to accumulate variant overrides and emit them to the ``variantOverrides`` property.
40
+
///
41
+
/// The overrides are emitted in the [JSON Patch](https://datatracker.ietf.org/doc/html/rfc6902) format.
42
+
///
31
43
/// ## Topics
32
44
///
33
45
/// ### General
@@ -130,6 +142,15 @@ public struct RenderNode {
130
142
/// List of variants of the same documentation node for various languages, etc.
131
143
publicvarvariants:[RenderNode.Variant]?
132
144
145
+
/// Language-specific overrides for documentation.
146
+
///
147
+
/// This property holds overrides that clients should apply to the render JSON when processing documentation for specific languages. The overrides are
148
+
/// organized by traits (e.g., language) and it's up to the client to determine which trait is most appropriate for them. For example, a client that wants to
149
+
/// process the Objective-C version of documentation should apply the overrides associated with the `interfaceLanguage: objc` trait.
150
+
///
151
+
/// The overrides are emitted in the [JSON Patch](https://datatracker.ietf.org/doc/html/rfc6902) format.
152
+
publicvarvariantOverrides:VariantOverrides?
153
+
133
154
/// Information about what API diffs are available for this symbol.
0 commit comments