Skip to content

Commit

Permalink
added rel attribute (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
sliemeobn authored Jun 26, 2024
1 parent 31bb7c9 commit d792eae
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions Sources/Elementary/HtmlAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@ extension HTMLTag.base: HTMLTrait.Attributes.target {}
extension HTMLTag.form: HTMLTrait.Attributes.target {}

public extension HTMLAttributeValue {
struct Target: ExpressibleByStringLiteral, Sendable, Equatable {
public var value: String
struct Target: ExpressibleByStringLiteral, RawRepresentable {
public var rawValue: String

public init(rawValue: String) {
self.rawValue = rawValue
}

public init(stringLiteral value: String) {
self.value = value
rawValue = value
}

public static var blank: Self { "_blank" }
Expand All @@ -122,7 +127,7 @@ public extension HTMLAttributeValue {

public extension HTMLAttribute where Tag: HTMLTrait.Attributes.target {
static func target(_ target: HTMLAttributeValue.Target) -> Self {
HTMLAttribute(name: "target", value: target.value)
HTMLAttribute(name: "target", value: target.rawValue)
}
}

Expand Down Expand Up @@ -172,6 +177,39 @@ public extension HTMLAttribute where Tag: HTMLTrait.Attributes.charset {
}
}

// rel attribute
public extension HTMLTrait.Attributes {
protocol rel {}
}

extension HTMLTag.a: HTMLTrait.Attributes.rel {}
extension HTMLTag.area: HTMLTrait.Attributes.rel {}
extension HTMLTag.link: HTMLTrait.Attributes.rel {}
extension HTMLTag.form: HTMLTrait.Attributes.rel {}

public extension HTMLAttributeValue {
struct Relationship: ExpressibleByStringLiteral, RawRepresentable, Sendable, Equatable {
public var rawValue: String

public init(rawValue: String) {
self.rawValue = rawValue
}

public init(stringLiteral value: String) {
rawValue = value
}

public static var icon: Self { "icon" }
public static var stylesheet: Self { "stylesheet" }
}
}

public extension HTMLAttribute where Tag: HTMLTrait.Attributes.rel {
static func rel(_ value: HTMLAttributeValue.Relationship) -> Self {
HTMLAttribute(name: "rel", value: value.rawValue)
}
}

// form tag attributes
public extension HTMLAttribute where Tag == HTMLTag.form {
struct Method: Sendable, Equatable {
Expand Down

0 comments on commit d792eae

Please sign in to comment.