1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
/*
This source file is part of the Swift.org open source project
Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
import Foundation
import Markdown
/// A semantic model for a view that arranges its children in a row.
public final class Stack: Semantic, AutomaticDirectiveConvertible {
public static let introducedVersion = "5.5"
public let originalMarkup: BlockDirective
/// The stack's children.
///
/// A list of media items with attached descriptions.
@ChildDirective(requirements: .oneOrMore)
public private(set) var contentAndMedia: [ContentAndMedia]
static var keyPaths: [String : AnyKeyPath] = [
"contentAndMedia" : \Stack._contentAndMedia,
]
override var children: [Semantic] {
return contentAndMedia
}
init(originalMarkup: BlockDirective, contentAndMedias: [ContentAndMedia]) {
self.originalMarkup = originalMarkup
super.init()
self.contentAndMedia = contentAndMedias
}
@available(*, deprecated, message: "Do not call directly. Required for 'AutomaticDirectiveConvertible'.")
init(originalMarkup: BlockDirective) {
self.originalMarkup = originalMarkup
}
static let childrenLimit = 3
func validate(source: URL?, for bundle: DocumentationBundle, in context: DocumentationContext, problems: inout [Problem]) -> Bool {
if contentAndMedia.count > Stack.childrenLimit {
let diagnostic = Diagnostic(source: source, severity: .warning, range: originalMarkup.range, identifier: "org.swift.docc.HasAtMost<\(Stack.self), \(ContentAndMedia.self)>(\(Stack.childrenLimit))", summary: "\(Stack.directiveName.singleQuoted) directive accepts at most \(Stack.childrenLimit) \(ContentAndMedia.directiveName.singleQuoted) child directives")
problems.append(Problem(diagnostic: diagnostic, possibleSolutions: []))
}
return true
}
public override func accept<V: SemanticVisitor>(_ visitor: inout V) -> V.Result {
return visitor.visitStack(self)
}
}
|