-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add authoring support for @TabNavigator directive #379
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
Sources/SwiftDocC/Semantics/Reference/TabNavigator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| This source file is part of the Swift.org open source project | ||
|
|
||
| Copyright (c) 2022 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 container directive that arranges content into a tab-based layout. | ||
| /// | ||
| /// Create a new tab navigator by writing a `@TabNavigator` directive that contains child | ||
| /// `@Tab` directives. | ||
| /// | ||
| /// ```md | ||
| /// @TabNavigator { | ||
| /// @Tab("Powers") { | ||
| ///  | ||
| /// } | ||
| /// | ||
| /// @Tab("Excerise routines") { | ||
| ///  | ||
| /// } | ||
| /// | ||
| /// @Tab("Hats") { | ||
| ///  | ||
| /// } | ||
| /// } | ||
| /// ``` | ||
| public final class TabNavigator: Semantic, AutomaticDirectiveConvertible, MarkupContaining { | ||
| public let originalMarkup: BlockDirective | ||
|
|
||
| /// The tabs that make up this tab navigator. | ||
| @ChildDirective(requirements: .oneOrMore) | ||
| public private(set) var tabs: [Tab] | ||
|
|
||
| static var keyPaths: [String : AnyKeyPath] = [ | ||
| "tabs" : \TabNavigator._tabs, | ||
| ] | ||
|
|
||
| var childMarkup: [Markup] { | ||
| return tabs.flatMap(\.childMarkup) | ||
| } | ||
|
|
||
| @available(*, deprecated, | ||
| message: "Do not call directly. Required for 'AutomaticDirectiveConvertible'." | ||
| ) | ||
| init(originalMarkup: BlockDirective) { | ||
| self.originalMarkup = originalMarkup | ||
| } | ||
| } | ||
|
|
||
| extension TabNavigator { | ||
| /// A container directive that holds general markup content describing an individual | ||
| /// tab within a tab-based layout. | ||
| public final class Tab: Semantic, AutomaticDirectiveConvertible, MarkupContaining { | ||
| public let originalMarkup: BlockDirective | ||
|
|
||
| /// The title that should identify the content in this tab when rendered. | ||
| @DirectiveArgumentWrapped(name: .unnamed) | ||
| public private(set) var title: String | ||
|
|
||
| /// The markup content in this tab. | ||
| @ChildMarkup(numberOfParagraphs: .oneOrMore, supportsStructure: true) | ||
| public private(set) var content: MarkupContainer | ||
|
|
||
| static var keyPaths: [String : AnyKeyPath] = [ | ||
| "title" : \Tab._title, | ||
| "content" : \Tab._content, | ||
| ] | ||
|
|
||
| var childMarkup: [Markup] { | ||
| return content.elements | ||
| } | ||
|
|
||
| @available(*, deprecated, | ||
| message: "Do not call directly. Required for 'AutomaticDirectiveConvertible'." | ||
| ) | ||
| init(originalMarkup: BlockDirective) { | ||
| self.originalMarkup = originalMarkup | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension TabNavigator: RenderableDirectiveConvertible { | ||
| func render(with contentCompiler: inout RenderContentCompiler) -> [RenderContent] { | ||
| let renderedTabs = tabs.map { tab in | ||
| return RenderBlockContent.TabNavigator.Tab( | ||
| title: tab.title, | ||
| content: tab.content.elements.flatMap { markupElement in | ||
| return contentCompiler.visit(markupElement) as! [RenderBlockContent] | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| let renderedNavigator = RenderBlockContent.TabNavigator(tabs: renderedTabs) | ||
| return [RenderBlockContent.tabNavigator(renderedNavigator)] | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the test is now poorly named, since it tests more than CustomIcons at this point. In my mind there are two alternatives. Either we break off the tests into individual tests and instead of
XCTAssertEqualon the full string, we assert on the presence of individual elements. alternatively we just rename this test totestRenderIndexGenerationWithBookLikeContentalthough I am not sure I like to refer to all of these as being book-like since I can see things like this new tab navigator being useful for large amounts of related screenshots in an article within conceptual documentation for an app or something.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I disagree. I think it's still only testing custom icons- if the navigator index doesn't include just regular article pages in it then something has gone really wrong.
I just had to update the test to reflect the content of the DocC catalog since I added an additional page for a different test in
RenderNodeTranslatorTestsbut the main thing this is testing for is still the special page that customizes an icon.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean, I think it's fine for this review then. FTR though I think that for someone new to the code base without the context of this PR, it is less clear what the test is checking for. We should come up with a better way of testing individual render index features without having to do this all the time.