Skip to content

Commit

Permalink
refactor(review): rename wrapper to provider for tokens of spaces (#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 1ba6494 commit 2e6917e
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import OUDSTokensSemantic
// Create an issue for update https://github.com/Orange-OpenSource/ouds-ios/issues/new?template=token_update.yml

/// Defines wrapper objects for space semantic tokens (i.e. in the end `DimensionRawTokens`).
/// These values can be overriden inside ``OUDSSpaceSemanticTokensWrapper`` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
extension OUDSSpaceSemanticTokensWrapper: SpaceMultipleSemanticTokens {
/// These values can be overriden inside ``OUDSSpaceSemanticTokensProvider`` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
extension OUDSSpaceSemanticTokensProvider: SpaceMultipleSemanticTokens {

// MARK: Semantic token - Spacing - Layout fluid

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 OUDSSpaceSemanticTokensWrapper: SpaceSemanticTokens {
extension OUDSSpaceSemanticTokensProvider: SpaceSemanticTokens {
@objc open var spaceColumnGapMedium: SpaceSemanticToken { DimensionRawTokens.dimension150 }
@objc open var spaceColumnGapNone: SpaceSemanticToken { DimensionRawTokens.dimension0 }
@objc open var spaceColumnGapShort: SpaceSemanticToken { DimensionRawTokens.dimension100 }
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 @@ -70,15 +70,15 @@ open class OUDSTheme: @unchecked Sendable {
/// - grids: An object providing all the grid semantic tokens, by default `OUDSGridSemanticTokensProvider`
/// - opacities: An object providing all the opacity semantic tokens, by default `OUDSOpacitySemanticTokensProvider`
/// - sizes: An object providing all the size semantic tokens, by default `OUDSSizeSemanticTokensProvider`
/// - spaces: An object providing all the space semantic tokens, by default `OUDSSpaceSemanticTokensWrapper`
/// - spaces: An object providing all the space semantic tokens, by default `OUDSSpaceSemanticTokensProvider`
public init(colors: AllColorSemanticTokens = OUDSColorSemanticTokensProvider(),
borders: AllBorderSemanticTokens = OUDSBorderSemanticTokensProvider(),
elevations: AllElevationSemanticTokens = OUDSElevationSemanticTokensProvider(),
fonts: AllFontSemanticTokens = OUDSFontSemanticTokensProvider(),
grids: AllGridSemanticTokens = OUDSGridSemanticTokensProvider(),
opacities: AllOpacitySemanticTokens = OUDSOpacitySemanticTokensProvider(),
sizes: AllSizeSemanticTokens = OUDSSizeSemanticTokensProvider(),
spaces: AllSpaceSemanticTokens = OUDSSpaceSemanticTokensWrapper()) {
spaces: AllSpaceSemanticTokens = OUDSSpaceSemanticTokensProvider()) {
self.colors = colors
self.borders = borders
self.elevations = elevations
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 @@ -54,7 +54,7 @@ If your theme needs to define its own _raw tokens_, you can also define them usi
You may want to define your own theme, thus you can override the `OrangeTheme` with your own class or just override the wrappers.

You will have to override the tokens wrapper you need. To do that, make a subclass of the wrapper you target:
- spaces tokens are `OUDSSpaceSemanticTokensWrapper`
- spaces tokens are `OUDSSpaceSemanticTokensProvider`
- sizes tokens are in `OUDSSizeSemanticTokensProvider`
- colors tokens are all defined in `OrangeThemeColorSemanticTokensWrapper`
- borders tokens are in `OUDSBorderSemanticTokensProvider`
Expand All @@ -71,7 +71,7 @@ import OUDSTokensRaw // To use raw tokens if needed

// Token wrapper for spaces

class YourAppThemeSpaceTokensWrapper: OUDSSpaceSemanticTokensWrapper {
class YourAppThemeSpaceTokensWrapper: OUDSSpaceSemanticTokensProvider {
override var spaceFixedMedium: SpaceSemanticToken {
DimensionRawTokens.dimension400
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import OUDSTokensSemantic

// swiftlint:disable required_deinit

/// Overrides **all** the space semantic tokens (from its super class, i.e. `OUDSSpaceSemanticTokensWrapper` so as to test overriding of them (unit tests)
/// Overrides **all** the space semantic tokens (from its super class, i.e. `OUDSSpaceSemanticTokensProvider` so as to test overriding of them (unit tests)
/// and to act like smoke tests with crashing tests if some tokens disappeared.
final class MockThemeSpaceSemanticTokensWrapper: OUDSSpaceSemanticTokensWrapper {
final class MockThemeSpaceSemanticTokensWrapper: OUDSSpaceSemanticTokensProvider {

static let mockThemeSpaceRawToken: DimensionRawToken = 911
static let mockThemeSpaceSemanticToken = MultipleSpaceSemanticTokens(compact: 1, regular: 151)
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 @@ -72,15 +72,15 @@ open class OrangeTheme: OUDSTheme, @unchecked Sendable {
/// - grids: An object providing all the grid semantic tokens, by default `AllGridSemanticTokens`, default set to `OUDSGridSemanticTokensProvider`
/// - opacities: An object providing all the opacity semantic tokens, as `OpacitySemanticTokens` implementation, default set to `OUDSOpacitySemanticTokensProvider`
/// - sizes: An object providing all the size semantic tokens, as `AllSizeSemanticTokens` implementation, default set to `OUDSSizeSemanticTokensProvider`
/// - spaces: An object providing all the space semantic tokens, as `AllSpaceSemanticTokens` implementation, default set to `OUDSSpaceSemanticTokensWrapper`
/// - spaces: An object providing all the space semantic tokens, as `AllSpaceSemanticTokens` implementation, default set to `OUDSSpaceSemanticTokensProvider`
override public init(colors: AllColorSemanticTokens = OrangeThemeColorSemanticTokensWrapper(),
borders: AllBorderSemanticTokens = OUDSBorderSemanticTokensProvider(),
elevations: AllElevationSemanticTokens = OUDSElevationSemanticTokensProvider(),
fonts: AllFontSemanticTokens = OUDSFontSemanticTokensProvider(),
grids: AllGridSemanticTokens = OUDSGridSemanticTokensProvider(),
opacities: AllOpacitySemanticTokens = OUDSOpacitySemanticTokensProvider(),
sizes: AllSizeSemanticTokens = OUDSSizeSemanticTokensProvider(),
spaces: AllSpaceSemanticTokens = OUDSSpaceSemanticTokensWrapper()) {
spaces: AllSpaceSemanticTokens = OUDSSpaceSemanticTokensProvider()) {
OUDSLogger.debug("Init of OrangeTheme")
super.init(colors: colors,
borders: borders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ You can enrich the ``OrangeTheme`` by subclassing it or by overriding some token
You may want to define your own theme, thus you can override the ``OrangeTheme`` with your own class or just override the wrappers.

You will have to override the tokens wrapper you need. To do that, make a subclass of the wrapper you target:
- spaces tokens are `OUDSSpaceSemanticTokensWrapper`
- spaces tokens are `OUDSSpaceSemanticTokensProvider`
- sizes tokens are in `OUDSSizeSemanticTokensProvider`
- colors tokens are all defined in `OrangeThemeColorSemanticTokensWrapper`
- borders tokens are in `OUDSBorderSemanticTokensProvider`
Expand All @@ -80,7 +80,7 @@ import OUDSTokensRaw // To use raw tokens if needed

// Token wrapper for spaces

class YourAppThemeSpaceTokensWrapper: OUDSSpaceSemanticTokensWrapper {
class YourAppThemeSpaceTokensWrapper: OUDSSpaceSemanticTokensProvider {
override var spaceFixedMedium: SpaceSemanticToken {
DimensionRawTokens.dimension400
}
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 space semantic tokens
/// class CustomSpaceTokensWrapper: OUDSSpaceSemanticTokensWrapper {
/// class CustomSpaceTokensWrapper: OUDSSpaceSemanticTokensProvider {
///
/// // Then override the space semantic tokens you want, using the dimension raw tokens available
///
Expand Down Expand Up @@ -49,11 +49,11 @@ import OUDSFoundations
/// ```swift
/// OrangeTheme(spaces: CustomSpaceTokensWrapper())
/// ```
open class OUDSSpaceSemanticTokensWrapper {
open class OUDSSpaceSemanticTokensProvider {

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

deinit{ }
Expand All @@ -63,5 +63,5 @@ open class OUDSSpaceSemanticTokensWrapper {
// the implemention of SpaceSemanticTokens and SpaceMultipleSemanticTokens are not here
// but in OUDS/OUDSTheme/OUDSTheme+SemanticTokens/OUDSTheme+SpaceSemanticTokens.swift
// and in OUDS/OUDSTheme/OUDSTheme+SemanticTokens/OUDSTheme+SpaceMultipleSemanticTokens.swift.
// This declaration of OUDSSpaceSemanticTokensWrapper is here to allow to write documentation.
// This declaration of OUDSSpaceSemanticTokensProvider is here to allow to write documentation.
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ public typealias AllSizeSemanticTokens = SizeSemanticTokens & SizeMultipleSemant

/// A type alias which merges ``SpaceSemanticTokens`` and ``SpaceMultipleSemanticTokens``.
/// It helps in the end to define a wrapper for all the semantic tokens of space, multiple or not, generated or not.
/// For example ``OUDSSpaceSemanticTokensWrapper`` matches this type alias.
/// For example ``OUDSSpaceSemanticTokensProvider`` matches this type alias.
public typealias AllSpaceSemanticTokens = SpaceSemanticTokens & SpaceMultipleSemanticTokens

0 comments on commit 2e6917e

Please sign in to comment.