Skip to content

Add support for @Small directive #380

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

Merged
merged 3 commits into from
Sep 16, 2022
Merged

Conversation

ethan-kusters
Copy link
Contributor

@ethan-kusters ethan-kusters commented Sep 13, 2022

Bug/issue #, if applicable: rdar://97744845

Summary

Adds support for the @Small directive as described here: https://forums.swift.org/t/supporting-more-dynamic-content-in-swift-docc-reference-documentation/59527#small-18

A new @Small directive based on HTML’s small tag. This directive can be used to specify small print like legal, license, or copyright text that should be rendered in a smaller font size.

@Small accepts no parameters and accepts arbitrary DocC markup body content.

Example:

You can create a sloth using the ``init(name:color:power:)``
initializer, or create randomly generated sloth using a
``SlothGenerator``:

   let slothGenerator = MySlothGenerator(seed: randomSeed())
   let habitat = Habitat(isHumid: false, isWarm: true)

   // ...

@Small {
    Licensed under Apache License v2.0 with Runtime Library Exception
}

Note
The implementation for @Small relies on some new infrastructure added in #378 to support directives that include directly renderable content.

Dependencies

Testing

Using the latest version of Swift-DocC-Render (support for @Small landed on the main branch recently), build documentation for a DocC catalog that includes the @Small directive. Confirm it renders as expected.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran the ./bin/test script and it succeeded
  • Updated documentation if necessary

@ethan-kusters ethan-kusters changed the base branch from row-and-column to main September 14, 2022 13:25
@ethan-kusters ethan-kusters force-pushed the small branch 3 times, most recently from cc6975e to 7c13a8e Compare September 15, 2022 11:25
@ethan-kusters ethan-kusters self-assigned this Sep 15, 2022
@ethan-kusters
Copy link
Contributor Author

@swift-ci please test

@ethan-kusters ethan-kusters marked this pull request as ready for review September 15, 2022 11:25
@@ -61,7 +61,11 @@ public enum RenderBlockContent: Equatable {
/// A table that contains a list of row data.
case table(Table)

/// A row in a grid-based layout system that describes a collection of columns.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mega nit, this probably belongs in another patch.

Copy link
Contributor Author

@ethan-kusters ethan-kusters Sep 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah agreed- I just missed it in #378 so I thought it was worth cleaning up here. I can split it into a separate commit though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be nice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split out here: e56bd43

"type": "object",
"required": [
"type",
"inlineContent",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit trailing comma

@@ -1057,5 +1057,15 @@ class RenderNodeTranslatorTests: XCTestCase {
XCTAssertEqual(row.columns.first?.content.count, 1)
XCTAssertEqual(row.columns.last?.size, 5)
XCTAssertEqual(row.columns.last?.content.count, 3)

guard case let .small(small) = discussion.content.last else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not have a separate test from row and column one for this? I find that having smaller test cases helps pin out failures faster.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch- I meant to create a new one here. Should be fixed now. Thanks!

Comment on lines +32 to +34
XCTAssertEqual(renderBlockContent.count, 1)
XCTAssertEqual(
renderBlockContent,
renderBlockContent.first,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not be in a separate patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split into a separate commit here: e4a6fc4.

}
}

func testMixesInlineAndBlockContent() throws {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight misnomer here, maybe something like testCanNotContainStructuredMarkup

@daniel-grumberg
Copy link
Contributor

Looks pretty good to me, small fixes and then LGTM

The current tests only look at the `first` RenderBlockContentelement.
This is a refactor to support testing `@Small` which
can return multiple RenderBlockContent items.
Adds support for the `@Small` directive as described here:
https://forums.swift.org/t/supporting-more-dynamic-content-in-swift-docc-reference-documentation/59527#small-18

A new `@Small` directive based on HTML’s small tag.
This directive can be used to specify small print like legal,
license, or copyright text that should be rendered in a smaller
font size.

`@Small` accepts no parameters and accepts inline DocC markup body
content.

Example:

    You can create a sloth using the ``init(name:color:power:)``
    initializer, or create randomly generated sloth using a
    ``SlothGenerator``:

       let slothGenerator = MySlothGenerator(seed: randomSeed())
       let habitat = Habitat(isHumid: false, isWarm: true)

       // ...

    @Small {
        Licensed under Apache License v2.0 with Runtime Library Exception
    }

Dependencies:

- swiftlang/swift-docc-render#405

Resolves rdar://97744845
@ethan-kusters
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@daniel-grumberg daniel-grumberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ethan-kusters ethan-kusters merged commit 5208c8d into swiftlang:main Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants