Skip to content

Commit

Permalink
refactor(review): rename wrapper to provider for tokens of fonts (#79)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
  • Loading branch information
pylapp committed Dec 17, 2024
1 parent 7798b5d commit 899ebf1
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import OUDSTokensSemantic
// swiftlint:disable line_length

/// Defines basic values common to all themes for `FontCompositeSemanticToken`.
/// These values can be overriden inside ``OUDSFontSemanticTokensWrapper`` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
/// These values can be overriden inside ``OUDSFontSemanticTokensProvider`` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
/// The aim of this extensions is to make relationships between all composite semantic tokens for typography / fonts and associated composite raw tokens.
/// The *tokenator* is not able to provide code for such "composite" objects because the *Figma* tool itself cannot manage that and does not output anything in its JSON to process.
extension OUDSFontSemanticTokensWrapper: FontCompositeSemanticTokens {
extension OUDSFontSemanticTokensProvider: FontCompositeSemanticTokens {

// MARK: - Semantic tokens - Typography - Composites - Display

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import OUDSTokensSemantic
// swiftlint:disable line_length

/// Defines wrapper objects for font semantic tokens but "multiple", i.e. tokens with values depending to size classes or color schemes.
/// These values can be overriden inside `OUDSFontSemanticTokensWrapper` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
extension OUDSFontSemanticTokensWrapper: FontMultipleSemanticTokens {
/// These values can be overriden inside `OUDSFontSemanticTokensProvider` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
extension OUDSFontSemanticTokensProvider: FontMultipleSemanticTokens {

// MARK: - Semantic token - Typography - Font - Size

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Foundation
import OUDSTokensRaw
import OUDSTokensSemantic

extension OUDSFontSemanticTokensWrapper: FontSemanticTokens {
extension OUDSFontSemanticTokensProvider: FontSemanticTokens {
@objc open var fontFamily: FontFamilySemanticToken { FontRawTokens.fontFamilySystemSfPro }
@objc open var fontLetterSpacingBodyLargeMobile: FontLetterSpacingSemanticToken { FontRawTokens.fontLetterSpacing250 }
@objc open var fontLetterSpacingBodyLargeTablet: FontLetterSpacingSemanticToken { FontRawTokens.fontLetterSpacing250 }
Expand Down
4 changes: 2 additions & 2 deletions OUDS/Core/OUDS/Sources/OUDSTheme/OUDSTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ open class OUDSTheme: @unchecked Sendable {
/// - colors: An object providing all the color semantic tokens, by default `OUDSColorSemanticTokensProvider`
/// - borders: An object providing all the border semantic tokens, by default `OUDSBorderSemanticTokensProvider`
/// - elevations: An object providing all the elevation semantic tokens, by default `OUDSElevationSemanticTokensProvider`
/// - fonts: An object providing all the font semantic tokens, by default `OUDSFontSemanticTokensWrapper`
/// - fonts: An object providing all the font semantic tokens, by default `OUDSFontSemanticTokensProvider`
/// - grids: An object providing all the grid semantic tokens, by default `OUDSGridSemanticTokensWrapper`
/// - opacities: An object providing all the opacity semantic tokens, by default `OUDSOpacitySemanticTokensWrapper`
/// - sizes: An object providing all the size semantic tokens, by default `OUDSSizeSemanticTokensWrapper`
/// - spaces: An object providing all the space semantic tokens, by default `OUDSSpaceSemanticTokensWrapper`
public init(colors: AllColorSemanticTokens = OUDSColorSemanticTokensProvider(),
borders: AllBorderSemanticTokens = OUDSBorderSemanticTokensProvider(),
elevations: AllElevationSemanticTokens = OUDSElevationSemanticTokensProvider(),
fonts: AllFontSemanticTokens = OUDSFontSemanticTokensWrapper(),
fonts: AllFontSemanticTokens = OUDSFontSemanticTokensProvider(),
grids: AllGridSemanticTokens = OUDSGridSemanticTokensWrapper(),
opacities: AllOpacitySemanticTokens = OUDSOpacitySemanticTokensWrapper(),
sizes: AllSizeSemanticTokens = OUDSSizeSemanticTokensWrapper(),
Expand Down
4 changes: 2 additions & 2 deletions OUDS/Core/OUDS/Sources/_OUDS.docc/Themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ You will have to override the tokens wrapper you need. To do that, make a subcla
- elevations tokens are in `OUDSElevationSemanticTokensProvider`
- opacity tokens are in `OUDSOpacitySemanticTokensWrapper`
- grid tokens are in `OUDSGridSemanticTokensWrapper`
- font tokens are in `OUDSFontSemanticTokensWrapper`
- font tokens are in `OUDSFontSemanticTokensProvider`

Find bellow some example

Expand Down Expand Up @@ -148,7 +148,7 @@ class YourAppThemeGridTokensWrapper: OUDSGridSemanticTokensWrapper {

// Token wrapper for font

class YourAppThemeFontTokensWrapper: OUDSFontSemanticTokensWrapper {
class YourAppThemeFontTokensWrapper: OUDSFontSemanticTokensProvider {
override var typeDisplayLarge: MultipleFontCompositeRawTokens {
MultipleFontCompositeRawTokens(compact: FontRawTokens.typeRegular150, regular: FontRawTokens.typeRegular150)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import OUDSTokensSemantic
// swiftlint:disable line_length
// swiftlint:disable required_deinit

/// Overrides **all** the font semantic tokens, both simple, multiple and composites (from its super class, i.e. `OUDSFontSemanticTokensWrapper` so as to test overriding of them (unit tests)
/// Overrides **all** the font semantic tokens, both simple, multiple and composites (from its super class, i.e. `OUDSFontSemanticTokensProvider` so as to test overriding of them (unit tests)
/// and to act like smoke tests with crashing tests if some tokens disappeared.
final class MockThemeFontSemanticTokensWrapper: OUDSFontSemanticTokensWrapper {
final class MockThemeFontSemanticTokensWrapper: OUDSFontSemanticTokensProvider {

// MARK: Semantic tokens - Not composites

Expand Down
4 changes: 2 additions & 2 deletions OUDS/Core/Themes/Orange/Sources/OrangeTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ open class OrangeTheme: OUDSTheme, @unchecked Sendable {
/// - colors: An object providing all the color semantic tokens, as `AllColorSemanticTokens` implementation, default set to `OrangeThemeColorSemanticTokensWrapper`
/// - borders: An object providing all the border semantic tokens, as `BorderSemanticTokens` implementation, default set to `OUDSBorderSemanticTokensProvider`
/// - elevations: An object providing all the elevation semantic tokens, by default `AllElevationSemanticTokens`, default set to `OUDSElevationSemanticTokensProvider`
/// - fonts: An object providing all the font semantic tokens, by default `AllFontemanticTokens`, default set to `OUDSFontSemanticTokensWrapper`
/// - fonts: An object providing all the font semantic tokens, by default `AllFontemanticTokens`, default set to `OUDSFontSemanticTokensProvider`
/// - grids: An object providing all the grid semantic tokens, by default `AllGridSemanticTokens`, default set to `OUDSGridSemanticTokensWrapper`
/// - opacities: An object providing all the opacity semantic tokens, as `OpacitySemanticTokens` implementation, default set to `OUDSOpacitySemanticTokensWrapper`
/// - sizes: An object providing all the size semantic tokens, as `AllSizeSemanticTokens` implementation, default set to `OUDSSizeSemanticTokensWrapper`
/// - spaces: An object providing all the space semantic tokens, as `AllSpaceSemanticTokens` implementation, default set to `OUDSSpaceSemanticTokensWrapper`
override public init(colors: AllColorSemanticTokens = OrangeThemeColorSemanticTokensWrapper(),
borders: AllBorderSemanticTokens = OUDSBorderSemanticTokensProvider(),
elevations: AllElevationSemanticTokens = OUDSElevationSemanticTokensProvider(),
fonts: AllFontSemanticTokens = OUDSFontSemanticTokensWrapper(),
fonts: AllFontSemanticTokens = OUDSFontSemanticTokensProvider(),
grids: AllGridSemanticTokens = OUDSGridSemanticTokensWrapper(),
opacities: AllOpacitySemanticTokens = OUDSOpacitySemanticTokensWrapper(),
sizes: AllSizeSemanticTokens = OUDSSizeSemanticTokensWrapper(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ You will have to override the tokens wrapper you need. To do that, make a subcla
- elevations tokens are in `OUDSElevationSemanticTokensProvider`
- opacity tokens are in `OUDSOpacitySemanticTokensWrapper`
- grid tokens are in `OUDSGridSemanticTokensWrapper`
- font tokens are in `OUDSFontSemanticTokensWrapper`
- font tokens are in `OUDSFontSemanticTokensProvider`

```swift
import OUDSTokensSemantic // To use semantic tokens if needed
Expand Down Expand Up @@ -157,7 +157,7 @@ class YourAppThemeGridTokensWrapper: OUDSGridSemanticTokensWrapper {

// Token wrapper for font

class YourAppThemeFontTokensWrapper: OUDSFontSemanticTokensWrapper {
class YourAppThemeFontTokensWrapper: OUDSFontSemanticTokensProvider {
override var typeDisplayLarge: MultipleFontCompositeRawTokens {
MultipleFontCompositeRawTokens(compact: FontRawTokens.typeRegular150, regular: FontRawTokens.typeRegular150)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import OUDSFoundations
///
/// ```swift
/// // Define your own wrapper for font semantic tokens
/// class CustomFontTokensWrapper: OUDSFontSemanticTokensWrapper {
/// class CustomFontTokensWrapper: OUDSFontSemanticTokensProvider {
///
/// // Then override the font semantic tokens you want, using the font raw tokens available
///
Expand Down Expand Up @@ -49,11 +49,11 @@ import OUDSFoundations
/// ```swift
/// OrangeTheme(fonts: CustomFontTokensWrapper())
/// ```
open class OUDSFontSemanticTokensWrapper {
open class OUDSFontSemanticTokensProvider {

/// Intializes the wrapper
public init() {
OUDSLogger.debug("Init of OUDSFontSemanticTokensWrapper")
OUDSLogger.debug("Init of OUDSFontSemanticTokensProvider")
}

deinit{ }
Expand All @@ -64,5 +64,5 @@ open class OUDSFontSemanticTokensWrapper {
// but in OUDS/OUDSTheme/OUDSTheme+SemanticTokens/OUDSTheme+FontSemanticTokens.swift,
// in OUDS/OUDSTheme/OUDSTheme+SemanticTokens/OUDSTheme+FontCompositeSemanticTokens.swift,
// and in OUDS/OUDSTheme/OUDSTheme+SemanticTokens/OUDSTheme+FontMultipleSemanticTokens.swift.
// This declaration of OUDSFontSemanticTokensWrapper is here to allow to write documentation.
// This declaration of OUDSFontSemanticTokensProvider is here to allow to write documentation.
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public typealias AllElevationSemanticTokens = ElevationSemanticTokens & Elevatio

/// A type alias which merges ``FontSemanticTokens``, ``FontCompositeSemanticTokens`` and ``FontMultipleSemanticTokens``.
/// It helps in the end to define a wrapper for all the semantic tokens of fonts, multiple, composite, or not, generated or not.
/// For example ``OUDSFontSemanticTokensWrapper`` matches this type alias.
/// For example ``OUDSFontSemanticTokensProvider`` matches this type alias.
public typealias AllFontSemanticTokens = FontSemanticTokens & FontCompositeSemanticTokens & FontMultipleSemanticTokens

/// A type alias which merges ``SizeSemanticTokens`` and ``SizeMultipleSemanticTokens``.
Expand Down

0 comments on commit 899ebf1

Please sign in to comment.