Skip to content

Commit

Permalink
Upgrade the package (#121)
Browse files Browse the repository at this point in the history
* Add the css for the textpad component

* Improve the text component

* Fix the form validation

* Change some of css

* Undo the package reference in the package manifest

* Add a test for string interpolation in a localized string

* Replace the lingo implementation

* Revise the new localization implementation

* Integrate the storage manager of the environment into the environment class

* Remove the localization configuration and replace it with the new localization class

* Improve the locale struct
  • Loading branch information
mattesmohr authored Mar 22, 2023
1 parent c811b23 commit b160413
Show file tree
Hide file tree
Showing 35 changed files with 933 additions and 296 deletions.
7 changes: 2 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/miroslavkovac/Lingo.git", from: "3.1.0"),
.package(url: "https://github.com/apple/swift-collections.git", from: "1.0.1"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.65.2")
Expand All @@ -31,7 +30,6 @@ let package = Package(
.target(
name: "HTMLKit",
dependencies: [
.product(name: "Lingo", package: "Lingo"),
.product(name: "Collections", package: "swift-collections")
],
exclude: ["Abstraction/README.md", "Framework/README.md"]
Expand All @@ -56,7 +54,6 @@ let package = Package(
dependencies: [
.target(name: "HTMLKit"),
.product(name: "Vapor", package: "vapor"),
.product(name: "Lingo", package: "lingo")
]
),
.testTarget(
Expand All @@ -65,7 +62,7 @@ let package = Package(
.target(name: "HTMLKit")
],
resources: [
.process("Localization")
.copy("Localization")
]
),
.testTarget(
Expand All @@ -92,7 +89,7 @@ let package = Package(
.product(name: "XCTVapor", package: "vapor")
],
resources: [
.process("Localization")
.copy("Localization")
]
),
.executableTarget(
Expand Down
112 changes: 28 additions & 84 deletions Sources/HTMLKit/Abstraction/Elements/BodyElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1563,12 +1563,8 @@ extension Heading1: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute

extension Heading1: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down Expand Up @@ -1818,12 +1814,8 @@ extension Heading2: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute

extension Heading2: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down Expand Up @@ -2073,12 +2065,8 @@ extension Heading3: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute

extension Heading3: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down Expand Up @@ -2328,12 +2316,8 @@ extension Heading4: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute

extension Heading4: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down Expand Up @@ -2583,12 +2567,8 @@ extension Heading5: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute

extension Heading5: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down Expand Up @@ -2838,12 +2818,8 @@ extension Heading6: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute

extension Heading6: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down Expand Up @@ -4069,12 +4045,8 @@ extension Paragraph: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut

extension Paragraph: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down Expand Up @@ -4811,12 +4783,8 @@ extension Blockquote: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu

extension Blockquote: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down Expand Up @@ -6090,12 +6058,8 @@ extension Anchor: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes,

extension Anchor: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down Expand Up @@ -6833,12 +6797,8 @@ extension Small: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes {

extension Small: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down Expand Up @@ -7012,12 +6972,8 @@ extension StrikeThrough: GlobalAttributes, GlobalEventAttributes {

extension StrikeThrough: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down Expand Up @@ -10938,12 +10894,8 @@ extension Italic: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes

extension Italic: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down Expand Up @@ -11193,12 +11145,8 @@ extension Bold: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes {

extension Bold: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down Expand Up @@ -11448,12 +11396,8 @@ extension Underline: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut

extension Underline: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down
16 changes: 4 additions & 12 deletions Sources/HTMLKit/Abstraction/Elements/FormElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,8 @@ extension Label: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes,

extension Label: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init<B>(_ localizedKey: String, with context: B) where B : Encodable {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down Expand Up @@ -1288,12 +1284,8 @@ extension Button: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes,

extension Button: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}

Expand Down
10 changes: 3 additions & 7 deletions Sources/HTMLKit/Abstraction/Elements/TableElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2184,13 +2184,9 @@ extension HeaderCell: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu
}
}

extension HeaderCell: Localizable {
extension HeaderCell: Localizable {

public init(_ localizedKey: String) {
self.content = [LocalizedStringKey(key: localizedKey)]
}

public init(_ localizedKey: String, with context: some Encodable) {
self.content = [LocalizedStringKey(key: localizedKey, context: context)]
public init(_ localizedKey: String, tableName: String? = nil, interpolation: Any...) {
self.content = [LocalizedStringKey(key: localizedKey, table: tableName, interpolation: interpolation)]
}
}
28 changes: 26 additions & 2 deletions Sources/HTMLKit/Framework/Environment/Environment.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import Foundation

/// A type that represents the environment
public struct Environment {
public class Environment {

/// The storage of the environment
private var storage: [AnyKeyPath: Any]

/// Initiates a manager
public init() {

self.storage = [:]
}

/// The current time zone of the environment
public var timeZone: TimeZone?
Expand All @@ -10,8 +19,23 @@ public struct Environment {
public var calendar: Calendar?

/// The current local of the environment
public var locale: String?
public var locale: Locale?

/// The current color scheme of the environment
public var colorScheme: String?

/// Retrieves an item from storage by its path
public func retrieve(for path: AnyKeyPath) -> Any? {

if let value = self.storage[path] {
return value
}

return nil
}

/// Adds und updates an item to the storage
public func upsert<T>(_ value: T, for path: AnyKeyPath) {
self.storage[path] = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public struct EnvironmentKeys: Hashable {

public var timeZone: TimeZone

public var locale: String
public var locale: Locale

public var colorScheme: String
}
29 changes: 0 additions & 29 deletions Sources/HTMLKit/Framework/Environment/Manager.swift

This file was deleted.

Loading

0 comments on commit b160413

Please sign in to comment.