From 50df5f1e9bfee9687ed8165ed51963309fc25694 Mon Sep 17 00:00:00 2001 From: Mattes Mohr Date: Sun, 9 Jan 2022 19:12:55 +0100 Subject: [PATCH] Minor fix (#60) * Add CustomProperty as a default case to the converter if the attribute isn't implemented yet. * Add charset and http-equiv as attribute case to the converter * Undo the RawRepresentable on enum types since the converter cannot parse it * Make the stringValue lowercased, since the rawValue init of a type seems to be case-sensitive * Add parent differentiation since different parents uses different types * Rename types for code consistency * Add a new role type * Mark the function handler with string value of the RoleAttribute as deprecated * Update the instructions * Update the instructions and the readme * Resolve issues --- Instructions/Features/Conversion.md | 8 +- Instructions/Features/Localization.md | 52 ++- Instructions/Installation.md | 25 +- Instructions/Overview.md | 50 ++- README.md | 22 +- .../External/Attributes/BasicAttributes.swift | 2 +- Sources/HTMLKit/External/Components.swift | 10 +- .../External/Elements/BasicElements.swift | 7 +- .../External/Elements/BodyElements.swift | 389 +++++++++++++++++- .../Elements/DefinitionElements.swift | 12 +- .../External/Elements/FigureElements.swift | 5 + .../External/Elements/FormElements.swift | 30 ++ .../External/Elements/HeadElements.swift | 33 +- .../External/Elements/HtmlElements.swift | 10 + .../External/Elements/InputElements.swift | 20 + .../External/Elements/ListElements.swift | 5 + .../External/Elements/MapElements.swift | 5 + .../External/Elements/MediaElements.swift | 12 +- .../External/Elements/ObjectElements.swift | 5 + .../External/Elements/RubyElements.swift | 10 + .../External/Elements/TableElements.swift | 45 ++ Sources/HTMLKit/External/Types.swift | 168 +++++--- .../Features/Conversion/Converter.swift | 44 +- .../Features/Conversion/Stencils.swift | 37 +- Tests/HTMLKitTests/Conversion/index.html | 1 + Tests/HTMLKitTests/PerformanceTests.swift | 6 +- Tests/HTMLKitTests/RenderingTests.swift | 12 +- 27 files changed, 898 insertions(+), 127 deletions(-) diff --git a/Instructions/Features/Conversion.md b/Instructions/Features/Conversion.md index de3707ac..7825c82c 100644 --- a/Instructions/Features/Conversion.md +++ b/Instructions/Features/Conversion.md @@ -1,11 +1,13 @@ # Conversion -The converter translates HTML into HTMLKit. +With HTMLKit you can convert your existing HTML code into Swift. It makes the change easier, faster and it can give you an idea how the library works. ## Essential ### Call +Call the converter and use the convert function. Pass the directory, where your html files are located and choose the output. We recommend to use the print option first, to get a quick preview on the output. The print shows up in the debug window of your IDE. If you choose the file option, the converter creates the swift files at the same directory you have given to the converter. + ```swift /// [configure.swift] ... @@ -45,3 +47,7 @@ struct IndexPage: Page { } } ``` + +## Note + +Keep in mind, that maybe the converter has not covered every case. If you miss something, file an [issue](https://github.com/vapor-community/HTMLKit/issues) and let us know to make the converter better. diff --git a/Instructions/Features/Localization.md b/Instructions/Features/Localization.md index a51f0b64..1dbf20ea 100644 --- a/Instructions/Features/Localization.md +++ b/Instructions/Features/Localization.md @@ -1,19 +1,67 @@ # Localization -The localization is +HTMLKit can render your content in different languages by using Localization. ## Essential ### Registration +The localization is optional, so if you want to use it, you need to register it first. Pass the directory path and the local identifier to the renderer. Keep in mind, that the directory path is the root directory where your localization files are located. + ```swift /// [configure.swift] + ... -try Renderer().registerLocalization(atPath: path, defaultLocale: "en") +try app.htmlkit.renderer.registerLocalization(atPath: path, defaultLocale: "en") ... ``` ### Definition +Define your localizations in a .json file. If you want to get to know more about definitions, take a a look at the [Lingo library](https://github.com/miroslavkovac/Lingo#usage). + +```swift +/// [en.json] + +{ + "Hallo.Welt": "Hello World" +} +``` + +### Implementation + +You can retrieve the definition by calling the localized initialiser of a localizable element. Most of the phrasing elements in HTMLKit should be localizable and provide you with the specific initialiser. Please [open an issue](https://github.com/vapor-community/HTMLKit/issues), if you find an element without it. + ```swift +/// [IndexView.swift] + +struct IndexView: View { + + var body: AnyContent { + Article { + Heading1("Hallo.Welt") + } + } +} +``` + +Also the locale for the environment can be changed for example by user input. Use the environment modifier on the element and pass the specific local identifier for it. + +```swift +/// [IndexView.swift] + +struct IndexView: View { + + struct Context { + let date: Date + let locale: String + } + + var body: AnyContent { + Article { + ... + } + .environment(locale: context.locale) + } +} ``` diff --git a/Instructions/Installation.md b/Instructions/Installation.md index 942af3d1..3c628eb0 100644 --- a/Instructions/Installation.md +++ b/Instructions/Installation.md @@ -1,10 +1,14 @@ # Installation -## Essential +## Requirements + +The requirements are + +## Configuration ### Packages -Add the packages as dependecies to your package. +To use HTMLKit in your project, you have to add the packages as dependecies first. Be sure to add it to your desired targets as well. ```swift /// [Package.swift] @@ -27,6 +31,21 @@ targets: [ ... ``` -## Vapor 3 +From time to time you want to update the packages. You can do it, by changing the version tags manually and saving it. You find the current version tag in the [release history](https://github.com/vapor-community/HTMLKit/releases). We recommand to read the release description first, to understand the possible changes. + +### Import + +Use the import keyword to load the module in your project files. + +```swift +/// [SimpleTemplate.swift] + +import HTMLKit +... +``` + +## Compatibiltiy + +### Vapor 3 Check the [provider](https://github.com/vapor-community/htmlkit-vapor-provider) to learn more about supporting Vapor 3. diff --git a/Instructions/Overview.md b/Instructions/Overview.md index a8a5fac1..7d5c77c7 100644 --- a/Instructions/Overview.md +++ b/Instructions/Overview.md @@ -1,22 +1,50 @@ # Overview -Render dynamic HTML templates in a *typesafe* and **performant** way! -By using Swift's powerful language features and a pre-rendering algorithm, HTMLKit will render insanely fast templates but also catch bugs that otherwise might occur with other templating options. +The instructions will provide you with information how to integrate HTMLKit in your project and how you can use it to write HTML by using Swift. Keep in mind, that the instructions are mainly based on a use in a vapor project. + +If still things are unclear, dont hesitate to [open an issue](https://github.com/vapor-community/HTMLKit/issues) or [join the discussions](https://github.com/vapor-community/HTMLKit/discussions). Also you find us on the vapor discord server. ## Index -1. Installation + +1. [Installation](Instructions/Installation.md) + + This section explains how to integrate the library in your project. 2. Essential -2.1 Elements -2.2 Layouts -2.3 Context -2.4 Statements + + 2.1 [Elements](Essential/Elements.md) + + This section gives an insight about the elements and how you can use it to write html. + + 2.2 [Layouts](Essential/Layouts.md) + + This section gives an insight about the layouts and how you can use it to build a template system. + + 2.3 [Context](Essential/Context.md) + + This section teaches you... + + 2.4 [Statements](Essential/Statements.md) + + This section teaches you, how you can use statements for control flow. 3. Features -3.1 Localization -3.2 Conversion -3.3 Templating + + 3.1 [Localization](Features/Localization.md) + + 3.2 [Conversion](Features/Conversion.md) + + 3.3 [Templating](Features/Templating.md) + 4. Example -## References + 4.1 [Code](https://github.com/vapor-community/HTMLKit/tree/main/Instructions/Example/Page) + + Shows a code example. + + 4.2 [Wiki](https://github.com/vapor-community/HTMLKit/wiki) + + Informations about the public api. + +## License diff --git a/README.md b/README.md index 7b82da62..010428e4 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,12 @@ # HTMLKit -Render dynamic HTML templates in a *typesafe* and **performant** way! -By using Swift's powerful language features and a pre-rendering algorithm, HTMLKit will render insanely fast templates but also catch bugs that otherwise might occur with other templating options. +Render dynamic HTML templates in a typesafe and performant way! By using Swift's powerful language features and a pre-rendering algorithm, HTMLKit will render insanely fast templates but also catch bugs that otherwise might occur with other templating options. ## Getting Started ### Installation -Add the packages as dependecies to your package. +Add the packages as dependecies and targets to your package file. ```swift /// [Package.swift] @@ -32,9 +31,11 @@ targets: [ ... ``` +Read the [installation instructions](https://github.com/vapor-community/HTMLKit/blob/main/Instructions/Installation.md) for more information. + ### Definition -Create a new file. Add the import and declare a new structure with the Protocol `Page`. Add some content to the `body` property. If you want to learn more about the definitions, take a look here. +Create a new file in your project. Add the import at the top of your file and declare a new structure. Extend your structure by adding a [layout definition](https://github.com/vapor-community/HTMLKit/blob/main/Instructions/Essential/Layouts.md) to adopt the required properties and methods. Add your content to the `body` property. ```swift /// [SimplePage.swift] @@ -66,19 +67,16 @@ struct SimplePage: Page { ### Implementation -Add the import to your controller and call the structure in your handler. Use the `render(for:)` method to render the structure for the request. +Call the structure you have created in your controller handler and use the render method to render the view for the request. ```swift /// [SimpleController.swift] ... -/// 1. Add the import -import HTMLKit - final class SimpleController { ... func getPage(req: Request) throws -> EventLoopFuture { - /// 2. Call the structure + /// 1. Call the structure return SimplePage().render(for: req) } ... @@ -91,4 +89,10 @@ final class SimpleController { ### Conversion +### Validation + ## Resources + +### Instructions + +See the [instructions](https://github.com/vapor-community/HTMLKit/blob/main/Instructions/Overview.md) to learn more about the library and the features. diff --git a/Sources/HTMLKit/External/Attributes/BasicAttributes.swift b/Sources/HTMLKit/External/Attributes/BasicAttributes.swift index 1e8946c3..f679b579 100644 --- a/Sources/HTMLKit/External/Attributes/BasicAttributes.swift +++ b/Sources/HTMLKit/External/Attributes/BasicAttributes.swift @@ -3411,7 +3411,7 @@ public protocol RoleAttribute: AnyAttribute { /// The func adds /// /// - func role(_ value: String) -> Self + func role(_ value: Roles) -> Self } extension RoleAttribute { diff --git a/Sources/HTMLKit/External/Components.swift b/Sources/HTMLKit/External/Components.swift index f68ce2c6..14580bb2 100644 --- a/Sources/HTMLKit/External/Components.swift +++ b/Sources/HTMLKit/External/Components.swift @@ -38,7 +38,7 @@ public struct MetaTitle: Component { } IF(useTwitter) { Meta() - .name(.init(rawValue: "twitter:title")!) + .custom(key: "name", value: "twitter:title") .content(self.title.rawValue) } } @@ -68,7 +68,7 @@ public struct MetaDescription: Component { } IF(useTwitter) { Meta() - .name(.init(rawValue: "twitter:description")!) + .custom(key: "name", value: "twitter:description") .content(self.description.rawValue) } } @@ -151,7 +151,7 @@ public struct Viewport: Component { public var body: AnyContent { Meta() .name(.viewport) - .content("width=\(mode.width), initial-scale=\(internalScale)") + .content("width=\(self.mode.width), initial-scale=\(self.internalScale)") } } @@ -170,9 +170,9 @@ public struct Author: Component { Meta() .name(.author) .content(self.author) - Unwrap(handle) { handle in + Unwrap(self.handle) { handle in Meta() - .name(.init(rawValue: "twitter:creator")!) + .custom(key: "name", value: "twitter:creator") .content(handle) } } diff --git a/Sources/HTMLKit/External/Elements/BasicElements.swift b/Sources/HTMLKit/External/Elements/BasicElements.swift index e7d7a9c2..aaf30d10 100644 --- a/Sources/HTMLKit/External/Elements/BasicElements.swift +++ b/Sources/HTMLKit/External/Elements/BasicElements.swift @@ -46,7 +46,7 @@ public struct Document: DocumentNode, BasicElement { public var content: String - public init(type: DocumentType) { + public init(type: Doctypes) { self.content = type.rawValue } } @@ -168,9 +168,14 @@ extension Html: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Html { return mutate(role: value) } + + public func role(_ value: Roles) -> Html { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Html { return mutate(spellcheck: condition) diff --git a/Sources/HTMLKit/External/Elements/BodyElements.swift b/Sources/HTMLKit/External/Elements/BodyElements.swift index 53c90ed5..2045af93 100644 --- a/Sources/HTMLKit/External/Elements/BodyElements.swift +++ b/Sources/HTMLKit/External/Elements/BodyElements.swift @@ -297,9 +297,14 @@ extension Article: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Article { return mutate(role: value) } + + public func role(_ value: Roles) -> Article { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Article { return mutate(spellcheck: condition) @@ -479,9 +484,14 @@ extension Section: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Section { return mutate(role: value) } + + public func role(_ value: Roles) -> Section { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Section { return mutate(spellcheck: condition) @@ -661,9 +671,14 @@ extension Navigation: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Navigation { return mutate(role: value) } + + public func role(_ value: Roles) -> Navigation { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Navigation { return mutate(spellcheck: condition) @@ -843,9 +858,14 @@ extension Aside: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Aside { return mutate(role: value) } + + public func role(_ value: Roles) -> Aside { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Aside { return mutate(spellcheck: condition) @@ -1025,9 +1045,14 @@ extension Heading1: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Heading1 { return mutate(role: value) } + + public func role(_ value: Roles) -> Heading1 { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Heading1 { return mutate(spellcheck: condition) @@ -1217,10 +1242,15 @@ extension Heading2: GlobalAttributes { public func nonce(_ value: String) -> Heading2 { return mutate(nonce: value) } - + + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Heading2 { return mutate(role: value) } + + public func role(_ value: Roles) -> Heading2 { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Heading2 { return mutate(spellcheck: condition) @@ -1411,9 +1441,14 @@ extension Heading3: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Heading3 { return mutate(role: value) } + + public func role(_ value: Roles) -> Heading3 { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Heading3 { return mutate(spellcheck: condition) @@ -1604,9 +1639,14 @@ extension Heading4: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Heading4 { return mutate(role: value) } + + public func role(_ value: Roles) -> Heading4 { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Heading4 { return mutate(spellcheck: condition) @@ -1797,9 +1837,14 @@ extension Heading5: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Heading5 { return mutate(role: value) } + + public func role(_ value: Roles) -> Heading5 { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Heading5 { return mutate(spellcheck: condition) @@ -1990,9 +2035,14 @@ extension Heading6: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Heading6 { return mutate(role: value) } + + public func role(_ value: Roles) -> Heading6 { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Heading6 { return mutate(spellcheck: condition) @@ -2183,10 +2233,15 @@ extension HeadingGroup: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> HeadingGroup { return mutate(role: value) } + public func role(_ value: Roles) -> HeadingGroup { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> HeadingGroup { return mutate(spellcheck: condition) } @@ -2365,9 +2420,14 @@ extension Header: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Header { return mutate(role: value) } + + public func role(_ value: Roles) -> Header { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Header { return mutate(spellcheck: condition) @@ -2547,9 +2607,14 @@ extension Footer: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Footer { return mutate(role: value) } + + public func role(_ value: Roles) -> Footer { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Footer { return mutate(spellcheck: condition) @@ -2729,9 +2794,14 @@ extension Address: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Address { return mutate(role: value) } + + public func role(_ value: Roles) -> Address { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Address { return mutate(spellcheck: condition) @@ -2911,9 +2981,14 @@ extension Paragraph: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Paragraph { return mutate(role: value) } + + public func role(_ value: Roles) -> Paragraph { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Paragraph { return mutate(spellcheck: condition) @@ -3099,9 +3174,14 @@ extension HorizontalRule: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> HorizontalRule { return mutate(role: value) } + + public func role(_ value: Roles) -> HorizontalRule { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> HorizontalRule { return mutate(spellcheck: condition) @@ -3281,9 +3361,14 @@ extension PreformattedText: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> PreformattedText { return mutate(role: value) } + + public func role(_ value: Roles) -> PreformattedText { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> PreformattedText { return mutate(spellcheck: condition) @@ -3463,9 +3548,14 @@ extension Blockquote: GlobalAttributes, CiteAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Blockquote { return mutate(role: value) } + + public func role(_ value: Roles) -> Blockquote { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Blockquote { return mutate(spellcheck: condition) @@ -3660,9 +3750,14 @@ extension OrderedList: GlobalAttributes, ReversedAttribute, StartAttribute, Type return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> OrderedList { return mutate(role: value) } + + public func role(_ value: Roles) -> OrderedList { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> OrderedList { return mutate(spellcheck: condition) @@ -3853,10 +3948,15 @@ extension UnorderedList: GlobalAttributes { public func nonce(_ value: String) -> UnorderedList { return mutate(nonce: value) } - + + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> UnorderedList { return mutate(role: value) } + + public func role(_ value: Roles) -> UnorderedList { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> UnorderedList { return mutate(spellcheck: condition) @@ -4035,10 +4135,15 @@ extension DescriptionList: GlobalAttributes { public func nonce(_ value: String) -> DescriptionList { return mutate(nonce: value) } - + + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> DescriptionList { return mutate(role: value) } + + public func role(_ value: Roles) -> DescriptionList { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> DescriptionList { return mutate(spellcheck: condition) @@ -4217,10 +4322,15 @@ extension Figure: GlobalAttributes { public func nonce(_ value: String) -> Figure { return mutate(nonce: value) } - + + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Figure { return mutate(role: value) } + + public func role(_ value: Roles) -> Figure { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Figure { return mutate(spellcheck: condition) @@ -4400,9 +4510,14 @@ extension Anchor: GlobalAttributes, DownloadAttribute, ReferenceAttribute, Refer return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Anchor { return mutate(role: value) } + + public func role(_ value: Roles) -> Anchor { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Anchor { return mutate(spellcheck: condition) @@ -4633,9 +4748,14 @@ extension Emphasize: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Emphasize { return mutate(role: value) } + + public func role(_ value: Roles) -> Emphasize { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Emphasize { return mutate(spellcheck: condition) @@ -4815,9 +4935,14 @@ extension Strong: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Strong { return mutate(role: value) } + + public func role(_ value: Roles) -> Strong { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Strong { return mutate(spellcheck: condition) @@ -4997,9 +5122,14 @@ extension Small: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Small { return mutate(role: value) } + + public func role(_ value: Roles) -> Small { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Small { return mutate(spellcheck: condition) @@ -5190,9 +5320,14 @@ extension StrikeThrough: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> StrikeThrough { return mutate(role: value) } + + public func role(_ value: Roles) -> StrikeThrough { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> StrikeThrough { return mutate(spellcheck: condition) @@ -5383,9 +5518,14 @@ extension Main: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Main { return mutate(role: value) } + + public func role(_ value: Roles) -> Main { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Main { return mutate(spellcheck: condition) @@ -5565,9 +5705,14 @@ extension Division: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Division { return mutate(role: value) } + + public func role(_ value: Roles) -> Division { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Division { return mutate(spellcheck: condition) @@ -5747,9 +5892,14 @@ extension Definition: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Definition { return mutate(role: value) } + + public func role(_ value: Roles) -> Definition { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Definition { return mutate(spellcheck: condition) @@ -5929,10 +6079,15 @@ extension Cite: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Cite { return mutate(role: value) } + public func role(_ value: Roles) -> Cite { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> Cite { return mutate(spellcheck: condition) } @@ -6111,9 +6266,14 @@ extension ShortQuote: GlobalAttributes, CiteAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> ShortQuote { return mutate(role: value) } + + public func role(_ value: Roles) -> ShortQuote { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> ShortQuote { return mutate(spellcheck: condition) @@ -6297,10 +6457,15 @@ extension Abbreviation: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Abbreviation { return mutate(role: value) } + public func role(_ value: Roles) -> Abbreviation { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> Abbreviation { return mutate(spellcheck: condition) } @@ -6479,9 +6644,14 @@ extension Ruby: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Ruby { return mutate(role: value) } + + public func role(_ value: Roles) -> Ruby { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Ruby { return mutate(spellcheck: condition) @@ -6660,10 +6830,15 @@ extension Data: GlobalAttributes, ValueAttribute { public func nonce(_ value: String) -> Data { return mutate(nonce: value) } - + + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Data { return mutate(role: value) } + + public func role(_ value: Roles) -> Data { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Data { return mutate(spellcheck: condition) @@ -6851,9 +7026,14 @@ extension Time: GlobalAttributes, DateTimeAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Time { return mutate(role: value) } + + public func role(_ value: Roles) -> Time { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Time { return mutate(spellcheck: condition) @@ -7037,9 +7217,14 @@ extension Code: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Code { return mutate(role: value) } + + public func role(_ value: Roles) -> Code { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Code { return mutate(spellcheck: condition) @@ -7219,9 +7404,14 @@ extension Variable: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Variable { return mutate(role: value) } + + public func role(_ value: Roles) -> Variable { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Variable { return mutate(spellcheck: condition) @@ -7400,10 +7590,15 @@ extension SampleOutput: GlobalAttributes { public func nonce(_ value: String) -> SampleOutput { return mutate(nonce: value) } - + + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> SampleOutput { return mutate(role: value) } + + public func role(_ value: Roles) -> SampleOutput { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> SampleOutput { return mutate(spellcheck: condition) @@ -7583,9 +7778,14 @@ extension KeyboardInput: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> KeyboardInput { return mutate(role: value) } + + public func role(_ value: Roles) -> KeyboardInput { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> KeyboardInput { return mutate(spellcheck: condition) @@ -7765,10 +7965,15 @@ extension Subscript: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Subscript { return mutate(role: value) } + public func role(_ value: Roles) -> Subscript { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> Subscript { return mutate(spellcheck: condition) } @@ -7947,9 +8152,14 @@ extension Superscript: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Superscript { return mutate(role: value) } + + public func role(_ value: Roles) -> Superscript { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Superscript { return mutate(spellcheck: condition) @@ -8129,9 +8339,14 @@ extension Italic: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Italic { return mutate(role: value) } + + public func role(_ value: Roles) -> Italic { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Italic { return mutate(spellcheck: condition) @@ -8322,9 +8537,14 @@ extension Bold: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Bold { return mutate(role: value) } + + public func role(_ value: Roles) -> Bold { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Bold { return mutate(spellcheck: condition) @@ -8515,9 +8735,14 @@ extension Underline: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Underline { return mutate(role: value) } + + public func role(_ value: Roles) -> Underline { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Underline { return mutate(spellcheck: condition) @@ -8708,9 +8933,14 @@ extension Mark: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Mark { return mutate(role: value) } + + public func role(_ value: Roles) -> Mark { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Mark { return mutate(spellcheck: condition) @@ -8890,9 +9120,14 @@ extension Bdi: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Bdi { return mutate(role: value) } + + public func role(_ value: Roles) -> Bdi { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Bdi { return mutate(spellcheck: condition) @@ -9067,9 +9302,14 @@ extension Bdo: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Bdo { return mutate(role: value) } + + public func role(_ value: Roles) -> Bdo { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Bdo { return mutate(spellcheck: condition) @@ -9249,9 +9489,14 @@ extension Span: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Span { return mutate(role: value) } + + public func role(_ value: Roles) -> Span { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Span { return mutate(spellcheck: condition) @@ -9426,9 +9671,14 @@ extension LineBreak: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> LineBreak { return mutate(role: value) } + + public func role(_ value: Roles) -> LineBreak { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> LineBreak { return mutate(spellcheck: condition) @@ -9603,10 +9853,15 @@ extension WordBreak: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> WordBreak { return mutate(role: value) } + public func role(_ value: Roles) -> WordBreak { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> WordBreak { return mutate(spellcheck: condition) } @@ -9785,9 +10040,14 @@ extension InsertedText: GlobalAttributes, CiteAttribute, DateTimeAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> InsertedText { return mutate(role: value) } + + public func role(_ value: Roles) -> InsertedText { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> InsertedText { return mutate(spellcheck: condition) @@ -9975,9 +10235,14 @@ extension DeletedText: GlobalAttributes, CiteAttribute, DateTimeAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> DeletedText { return mutate(role: value) } + + public func role(_ value: Roles) -> DeletedText { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> DeletedText { return mutate(spellcheck: condition) @@ -10164,10 +10429,15 @@ extension Picture: GlobalAttributes { public func nonce(_ value: String) -> Picture { return mutate(nonce: value) } - + + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Picture { return mutate(role: value) } + + public func role(_ value: Roles) -> Picture { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Picture { return mutate(spellcheck: condition) @@ -10350,9 +10620,14 @@ extension Image: GlobalAttributes, AlternateAttribute, SourceAttribute, SizesAtt return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Image { return mutate(role: value) } + + public func role(_ value: Roles) -> Image { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Image { return mutate(spellcheck: condition) @@ -10556,10 +10831,15 @@ extension InlineFrame: GlobalAttributes, SourceAttribute, NameAttribute, WidthAt return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> InlineFrame { return mutate(role: value) } + public func role(_ value: Roles) -> InlineFrame { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> InlineFrame { return mutate(spellcheck: condition) } @@ -10757,10 +11037,15 @@ extension Embed: GlobalAttributes, SourceAttribute, TypeAttribute, WidthAttribut return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Embed { return mutate(role: value) } + public func role(_ value: Roles) -> Embed { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> Embed { return mutate(spellcheck: condition) } @@ -10785,7 +11070,7 @@ extension Embed: GlobalAttributes, SourceAttribute, TypeAttribute, WidthAttribut return mutate(source: value) } - public func type(_ value: MediaType) -> Embed { + public func type(_ value: Medias) -> Embed { return mutate(type: value.rawValue) } @@ -10959,9 +11244,14 @@ extension Object: GlobalAttributes, DataAttribute, TypeAttribute, NameAttribute, return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Object { return mutate(role: value) } + + public func role(_ value: Roles) -> Object { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Object { return mutate(spellcheck: condition) @@ -10987,7 +11277,7 @@ extension Object: GlobalAttributes, DataAttribute, TypeAttribute, NameAttribute, return mutate(data: value) } - public func type(_ value: MediaType) -> Object { + public func type(_ value: Medias) -> Object { return mutate(type: value.rawValue) } @@ -11169,10 +11459,15 @@ extension Video: GlobalAttributes, SourceAttribute, AutoplayAttribute, LoopAttri return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Video { return mutate(role: value) } + public func role(_ value: Roles) -> Video { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> Video { return mutate(spellcheck: condition) } @@ -11379,9 +11674,14 @@ extension Audio: GlobalAttributes, SourceAttribute, AutoplayAttribute, LoopAttri return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Audio { return mutate(role: value) } + + public func role(_ value: Roles) -> Audio { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Audio { return mutate(spellcheck: condition) @@ -11581,9 +11881,14 @@ extension Map: GlobalAttributes, NameAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Map { return mutate(role: value) } + + public func role(_ value: Roles) -> Map { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Map { return mutate(spellcheck: condition) @@ -11779,9 +12084,14 @@ extension Form: GlobalAttributes, ActionAttribute, AutocompleteAttribute, Encodi return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Form { return mutate(role: value) } + + public func role(_ value: Roles) -> Form { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Form { return mutate(spellcheck: condition) @@ -11993,9 +12303,14 @@ extension DataList: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> DataList { return mutate(role: value) } + + public func role(_ value: Roles) -> DataList { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> DataList { return mutate(spellcheck: condition) @@ -12175,9 +12490,14 @@ extension Output: GlobalAttributes, ForAttribute, FormAttribute, NameAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Output { return mutate(role: value) } + + public func role(_ value: Roles) -> Output { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Output { return mutate(spellcheck: condition) @@ -12372,10 +12692,15 @@ extension Progress: GlobalAttributes, ValueAttribute, MaximumValueAttribute { public func nonce(_ value: String) -> Progress { return mutate(nonce: value) } - + + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Progress { return mutate(role: value) } + + public func role(_ value: Roles) -> Progress { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Progress { return mutate(spellcheck: condition) @@ -12567,9 +12892,14 @@ extension Meter: GlobalAttributes, ValueAttribute, MinimumValueAttribute, Maximu return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Meter { return mutate(role: value) } + + public func role(_ value: Roles) -> Meter { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Meter { return mutate(spellcheck: condition) @@ -12777,10 +13107,15 @@ extension Details: GlobalAttributes, OpenAttribute, ToggleEventAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Details { return mutate(role: value) } + public func role(_ value: Roles) -> Details { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> Details { return mutate(spellcheck: condition) } @@ -12963,10 +13298,15 @@ extension Dialog: GlobalAttributes, OpenAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Dialog { return mutate(role: value) } + public func role(_ value: Roles) -> Dialog { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> Dialog { return mutate(spellcheck: condition) } @@ -13156,10 +13496,15 @@ extension Script: GlobalAttributes, AsynchronouslyAttribute, ReferrerPolicyAttri public func nonce(_ value: String) -> Script { return mutate(nonce: value) } - + + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Script { return mutate(role: value) } + + public func role(_ value: Roles) -> Script { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Script { return mutate(spellcheck: condition) @@ -13193,7 +13538,7 @@ extension Script: GlobalAttributes, AsynchronouslyAttribute, ReferrerPolicyAttri return mutate(source: value) } - public func type(_ value: MediaType) -> Script { + public func type(_ value: Medias) -> Script { return mutate(type: value.rawValue) } @@ -13355,10 +13700,15 @@ extension NoScript: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> NoScript { return mutate(role: value) } + public func role(_ value: Roles) -> NoScript { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> NoScript { return mutate(spellcheck: condition) } @@ -13537,9 +13887,14 @@ extension Template: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Template { return mutate(role: value) } + + public func role(_ value: Roles) -> Template { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Template { return mutate(spellcheck: condition) @@ -13719,9 +14074,14 @@ extension Canvas: GlobalAttributes, WidthAttribute, HeightAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Canvas { return mutate(role: value) } + + public func role(_ value: Roles) -> Canvas { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Canvas { return mutate(spellcheck: condition) @@ -13909,9 +14269,14 @@ extension Table: GlobalAttributes, WidthAttribute, HeightAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Table { return mutate(role: value) } + + public func role(_ value: Roles) -> Table { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Table { return mutate(spellcheck: condition) diff --git a/Sources/HTMLKit/External/Elements/DefinitionElements.swift b/Sources/HTMLKit/External/Elements/DefinitionElements.swift index 262c612c..7e29ac9f 100644 --- a/Sources/HTMLKit/External/Elements/DefinitionElements.swift +++ b/Sources/HTMLKit/External/Elements/DefinitionElements.swift @@ -127,10 +127,15 @@ extension TermName: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> TermName { return mutate(role: value) } + public func role(_ value: Roles) -> TermName { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> TermName { return mutate(spellcheck: condition) } @@ -308,11 +313,16 @@ extension TermDefinition: GlobalAttributes { public func nonce(_ value: String) -> TermDefinition { return mutate(nonce: value) } - + + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> TermDefinition { return mutate(role: value) } + public func role(_ value: Roles) -> TermDefinition { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> TermDefinition { return mutate(spellcheck: condition) } diff --git a/Sources/HTMLKit/External/Elements/FigureElements.swift b/Sources/HTMLKit/External/Elements/FigureElements.swift index cb8e08e0..5ac19bfe 100644 --- a/Sources/HTMLKit/External/Elements/FigureElements.swift +++ b/Sources/HTMLKit/External/Elements/FigureElements.swift @@ -122,9 +122,14 @@ extension FigureCaption: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> FigureCaption { return mutate(role: value) } + + public func role(_ value: Roles) -> FigureCaption { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> FigureCaption { return mutate(spellcheck: condition) diff --git a/Sources/HTMLKit/External/Elements/FormElements.swift b/Sources/HTMLKit/External/Elements/FormElements.swift index 30441a19..ba0d33ef 100644 --- a/Sources/HTMLKit/External/Elements/FormElements.swift +++ b/Sources/HTMLKit/External/Elements/FormElements.swift @@ -116,9 +116,14 @@ extension Input: GlobalAttributes, AcceptAttribute, AlternateAttribute, Autocomp return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Input { return mutate(role: value) } + + public func role(_ value: Roles) -> Input { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Input { return mutate(spellcheck: condition) @@ -410,9 +415,14 @@ extension Label: GlobalAttributes, ForAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Label { return mutate(role: value) } + + public func role(_ value: Roles) -> Label { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Label { return mutate(spellcheck: condition) @@ -607,9 +617,14 @@ extension Select: GlobalAttributes, AutocompleteAttribute, DisabledAttribute, Fo return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Select { return mutate(role: value) } + + public func role(_ value: Roles) -> Select { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Select { return mutate(spellcheck: condition) @@ -821,9 +836,14 @@ extension TextArea: GlobalAttributes, AutocompleteAttribute, ColumnsAttribute, D return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> TextArea { return mutate(role: value) } + + public func role(_ value: Roles) -> TextArea { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> TextArea { return mutate(spellcheck: condition) @@ -1059,9 +1079,14 @@ extension Button: GlobalAttributes, DisabledAttribute, FormAttribute, FormAction return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Button { return mutate(role: value) } + + public func role(_ value: Roles) -> Button { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Button { return mutate(spellcheck: condition) @@ -1284,9 +1309,14 @@ extension Fieldset: GlobalAttributes, DisabledAttribute, FormAttribute, NameAttr return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Fieldset { return mutate(role: value) } + + public func role(_ value: Roles) -> Fieldset { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Fieldset { return mutate(spellcheck: condition) diff --git a/Sources/HTMLKit/External/Elements/HeadElements.swift b/Sources/HTMLKit/External/Elements/HeadElements.swift index 7104d714..150e6b62 100644 --- a/Sources/HTMLKit/External/Elements/HeadElements.swift +++ b/Sources/HTMLKit/External/Elements/HeadElements.swift @@ -119,10 +119,15 @@ extension Title: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Title { return mutate(role: value) } + public func role(_ value: Roles) -> Title { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> Title { return mutate(spellcheck: condition) } @@ -299,10 +304,15 @@ extension Base: GlobalAttributes, ReferenceAttribute, TargetAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Base { return mutate(role: value) } + public func role(_ value: Roles) -> Base { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> Base { return mutate(spellcheck: condition) } @@ -489,9 +499,14 @@ extension Meta: GlobalAttributes, ContentAttribute, NameAttribute, PropertyAttri return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Meta { return mutate(role: value) } + + public func role(_ value: Roles) -> Meta { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Meta { return mutate(spellcheck: condition) @@ -521,11 +536,11 @@ extension Meta: GlobalAttributes, ContentAttribute, NameAttribute, PropertyAttri return mutate(content: value.rawValue) } - public func name(_ value: NameType) -> Meta { + public func name(_ value: Names) -> Meta { return mutate(name: value.rawValue) } - public func name(_ value: TemplateValue) -> Meta { + public func name(_ value: TemplateValue) -> Meta { return mutate(name: value.rawValue) } @@ -704,10 +719,15 @@ extension Style: GlobalAttributes, TypeAttribute, MediaAttribute, LoadEventAttri return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Style { return mutate(role: value) } + public func role(_ value: Roles) -> Style { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> Style { return mutate(spellcheck: condition) } @@ -728,7 +748,7 @@ extension Style: GlobalAttributes, TypeAttribute, MediaAttribute, LoadEventAttri return mutate(translate: value) } - public func type(_ value: MediaType) -> Style { + public func type(_ value: Medias) -> Style { return mutate(type: value.rawValue) } @@ -897,9 +917,14 @@ extension Link: GlobalAttributes, ReferenceAttribute, ReferenceLanguageAttribute return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Link { return mutate(role: value) } + + public func role(_ value: Roles) -> Link { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Link { return mutate(spellcheck: condition) @@ -949,7 +974,7 @@ extension Link: GlobalAttributes, ReferenceAttribute, ReferenceLanguageAttribute return mutate(sizes: size) } - public func type(_ value: MediaType) -> Link { + public func type(_ value: Medias) -> Link { return mutate(type: value.rawValue) } diff --git a/Sources/HTMLKit/External/Elements/HtmlElements.swift b/Sources/HTMLKit/External/Elements/HtmlElements.swift index 48060280..5a3c9a09 100644 --- a/Sources/HTMLKit/External/Elements/HtmlElements.swift +++ b/Sources/HTMLKit/External/Elements/HtmlElements.swift @@ -117,10 +117,15 @@ extension Head: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Head { return mutate(role: value) } + public func role(_ value: Roles) -> Head { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> Head { return mutate(spellcheck: condition) } @@ -335,9 +340,14 @@ extension Body: GlobalAttributes, AfterPrintEventAttribute, BeforePrintEventAttr return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Body { return mutate(role: value) } + + public func role(_ value: Roles) -> Body { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Body { return mutate(spellcheck: condition) diff --git a/Sources/HTMLKit/External/Elements/InputElements.swift b/Sources/HTMLKit/External/Elements/InputElements.swift index 5a15f0a3..625382b9 100644 --- a/Sources/HTMLKit/External/Elements/InputElements.swift +++ b/Sources/HTMLKit/External/Elements/InputElements.swift @@ -122,9 +122,14 @@ extension OptionGroup: GlobalAttributes, DisabledAttribute, LabelAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> OptionGroup { return mutate(role: value) } + + public func role(_ value: Roles) -> OptionGroup { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> OptionGroup { return mutate(spellcheck: condition) @@ -312,9 +317,14 @@ extension Option: GlobalAttributes, DisabledAttribute, LabelAttribute, ValueAttr return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Option { return mutate(role: value) } + + public func role(_ value: Roles) -> Option { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Option { return mutate(spellcheck: condition) @@ -512,10 +522,15 @@ extension Legend: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Legend { return mutate(role: value) } + public func role(_ value: Roles) -> Legend { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> Legend { return mutate(spellcheck: condition) } @@ -694,9 +709,14 @@ extension Summary: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Summary { return mutate(role: value) } + + public func role(_ value: Roles) -> Summary { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Summary { return mutate(spellcheck: condition) diff --git a/Sources/HTMLKit/External/Elements/ListElements.swift b/Sources/HTMLKit/External/Elements/ListElements.swift index 88525616..20cc409d 100644 --- a/Sources/HTMLKit/External/Elements/ListElements.swift +++ b/Sources/HTMLKit/External/Elements/ListElements.swift @@ -122,10 +122,15 @@ extension ListItem: GlobalAttributes, ValueAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> ListItem { return mutate(role: value) } + public func role(_ value: Roles) -> ListItem { + return mutate(role: value.rawValue) + } + public func hasSpellCheck(_ condition: Bool) -> ListItem { return mutate(spellcheck: condition) } diff --git a/Sources/HTMLKit/External/Elements/MapElements.swift b/Sources/HTMLKit/External/Elements/MapElements.swift index 0bb31871..d7d9d426 100644 --- a/Sources/HTMLKit/External/Elements/MapElements.swift +++ b/Sources/HTMLKit/External/Elements/MapElements.swift @@ -117,9 +117,14 @@ extension Area: GlobalAttributes, AlternateAttribute, CoordinatesAttribute, Shap return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Area { return mutate(role: value) } + + public func role(_ value: Roles) -> Area { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Area { return mutate(spellcheck: condition) diff --git a/Sources/HTMLKit/External/Elements/MediaElements.swift b/Sources/HTMLKit/External/Elements/MediaElements.swift index 91a675f4..50a49b6e 100644 --- a/Sources/HTMLKit/External/Elements/MediaElements.swift +++ b/Sources/HTMLKit/External/Elements/MediaElements.swift @@ -112,9 +112,14 @@ extension Source: GlobalAttributes, TypeAttribute, SourceAttribute, SizesAttribu return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Source { return mutate(role: value) } + + public func role(_ value: Roles) -> Source { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Source { return mutate(spellcheck: condition) @@ -136,7 +141,7 @@ extension Source: GlobalAttributes, TypeAttribute, SourceAttribute, SizesAttribu return mutate(translate: value) } - public func type(_ value: MediaType) -> Source { + public func type(_ value: Medias) -> Source { return mutate(type: value.rawValue) } @@ -313,9 +318,14 @@ extension Track: GlobalAttributes, KindAttribute, SourceAttribute, LabelAttribut return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Track { return mutate(role: value) } + + public func role(_ value: Roles) -> Track { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Track { return mutate(spellcheck: condition) diff --git a/Sources/HTMLKit/External/Elements/ObjectElements.swift b/Sources/HTMLKit/External/Elements/ObjectElements.swift index a85d98c0..469a9b53 100644 --- a/Sources/HTMLKit/External/Elements/ObjectElements.swift +++ b/Sources/HTMLKit/External/Elements/ObjectElements.swift @@ -112,9 +112,14 @@ extension Parameter: GlobalAttributes, NameAttribute, ValueAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Parameter { return mutate(role: value) } + + public func role(_ value: Roles) -> Parameter { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Parameter { return mutate(spellcheck: condition) diff --git a/Sources/HTMLKit/External/Elements/RubyElements.swift b/Sources/HTMLKit/External/Elements/RubyElements.swift index a27d2609..0d430161 100644 --- a/Sources/HTMLKit/External/Elements/RubyElements.swift +++ b/Sources/HTMLKit/External/Elements/RubyElements.swift @@ -127,9 +127,14 @@ extension RubyText: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> RubyText { return mutate(role: value) } + + public func role(_ value: Roles) -> RubyText { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> RubyText { return mutate(spellcheck: condition) @@ -309,9 +314,14 @@ extension RubyPronunciation: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> RubyPronunciation { return mutate(role: value) } + + public func role(_ value: Roles) -> RubyPronunciation { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> RubyPronunciation { return mutate(spellcheck: condition) diff --git a/Sources/HTMLKit/External/Elements/TableElements.swift b/Sources/HTMLKit/External/Elements/TableElements.swift index b150febd..b9749e8e 100644 --- a/Sources/HTMLKit/External/Elements/TableElements.swift +++ b/Sources/HTMLKit/External/Elements/TableElements.swift @@ -157,9 +157,14 @@ extension Caption: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Caption { return mutate(role: value) } + + public func role(_ value: Roles) -> Caption { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Caption { return mutate(spellcheck: condition) @@ -339,9 +344,14 @@ extension ColumnGroup: GlobalAttributes, SpanAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> ColumnGroup { return mutate(role: value) } + + public func role(_ value: Roles) -> ColumnGroup { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> ColumnGroup { return mutate(spellcheck: condition) @@ -525,9 +535,14 @@ extension Column: GlobalAttributes, SpanAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> Column { return mutate(role: value) } + + public func role(_ value: Roles) -> Column { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> Column { return mutate(spellcheck: condition) @@ -711,9 +726,14 @@ extension TableBody: GlobalAttributes, WidthAttribute, HeightAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> TableBody { return mutate(role: value) } + + public func role(_ value: Roles) -> TableBody { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> TableBody { return mutate(spellcheck: condition) @@ -901,9 +921,14 @@ extension TableHead: GlobalAttributes, WidthAttribute, HeightAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> TableHead { return mutate(role: value) } + + public func role(_ value: Roles) -> TableHead { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> TableHead { return mutate(spellcheck: condition) @@ -1091,9 +1116,14 @@ extension TableFoot: GlobalAttributes { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> TableFoot { return mutate(role: value) } + + public func role(_ value: Roles) -> TableFoot { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> TableFoot { return mutate(spellcheck: condition) @@ -1273,9 +1303,14 @@ extension TableRow: GlobalAttributes, WidthAttribute, HeightAttribute { return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> TableRow { return mutate(role: value) } + + public func role(_ value: Roles) -> TableRow { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> TableRow { return mutate(spellcheck: condition) @@ -1463,9 +1498,14 @@ extension DataCell: GlobalAttributes, ColumnSpanAttribute, RowSpanAttribute, Hea return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> DataCell { return mutate(role: value) } + + public func role(_ value: Roles) -> DataCell { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> DataCell { return mutate(spellcheck: condition) @@ -1657,9 +1697,14 @@ extension HeaderCell: GlobalAttributes, ColumnSpanAttribute, RowSpanAttribute, H return mutate(nonce: value) } + @available(*, deprecated, message: "use role(_ value: Roles) instead") public func role(_ value: String) -> HeaderCell { return mutate(role: value) } + + public func role(_ value: Roles) -> HeaderCell { + return mutate(role: value.rawValue) + } public func hasSpellCheck(_ condition: Bool) -> HeaderCell { return mutate(spellcheck: condition) diff --git a/Sources/HTMLKit/External/Types.swift b/Sources/HTMLKit/External/Types.swift index dfb22e44..c1260a6e 100644 --- a/Sources/HTMLKit/External/Types.swift +++ b/Sources/HTMLKit/External/Types.swift @@ -13,23 +13,14 @@ /// /// ## References /// -public struct NameType: RawRepresentable { +public enum Names: String { - public var rawValue: String - - public init?(rawValue: String) { - self.rawValue = rawValue - } -} - -extension NameType { - - static let author = NameType(rawValue: "author")! - static let description = NameType(rawValue: "description")! - static let generator = NameType(rawValue: "generator")! - static let keywords = NameType(rawValue: "keywords")! - static let viewport = NameType(rawValue: "viewport")! - static let applicationName = NameType(rawValue: "application-name")! + case author = "author" + case description = "description" + case generator = "generator" + case keywords = "keywords" + case viewport = "viewport" + case applicationName = "application-name" } /// ## Description @@ -390,24 +381,15 @@ public enum Direction: String { /// /// ## References /// -public struct MediaType: RawRepresentable { - - public var rawValue: String - - public init?(rawValue: String) { - self.rawValue = rawValue - } -} - -extension MediaType { +public enum Medias: String { - static let html = MediaType(rawValue: "text/html")! - static let css = MediaType(rawValue: "text/css")! - static let ogg = MediaType(rawValue: "video/ogg")! - static let mp4 = MediaType(rawValue: "video/mp4")! - static let webm = MediaType(rawValue: "video/webm")! - static let mpeg = MediaType(rawValue: "audio/mpeg")! - static let javascript = MediaType(rawValue: "application/javascript")! + case html = "text/html" + case css = "text/css" + case ogg = "video/ogg" + case mp4 = "video/mp4" + case webm = "video/webm" + case mpeg = "audio/mpeg" + case javascript = "application/javascript" } /// ## Description @@ -429,7 +411,7 @@ public enum Marker: String { /// /// ## References /// -public enum DocumentType: String { +public enum Doctypes: String { case html5 = "html" case html4Strict = #"HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd""# @@ -491,21 +473,12 @@ public enum Capitalization: String { /// /// ## References /// -public struct Charset: RawRepresentable { - - public var rawValue: String - - public init?(rawValue: String) { - self.rawValue = rawValue - } -} - -extension Charset { +public enum Charset: String { - static let utf8 = Charset(rawValue: "UTF-8")! - static let utf16 = Charset(rawValue: "UTF-16")! - static let ansi = Charset(rawValue: "Windows-1252")! - static let iso = Charset(rawValue: "ISO-8859-1")! + case utf8 = "utf-8" + case utf16 = "utf-16" + case ansi = "windows-1252" + case iso = "iso-8859-1" } /// ## Description @@ -513,18 +486,97 @@ extension Charset { /// /// ## References /// -public struct Equivalent: RawRepresentable { +public enum Equivalent: String { - public var rawValue: String - - public init?(rawValue: String) { - self.rawValue = rawValue - } + case content = "content-type" + case `default` = "default-style" + case refresh = "refresh" } -extension Equivalent { +/// ## Description +/// The type is for +/// +/// ## References +/// +public enum Roles: String { - static let content = Equivalent(rawValue: "content-type")! - static let `default` = Equivalent(rawValue: "default-style")! - static let refresh = Equivalent(rawValue: "refresh")! + case alert + case alertDialog = "alertdialog" + case application + case article + case banner + case button + case cell + case checkbox + case columnHeader = "columnheader" + case combobox + case command + case comment + case complementary + case composite + case contentInfo = "contentinfo" + case definition + case dialog + case directory + case document + case feed + case figure + case form + case grid + case gridCell = "gridcell" + case group + case heading + case img + case input + case landmark + case list + case listBox = "listbox" + case listItem = "listitem" + case log + case main + case mark + case marquee + case math + case menu + case menuBar = "menubar" + case menuItem = "menuitem" + case menuItemCheckbox = "menuitemcheckbox" + case menuItemRadio = "menuitemradio" + case meter + case navigation + case none + case note + case option + case presentation + case radio + case range + case region + case roleType = "roletype" + case row + case rowGroup = "rowgroup" + case rowHeader = "rowheader" + case scrollbar + case search + case searchBox = "searchbox" + case sectionHead = "sectionhead" + case select + case separator + case status + case structure + case suggestion + case `switch` + case tab + case table + case tabList = "tablist" + case tabPanel = "tabpanel" + case term + case textbox + case timer + case toolbar + case tooltip + case tree + case treeGrid = "treegrid" + case treeItem = "treeitem" + case widget + case window } diff --git a/Sources/HTMLKit/Internal/Features/Conversion/Converter.swift b/Sources/HTMLKit/Internal/Features/Conversion/Converter.swift index 1b171735..c27a0156 100644 --- a/Sources/HTMLKit/Internal/Features/Conversion/Converter.swift +++ b/Sources/HTMLKit/Internal/Features/Conversion/Converter.swift @@ -68,7 +68,7 @@ public class Converter { if let dtd = document.dtd { - let layout = PageLayout(name: fileName, doctype: dtd, root: root).build() + let layout = PageLayout(name: fileName, doctype: dtd, root: root).build() print(layout) @@ -83,7 +83,7 @@ public class Converter { if let dtd = document.dtd { - let layout = PageLayout(name: fileName, doctype: dtd, root: root).build() + let layout = PageLayout(name: fileName, doctype: dtd, root: root).build() try layout.write(to: file.deletingPathExtension().appendingPathExtension("swift"), atomically: true, @@ -220,7 +220,17 @@ public class Converter { case "muted": EmptyProperty(node: attribute).build() case "name": - ValueProperty(node: attribute).build() + + if let parent = attribute.parent { + + switch parent.localName { + case "meta": + TypeProperty(node: attribute).build() + default: + ValueProperty(node: attribute).build() + } + } + case "nonce": ValueProperty(node: attribute).build() case "novalidate": @@ -252,7 +262,7 @@ public class Converter { case "reversed": EmptyProperty(node: attribute).build() case "role": - ValueProperty(node: attribute).build() + TypeProperty(node: attribute).build() case "rows": ValueProperty(node: attribute).build() case "rowspan": @@ -290,7 +300,25 @@ public class Converter { case "translate": ValueProperty(node: attribute).build() case "type": - TypeProperty(node: attribute).build() + + if let parent = attribute.parent { + + switch parent.localName { + case "input": + TypeProperty(node: attribute).build() + case "button": + TypeProperty(node: attribute).build() + case "link": + TypeProperty(node: attribute).build() + case "script": + TypeProperty(node: attribute).build() + case "audio": + TypeProperty(node: attribute).build() + default: + ValueProperty(node: attribute).build() + } + } + case "value": ValueProperty(node: attribute).build() case "width": @@ -299,8 +327,12 @@ public class Converter { TypeProperty(node: attribute).build() case "property": TypeProperty(node: attribute).build() + case "charset": + TypeProperty(node: attribute).build() + case "http-equiv": + TypeProperty(node: attribute).build() default: - "attribute is not listed. contact the author" + CustomProperty(node: attribute).build() } } diff --git a/Sources/HTMLKit/Internal/Features/Conversion/Stencils.swift b/Sources/HTMLKit/Internal/Features/Conversion/Stencils.swift index dbbfc98e..e3050ab8 100644 --- a/Sources/HTMLKit/Internal/Features/Conversion/Stencils.swift +++ b/Sources/HTMLKit/Internal/Features/Conversion/Stencils.swift @@ -400,7 +400,7 @@ internal struct TypeProperty{ return nil } - if let type = T(rawValue: value as! T.RawValue) { + if let type = T(rawValue: value.lowercased() as! T.RawValue) { return ".\(type)" } @@ -437,3 +437,38 @@ internal struct TypeProperty{ } } } + +@available(macOS 11.0, *) +internal struct CustomProperty { + + private var name: String? { + + guard let name = node.name else { + return nil + } + + return name + } + + private var value: String? { + + guard let value = node.stringValue else { + return nil + } + + return value + } + + private let node: XMLNode + + internal init(node: XMLNode) { + self.node = node + } + + @StringBuilder internal func build() -> String { + + if let name = name { + ".custom(key: \"\(name)\", value: \"\(value ?? "")\")\n" + } + } +} diff --git a/Tests/HTMLKitTests/Conversion/index.html b/Tests/HTMLKitTests/Conversion/index.html index ed9e90e1..9012845c 100644 --- a/Tests/HTMLKitTests/Conversion/index.html +++ b/Tests/HTMLKitTests/Conversion/index.html @@ -3,6 +3,7 @@ test +

headline

diff --git a/Tests/HTMLKitTests/PerformanceTests.swift b/Tests/HTMLKitTests/PerformanceTests.swift index d9e4c613..03953e44 100644 --- a/Tests/HTMLKitTests/PerformanceTests.swift +++ b/Tests/HTMLKitTests/PerformanceTests.swift @@ -77,7 +77,7 @@ final class PerformanceTests: XCTestCase { } .id("test") .class("class") - .role("role") + .role(.heading) } Main { Article { @@ -86,12 +86,12 @@ final class PerformanceTests: XCTestCase { } .id("test") .class("class") - .role("role") + .role(.heading) } } .id("test") .class("class") - .role("role") + .role(.main) } } } diff --git a/Tests/HTMLKitTests/RenderingTests.swift b/Tests/HTMLKitTests/RenderingTests.swift index 32466c0b..2d099919 100644 --- a/Tests/HTMLKitTests/RenderingTests.swift +++ b/Tests/HTMLKitTests/RenderingTests.swift @@ -95,7 +95,6 @@ final class RenderingTests: XCTestCase { Paragraph { "text" } - .role("role") .class("class") } @@ -103,7 +102,7 @@ final class RenderingTests: XCTestCase { XCTAssertEqual(try renderer.render(raw: TestPage.self), """ -

text

+

text

""" ) } @@ -115,7 +114,6 @@ final class RenderingTests: XCTestCase { Paragraph { "text" } - .role("ro_le") .class("cl_ass") } @@ -123,7 +121,7 @@ final class RenderingTests: XCTestCase { XCTAssertEqual(try renderer.render(raw: TestPage.self), """ -

text

+

text

""" ) } @@ -134,7 +132,6 @@ final class RenderingTests: XCTestCase { Paragraph { "text" } - .role("ro-le") .class("cl-ass") } @@ -142,7 +139,7 @@ final class RenderingTests: XCTestCase { XCTAssertEqual(try renderer.render(raw: TestPage.self), """ -

text

+

text

""" ) } @@ -174,7 +171,6 @@ final class RenderingTests: XCTestCase { Paragraph { "text" } - .role("role") .class("cl'ass") } @@ -182,7 +178,7 @@ final class RenderingTests: XCTestCase { XCTAssertEqual(try renderer.render(raw: TestPage.self), """ -

text

+

text

""" ) }